diff --git a/components/TempDesignSystem/Form/Date/index.tsx b/components/TempDesignSystem/Form/Date/index.tsx index 36a0ff44a..268b2c30d 100644 --- a/components/TempDesignSystem/Form/Date/index.tsx +++ b/components/TempDesignSystem/Form/Date/index.tsx @@ -21,7 +21,7 @@ import type { DateProps } from "./date" export default function DateSelect({ name, registerOptions = {} }: DateProps) { const intl = useIntl() - const { control, setValue, trigger, formState, watch } = useFormContext() + const { control, setValue, formState, watch } = useFormContext() const { field, fieldState } = useController({ control, name, @@ -43,20 +43,6 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) { .reverse() .map((year) => ({ value: year, label: year.toString() })) - function getDaysInMonth(year: number | null, month: number | null): number { - if (month === null) { - return 31 - } - - // If month is February and no year selected, return minimum. - if (month === 1 && !year) { - return 28 - } - - const yearToUse = year ?? new Date().getFullYear() - return dt(`${yearToUse}-${month + 1}-01`).daysInMonth() - } - // Calculate available days based on selected year and month const daysInMonth = getDaysInMonth( year ? Number(year) : null, @@ -202,3 +188,17 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) { ) } + +function getDaysInMonth(year: number | null, month: number | null): number { + if (month === null) { + return 31 + } + + // If month is February and no year selected, return minimum. + if (month === 1 && !year) { + return 28 + } + + const yearToUse = year ?? new Date().getFullYear() + return dt(`${yearToUse}-${month + 1}-01`).daysInMonth() +}