ui phase 3

This commit is contained in:
hamid
2026-07-18 01:56:17 +03:30
parent 222856d600
commit 53b4e1b0a4
33 changed files with 1000 additions and 81 deletions
@@ -1,96 +0,0 @@
'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { useLocale, useTranslations } from 'next-intl';
import { useSnackbar } from 'notistack';
import { Box, Stack, Typography } from '@mui/material';
import { AppButton, PatientForm, RelationSelect, StepperHeader } from '@/components';
import { ROUTES } from '@/constants';
import { useCreatePatient } from '@/services/patients';
import { RELATION_CODES } from '@/services/patients/constants';
import type { CreatePatientInput, Relation } from '@/services/patients/types';
const ONBOARDING_MAX_WIDTH = 520;
/**
* A3 → A4 onboarding wizard: pick who care is for, then register the first patient. The
* chosen relation pre-shapes the patient (it is hidden on the A4 form since it's already
* chosen here). On save it creates the patient and lands on Home (A5).
*/
export default function OnboardingPage() {
const t = useTranslations('onboarding');
const tc = useTranslations('common');
const router = useRouter();
const locale = useLocale();
const { enqueueSnackbar } = useSnackbar();
const createPatient = useCreatePatient();
const [step, setStep] = useState(0);
const [relation, setRelation] = useState<Relation | null>(null);
const relationOptions = RELATION_CODES.map((code) => ({ code, label: t(`relation_${code}`), icon: 'account' }));
const handleCreate = (input: CreatePatientInput) => {
createPatient.mutate(
{ ...input, relation },
{
onSuccess: () => {
enqueueSnackbar(t('saved'), { variant: 'success' });
router.replace(`/${locale}${ROUTES.HOME}`);
},
},
);
};
return (
<Box sx={{ maxWidth: ONBOARDING_MAX_WIDTH, mx: 'auto', display: 'flex', flexDirection: 'column', gap: 3 }}>
<StepperHeader steps={[t('step_relation'), t('step_patient')]} activeStep={step} />
{step === 0 ? (
<Stack sx={{ gap: 2 }}>
<Stack sx={{ gap: 0.5 }}>
<Typography variant="h6" component="h1">
{t('relation_title')}
</Typography>
<Typography variant="body2" sx={{ color: 'text.secondary' }}>
{t('relation_subtitle')}
</Typography>
</Stack>
<RelationSelect
options={relationOptions}
value={relation}
onChange={(code) => setRelation(code as Relation)}
/>
<AppButton
color="primary"
variant="contained"
fullWidth
disabled={!relation}
onClick={() => setStep(1)}
>
{t('continue')}
</AppButton>
</Stack>
) : (
<Stack sx={{ gap: 2 }}>
<Stack sx={{ gap: 0.5 }}>
<Typography variant="h6" component="h1">
{t('patient_title')}
</Typography>
<Typography variant="body2" sx={{ color: 'text.secondary' }}>
{t('patient_subtitle')}
</Typography>
</Stack>
<PatientForm
initial={{ relation: relation ?? undefined }}
submitLabel={t('save_continue')}
submitting={createPatient.isPending}
onSubmit={handleCreate}
onCancel={() => setStep(0)}
cancelLabel={tc('back')}
/>
</Stack>
)}
</Box>
);
}