From 9ebe706ef9ec4b71770a9905c05d91cc5a2b8122 Mon Sep 17 00:00:00 2001 From: rgrgogu Date: Wed, 15 Jul 2026 23:12:51 +0800 Subject: [PATCH] changed native date to shadcn --- src/modules/auth/components/RegisterForm.jsx | 57 +++++++++++++++++--- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/src/modules/auth/components/RegisterForm.jsx b/src/modules/auth/components/RegisterForm.jsx index 7261106..c6c6cbb 100644 --- a/src/modules/auth/components/RegisterForm.jsx +++ b/src/modules/auth/components/RegisterForm.jsx @@ -17,16 +17,19 @@ ***********************************************************************************************************************************************************************/ import { useState } from 'react' import { useNavigate, Link, useSearchParams } from 'react-router-dom' -import { useForm } from 'react-hook-form' +import { useForm, Controller } from 'react-hook-form' import { useAuth } from '@/contexts/AuthContext' import { z } from 'zod' import { zodResolver } from '@hookform/resolvers/zod' +import { format, parseISO, isValid as isValidDate } from 'date-fns' import { cn } from '@/lib/utils' import { OtpVerifyForm } from './OtpVerifyForm' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Badge } from '@/components/ui/badge' +import { Calendar } from '@/components/ui/calendar' +import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' import { AlertDialog, AlertDialogAction, @@ -36,7 +39,11 @@ import { AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog' -import { Eye, EyeOff, LoaderCircle, Users, Check } from 'lucide-react' +import { Eye, EyeOff, LoaderCircle, Users, Check, CalendarIcon } from 'lucide-react' + +// Birthday must put the user between 13 and 120 years old (mirrors personalSchema below) +const MIN_BIRTHDATE = new Date(new Date().getFullYear() - 120, 0, 1) +const MAX_BIRTHDATE = new Date(new Date().getFullYear() - 13, new Date().getMonth(), new Date().getDate()) // ─── Step schemas ───────────────────────────────────────────────────────────── const personalSchema = z.object({ @@ -141,6 +148,7 @@ export function RegisterForm({ className, ...props }) { const [showConfirm, setShowConfirm] = useState(false) const [errorDialogOpen, setErrorDialogOpen] = useState(false) const [errorMessage, setErrorMessage] = useState('') + const [birthdayOpen, setBirthdayOpen] = useState(false) // Accumulated data across steps const [personalData, setPersonalData] = useState({}) @@ -149,6 +157,7 @@ export function RegisterForm({ className, ...props }) { const { register: regPersonal, handleSubmit: submitPersonal, + control: controlPersonal, formState: { errors: errPersonal }, } = useForm({ resolver: zodResolver(personalSchema), @@ -304,12 +313,44 @@ export function RegisterForm({ className, ...props }) { - { + const selectedDate = field.value ? parseISO(field.value) : undefined + const validSelected = selectedDate && isValidDate(selectedDate) ? selectedDate : undefined + + return ( + + + + + + { + field.onChange(date ? format(date, 'yyyy-MM-dd') : '') + setBirthdayOpen(false) + }} + /> + + + ) + }} /> {errPersonal.date_of_birth && (

{errPersonal.date_of_birth.message}