mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
changed native date to shadcn
This commit is contained in:
@@ -41,9 +41,10 @@ import {
|
|||||||
} from '@/components/ui/alert-dialog'
|
} from '@/components/ui/alert-dialog'
|
||||||
import { Eye, EyeOff, LoaderCircle, Users, Check, CalendarIcon } 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)
|
// Birthday must put the user's birth year between 3 and 120 years ago (mirrors personalSchema below).
|
||||||
|
// Bounds are whole calendar years (Jan 1 / Dec 31) so every month/day is selectable within a boundary year.
|
||||||
const MIN_BIRTHDATE = new Date(new Date().getFullYear() - 120, 0, 1)
|
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())
|
const MAX_BIRTHDATE = new Date(new Date().getFullYear() - 3, 11, 31)
|
||||||
|
|
||||||
// ─── Step schemas ─────────────────────────────────────────────────────────────
|
// ─── Step schemas ─────────────────────────────────────────────────────────────
|
||||||
const personalSchema = z.object({
|
const personalSchema = z.object({
|
||||||
@@ -56,9 +57,9 @@ const personalSchema = z.object({
|
|||||||
.min(1, 'Birthday is required')
|
.min(1, 'Birthday is required')
|
||||||
.refine((v) => !isNaN(Date.parse(v)), { message: 'Invalid date' })
|
.refine((v) => !isNaN(Date.parse(v)), { message: 'Invalid date' })
|
||||||
.refine((v) => {
|
.refine((v) => {
|
||||||
const age = (Date.now() - new Date(v)) / (1000 * 60 * 60 * 24 * 365.25)
|
const yearsAgo = new Date().getFullYear() - new Date(v).getFullYear()
|
||||||
return age >= 13 && age <= 120
|
return yearsAgo >= 3 && yearsAgo <= 120
|
||||||
}, { message: 'Must be at least 13 years old' }),
|
}, { message: 'Must be at least 3 years old' }),
|
||||||
occupation: z.string().min(1, 'Occupation is required').max(100),
|
occupation: z.string().min(1, 'Occupation is required').max(100),
|
||||||
phone: z.string().min(1, 'Phone number is required').regex(/^\+?[0-9\s\-()]{7,20}$/, 'Invalid phone number'),
|
phone: z.string().min(1, 'Phone number is required').regex(/^\+?[0-9\s\-()]{7,20}$/, 'Invalid phone number'),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user