diff --git a/apps/portal/src/app/features/profile/components/ProfileFormContent.tsx b/apps/portal/src/app/features/profile/components/ProfileFormContent.tsx index 4540554a9..421af4c35 100644 --- a/apps/portal/src/app/features/profile/components/ProfileFormContent.tsx +++ b/apps/portal/src/app/features/profile/components/ProfileFormContent.tsx @@ -1,21 +1,23 @@ import { Loader, Select, SimpleGrid, TextInput } from '@mantine/core'; import type { FieldErrors, UseFormRegister, UseFormSetValue, UseFormWatch, UseFormTrigger } from 'react-hook-form'; import { z } from 'zod'; +import type { TFunction } from 'i18next'; import { useTranslation } from 'react-i18next'; import { AmharicDatePicker } from '@ema-platform/ui'; -export const profileSchema = z.object({ - professionId: z.string().min(1, 'Select your profession'), - firstName: z.string().min(3, 'First name must be at least 3 characters'), - middleName: z.string().min(3, 'Middle name must be at least 3 characters'), - lastName: z.string().min(3, 'Last name must be at least 3 characters'), - gender: z.string().min(1, 'Select your gender'), - dob: z.string().min(1, 'Select your date of birth'), - pob: z.string().optional(), - maritalStatus: z.string().min(1, 'Select your marital status'), -}); +export const profileSchema = (t: TFunction) => + z.object({ + professionId: z.string().min(1, t('profileForm.validation.professionRequired')), + firstName: z.string().min(3, t('profileForm.validation.firstNameMin')), + middleName: z.string().min(3, t('profileForm.validation.middleNameMin')), + lastName: z.string().min(3, t('profileForm.validation.lastNameMin')), + gender: z.string().min(1, t('profileForm.validation.genderRequired')), + dob: z.string().min(1, t('profileForm.validation.dobRequired')), + pob: z.string().optional(), + maritalStatus: z.string().min(1, t('profileForm.validation.maritalStatusRequired')), + }); -export type ProfileValues = z.infer; +export type ProfileValues = z.infer>; export const GENDERS = ['MALE', 'FEMALE'] as const; export const MARITAL_STATUSES = ['SINGLE', 'MARRIED', 'DIVORCED', 'WIDOWED'] as const; @@ -45,8 +47,8 @@ export function ProfileFormContent({ return ( ({ value: g, label: t(`profileForm.genders.${g}`) }))} error={errors.gender?.message} value={watch('gender')} onChange={(val) => setValue('gender', val || '', { shouldValidate: true })} @@ -91,7 +93,7 @@ export function ProfileFormContent({ name="gender" /> setValue('dob', val, { shouldValidate: true })} @@ -100,16 +102,16 @@ export function ProfileFormContent({ error={errors.dob?.message} />