diff --git a/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx b/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx index 3550d6de26bab8fafe9eaed2f42b72ce1c89484f..7b158bd04aa6799974f60347a5098c7c5e79f016 100644 --- a/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx +++ b/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx @@ -305,9 +305,6 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) { control={control} rules={{ required: true, - validate: () => - Number(getValues('start_date')) <= - Number(getValues('end_date')), }} render={({ field }) => ( <DatePicker @@ -315,6 +312,7 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) { label={t('input.roleEndDate')} disabled={!roleTypeChoice} value={endDate} + minDate={today} maxDate={maxDate} inputFormat="yyyy-MM-dd" onChange={(value) => { diff --git a/frontend/src/routes/sponsor/register/formData.ts b/frontend/src/routes/sponsor/register/formData.ts index b0ccade7cd7e21f45807029e6b6ee64875d53b06..af92bb905f17946ab756dd6026396dcb82a85d8e 100644 --- a/frontend/src/routes/sponsor/register/formData.ts +++ b/frontend/src/routes/sponsor/register/formData.ts @@ -3,7 +3,7 @@ export type RegisterFormData = { last_name?: string role_type?: number role_start: Date - role_end: Date + role_end: Date | null contact_person_unit?: string comment?: string ou_id?: number diff --git a/frontend/src/routes/sponsor/register/stepPersonForm.tsx b/frontend/src/routes/sponsor/register/stepPersonForm.tsx index 4b2c63aa678241dd93452e3b70ef4d95c563c6e1..49fc572c791f3003b33e38d172e66c2edd4150e3 100644 --- a/frontend/src/routes/sponsor/register/stepPersonForm.tsx +++ b/frontend/src/routes/sponsor/register/stepPersonForm.tsx @@ -69,7 +69,6 @@ const StepPersonForm = forwardRef( formState: { errors }, setValue, getValues, - trigger, } = useForm<RegisterFormData>({ mode: 'onTouched', defaultValues: formData, @@ -103,9 +102,6 @@ const StepPersonForm = forwardRef( : roleTypes.find((rt) => rt.id === roleTypeId) const maxDate = getMaxDateForRoleType(selectedRoleTypeInfo) setTodayPlusMaxDays(maxDate) - // Trigger revalidation of role end since the max end date is - // different for different role types - trigger('role_end') } // When the component is first rendered and there is some role_type set in @@ -319,13 +315,14 @@ const StepPersonForm = forwardRef( <Controller name="role_end" control={control} - defaultValue={today} + rules={{ required: true }} render={({ field }) => ( <DatePicker mask="____-__-__" label={t('input.roleEndDate')} - maxDate={todayPlusMaxDays} value={field.value} + minDate={today} + maxDate={todayPlusMaxDays} inputFormat="yyyy-MM-dd" onChange={(value) => { field.onChange(value) @@ -334,6 +331,11 @@ const StepPersonForm = forwardRef( /> )} /> + {!!errors.role_end && ( + <Box sx={{ typography: 'caption', color: 'red' }}> + {t('validation.roleEndRequired')} + </Box> + )} {displayContactAtUnit && ( <TextField diff --git a/frontend/src/routes/sponsor/register/stepRegistration.tsx b/frontend/src/routes/sponsor/register/stepRegistration.tsx index 23e6034ad8c5aff094e125c88453c6420ebe5264..4fe22457a609006d39f6e8c757d8f4d985c5d3b4 100644 --- a/frontend/src/routes/sponsor/register/stepRegistration.tsx +++ b/frontend/src/routes/sponsor/register/stepRegistration.tsx @@ -38,9 +38,9 @@ export default function StepRegistration() { first_name: undefined, last_name: undefined, role_type: undefined, - // Having role_start and role_end to be nullable caused problems when specifying a default value, so instead having them as non-null and use today as the default date here + // Having role_start to be nullable caused problems when specifying a default value, so instead having them as non-null and use today as the default date here role_start: new Date(), - role_end: new Date(), + role_end: null, comment: undefined, ou_id: undefined, email: undefined,