Skip to content

Commit

Permalink
(feat) 03-3404: follow-up -ensure the dateAppointmentScheduled <= app…
Browse files Browse the repository at this point in the history
…ointmentDate (#1295)
  • Loading branch information
lucyjemutai authored Aug 28, 2024
1 parent f21abc4 commit f99530d
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,22 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
)
.refine(
(formValues) => {
const appointmentDate = formValues.appointmentDateTime?.startDate;
const dateAppointmentScheduled = formValues.dateAppointmentScheduled;
const { appointmentDateTime, dateAppointmentScheduled } = formValues;

if (!appointmentDate || !dateAppointmentScheduled) return true;
return dateAppointmentScheduled < appointmentDate;
const startDate = appointmentDateTime?.startDate;

if (!startDate || !dateAppointmentScheduled) return true;

const normalizeDate = (date: Date) => {
const normalizedDate = new Date(date);
normalizedDate.setHours(0, 0, 0, 0);
return normalizedDate;
};

const startDateObj = normalizeDate(startDate);
const scheduledDateObj = normalizeDate(dateAppointmentScheduled);

return scheduledDateObj <= startDateObj;
},
{
path: ['dateAppointmentScheduled'],
Expand All @@ -195,6 +206,7 @@ const AppointmentsForm: React.FC<AppointmentsFormProps> = ({
),
},
);

type AppointmentFormData = z.infer<typeof appointmentsFormSchema>;

const defaultDateAppointmentScheduled = appointment?.dateAppointmentScheduled
Expand Down

0 comments on commit f99530d

Please sign in to comment.