Files
maternal-app/maternal-web/components/children/ChildDialog.tsx
Andrei c22fa82521
Some checks failed
ParentFlow CI/CD Pipeline / Backend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Frontend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Security Scanning (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-app/maternal-app-backend dockerfile:Dockerfile.production name:backend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-web dockerfile:Dockerfile.production name:frontend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Development (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled
feat: Implement comprehensive error handling and production deployment pipeline
## Error Handling System
- Add centralized error handling utilities (errorHandler.ts)
- Create reusable error components (ErrorMessage, ErrorToast)
- Implement multilingual error support (preserves backend error messages in 5 languages)
- Update 15+ forms and components with consistent error handling
  - Auth forms: login, register, forgot-password
  - Family management: family page, join family dialog
  - Child management: child dialog
  - All tracking forms: feeding, sleep, diaper, medicine, growth, activity

## Production Build Fixes
- Fix backend TypeScript errors: InviteCode.uses → InviteCode.useCount (5 instances)
- Remove non-existent savedFamily variable from registration response
- Fix admin panel TypeScript errors: SimpleMDE toolbar type, PieChart label type

## User Experience Improvements
- Auto-uppercase invite code and share code inputs
- Visual feedback for case conversion with helper text
- Improved form validation with error codes

## CI/CD Pipeline
- Create comprehensive production deployment checklist (PRODUCTION_DEPLOYMENT_CHECKLIST.md)
- Add automated pre-deployment check script (pre-deploy-check.sh)
  - Validates frontend, backend, and admin panel builds
  - Checks git status, branch, and sync state
  - Verifies environment files and migrations
- Add quick start deployment guide (DEPLOYMENT_QUICK_START.md)
- Add production deployment automation template (deploy-production.sh)

## Cleanup
- Remove outdated push notifications documentation files
- Remove outdated PWA implementation plan

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-09 21:27:39 +00:00

188 lines
5.3 KiB
TypeScript

'use client';
import { useState, useEffect } from 'react';
import {
Dialog,
DialogTitle,
DialogContent,
DialogActions,
Button,
TextField,
MenuItem,
Box,
Alert,
} from '@mui/material';
import { Child, CreateChildData } from '@/lib/api/children';
import { useTranslation } from '@/hooks/useTranslation';
import { PhotoUpload } from '@/components/common/PhotoUpload';
import { useErrorMessage } from '@/components/common/ErrorMessage';
import { formatErrorMessage } from '@/lib/utils/errorHandler';
interface ChildDialogProps {
open: boolean;
onClose: () => void;
onSubmit: (data: CreateChildData) => Promise<void>;
child?: Child | null;
isLoading?: boolean;
}
export function ChildDialog({ open, onClose, onSubmit, child, isLoading = false }: ChildDialogProps) {
const { t } = useTranslation('children');
const [formData, setFormData] = useState<CreateChildData>({
name: '',
birthDate: '',
gender: 'male',
photoUrl: '',
photoAlt: '',
});
const { error, showError, clearError, hasError } = useErrorMessage();
useEffect(() => {
if (child) {
setFormData({
name: child.name,
birthDate: child.birthDate.split('T')[0], // Convert to YYYY-MM-DD format
gender: child.gender,
photoUrl: child.photoUrl || '',
photoAlt: child.photoAlt || '',
});
} else {
setFormData({
name: '',
birthDate: '',
gender: 'male',
photoUrl: '',
photoAlt: '',
});
}
clearError();
}, [child, open, clearError]);
const handleChange = (field: keyof CreateChildData) => (
e: React.ChangeEvent<HTMLInputElement>
) => {
setFormData({ ...formData, [field]: e.target.value });
};
const handleSubmit = async () => {
clearError();
// Validation
if (!formData.name.trim()) {
showError({ message: t('dialog.validation.nameRequired'), code: 'VALIDATION_NAME_REQUIRED' });
return;
}
if (!formData.birthDate) {
showError({ message: t('dialog.validation.birthDateRequired'), code: 'VALIDATION_BIRTHDATE_REQUIRED' });
return;
}
// Check if birth date is in the future
const selectedDate = new Date(formData.birthDate);
const today = new Date();
today.setHours(0, 0, 0, 0);
if (selectedDate > today) {
showError({ message: t('dialog.validation.birthDateFuture'), code: 'VALIDATION_BIRTHDATE_FUTURE' });
return;
}
try {
await onSubmit(formData);
onClose();
} catch (err: any) {
showError(err);
}
};
return (
<Dialog
open={open}
onClose={onClose}
maxWidth="sm"
fullWidth
aria-labelledby="child-dialog-title"
aria-describedby="child-dialog-description"
>
<DialogTitle id="child-dialog-title">{child ? t('editChild') : t('addChild')}</DialogTitle>
<DialogContent>
<Box
id="child-dialog-description"
sx={{ pt: 2, display: 'flex', flexDirection: 'column', gap: 2 }}
>
{hasError && (
<Alert severity="error" onClose={clearError} role="alert">
{formatErrorMessage(error)}
</Alert>
)}
<TextField
label={t('dialog.name')}
value={formData.name}
onChange={handleChange('name')}
fullWidth
required
autoFocus
disabled={isLoading}
inputProps={{
'aria-required': 'true',
'aria-invalid': !formData.name.trim() && error ? 'true' : 'false',
}}
/>
<TextField
label={t('dialog.birthDate')}
type="date"
value={formData.birthDate}
onChange={handleChange('birthDate')}
fullWidth
required
InputLabelProps={{
shrink: true,
}}
disabled={isLoading}
inputProps={{
'aria-required': 'true',
'aria-invalid': !formData.birthDate && error ? 'true' : 'false',
}}
/>
<TextField
label={t('dialog.gender')}
value={formData.gender}
onChange={handleChange('gender')}
fullWidth
required
select
disabled={isLoading}
inputProps={{
'aria-required': 'true',
}}
>
<MenuItem value="male">{t('gender.male')}</MenuItem>
<MenuItem value="female">{t('gender.female')}</MenuItem>
<MenuItem value="other">{t('gender.other')}</MenuItem>
</TextField>
<PhotoUpload
label={t('dialog.photoUrl')}
value={formData.photoUrl || ''}
onChange={(url) => setFormData({ ...formData, photoUrl: url })}
altText={formData.photoAlt || ''}
onAltTextChange={(altText) => setFormData({ ...formData, photoAlt: altText })}
disabled={isLoading}
size={80}
/>
</Box>
</DialogContent>
<DialogActions>
<Button onClick={onClose} disabled={isLoading}>
{t('dialog.cancel')}
</Button>
<Button onClick={handleSubmit} variant="contained" disabled={isLoading}>
{isLoading ? t('dialog.saving') : child ? t('dialog.update') : t('dialog.add')}
</Button>
</DialogActions>
</Dialog>
);
}