From 2368df5f5eee51e43372657778183139ff1a0fb5 Mon Sep 17 00:00:00 2001 From: Jakob Wennberg Date: Wed, 4 Mar 2026 20:56:10 +0100 Subject: [PATCH] fix: simplify onboarding fiscal year start to month/year picker Remove the Day dropdown since fiscal year always starts on the 1st. Fix selection bug where picking month first showed nothing because the compose function required all three values before updating the form. Co-Authored-By: Claude Opus 4.6 --- .../onboarding/Step3TaxRegistration.tsx | 64 ++++++++----------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/components/onboarding/Step3TaxRegistration.tsx b/components/onboarding/Step3TaxRegistration.tsx index 2f0ca119..36392d31 100644 --- a/components/onboarding/Step3TaxRegistration.tsx +++ b/components/onboarding/Step3TaxRegistration.tsx @@ -188,6 +188,18 @@ export default function Step3TaxRegistration({ } }, [vatRegistered, vatNumber, orgNumber, setValue]) + // State for first-year start date selectors (month/year) + const [startMonth, setStartMonth] = useState( + initialData.first_year_start + ? new Date(initialData.first_year_start).getMonth() + 1 + : 0 + ) + const [startYear, setStartYear] = useState( + initialData.first_year_start + ? new Date(initialData.first_year_start).getFullYear() + : 0 + ) + // State for AB first-year end month selector const [abEndMonth, setAbEndMonth] = useState( initialData.first_year_end @@ -380,48 +392,28 @@ export default function Step3TaxRegistration({ name="first_year_start" control={control} render={({ field }) => { - const parsed = field.value ? (() => { - const d = new Date(field.value) - if (isNaN(d.getTime())) return null - return { day: d.getDate(), month: d.getMonth() + 1, year: d.getFullYear() } - })() : null - - const selectedDay = parsed?.day ?? 0 - const selectedMonth = parsed?.month ?? 0 - const selectedYear = parsed?.year ?? 0 - const currentYear = new Date().getFullYear() const years = Array.from({ length: 7 }, (_, i) => currentYear - 5 + i) - const maxDays = selectedMonth && selectedYear - ? lastDayOfMonth(selectedYear, selectedMonth) - : 31 + const handleMonthChange = (month: number) => { + setStartMonth(month) + if (month && startYear) { + field.onChange(`${startYear}-${String(month).padStart(2, '0')}-01`) + } + } - const compose = (day: number, month: number, year: number) => { - if (day && month && year) { - const clamped = Math.min(day, lastDayOfMonth(year, month)) - field.onChange(`${year}-${String(month).padStart(2, '0')}-${String(clamped).padStart(2, '0')}`) + const handleYearChange = (year: number) => { + setStartYear(year) + if (startMonth && year) { + field.onChange(`${year}-${String(startMonth).padStart(2, '0')}-01`) } } return ( -
+
-