diff --git a/components/Forms/Signup/schema.ts b/components/Forms/Signup/schema.ts index 6a8eecc22..2962d9b90 100644 --- a/components/Forms/Signup/schema.ts +++ b/components/Forms/Signup/schema.ts @@ -16,7 +16,9 @@ export const signUpSchema = z.object({ "Phone is required", "Please enter a valid phone number" ), - dateOfBirth: z.string().min(1), + dateOfBirth: z.string().min(1, { + message: "Date of birth is required", + }), address: z.object({ countryCode: z .string({ diff --git a/components/TempDesignSystem/Form/Date/index.tsx b/components/TempDesignSystem/Form/Date/index.tsx index 3f56edcfb..c2754bb13 100644 --- a/components/TempDesignSystem/Form/Date/index.tsx +++ b/components/TempDesignSystem/Form/Date/index.tsx @@ -56,15 +56,20 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) { .reverse() .map((year) => ({ value: year, label: year.toString() })) - const daysInMonth = - selectedMonth !== null && selectedYear !== null - ? dt(`${selectedYear}-${selectedMonth + 1}-01`).daysInMonth() - : 31 + function getDaysInMonth(year: number | null, month: number | null): number { + if (month === null) { + return 31 + } + const yearToUse = year ?? new Date().getFullYear() + return dt(`${yearToUse}-${month + 1}-01`).daysInMonth() + } - const days = rangeArray(1, daysInMonth).map((day) => ({ - value: day, - label: `${day}`, - })) + const days = rangeArray(1, getDaysInMonth(selectedYear, selectedMonth)).map( + (day) => ({ + value: day, + label: `${day}`, + }) + ) function handleSegmentChange(selector: DateName, value: number) { let newYear = selectedYear @@ -84,7 +89,7 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) { newMonth = value - 1 setSelectedMonth(newMonth) if (selectedDay) { - const maxDays = dt(`${newYear}-${value}-01`).daysInMonth() + const maxDays = getDaysInMonth(newYear, newMonth) if (selectedDay > maxDays) { newDay = maxDays setSelectedDay(newDay)