"use client"; import { CalendarHijri } from "@/components/UI/Calendar"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/UI/Popover"; import { motion } from "framer-motion"; import { useState } from "react"; import { Path, UseFormSetValue } from "react-hook-form"; type Props> = { name: Path; label?: string | null; setValue: UseFormSetValue; defaultValue?: string | null; }; export default function DatePickerField>({ name, label, setValue, defaultValue, }: Props) { const [date, setDate] = useState(defaultValue ? new Date(defaultValue) : undefined); const [open, setOpen] = useState(false); // format date into Persian numerals const formatJalali = (date?: Date) => { if (!date) return ""; const formatter = new Intl.DateTimeFormat("fa-IR", { year: "numeric", month: "2-digit", day: "2-digit", }); return formatter.format(date); }; return (
{label}
{ setDate(selectedDate); if (selectedDate) { setValue(name, selectedDate.toISOString() as any, { shouldValidate: true }); setOpen(false); } }} />
); }