// * Other import { fr, enUS } from "date-fns/locale"; import { usePage } from "@inertiajs/react"; import { CalendarIcon, RefreshCcw } from "lucide-react"; // * Components shadcn import { Calendar } from "@/components/ui/calendar"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; import { Separator } from "@/components/ui/separator"; import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; // * Other import InputError from "@/back/Components/InputError"; import { cn, GetFormatedDate } from "@/lib/utils"; import str from "@/hooks/use-string"; import useLocale from "@/store/use-locale-store"; import useTrans from "@/hooks/use-translations"; type SimpleDatePickerProps = { name: string; placeholder?: string; date?: Date | null; required?: boolean; disabled?: boolean; className?: string; label: string; hasTime?: boolean; parentErrors?: Record | null; // eslint-disable-next-line no-unused-vars setData: (name: string, value: Date | null) => void; }; export default function SimpleDatePicker({ name, placeholder = "Sélectionner une date", date, required = false, disabled = false, className, label, hasTime = false, parentErrors = null, setData, }: SimpleDatePickerProps) { const { errors } = usePage().props; const localErrors = parentErrors ?? errors; let calendarLocale = fr; switch (usePage().props.locale) { case "en": calendarLocale = enUS; break; default: calendarLocale = fr; break; } const parsedDate = date ? new Date(date) : undefined; const hours = Array.from({ length: 24 }, (_, i) => i); const minutes = Array.from({ length: 12 }, (_, i) => i * 5); const handleDateSelect = (selectedDate: Date | undefined) => { if (selectedDate) { setData(name, selectedDate); } }; const resetDate = () => { setData(name, null); }; function handleTimeChange(type: "hour" | "minute", value: string) { const currentDate = parsedDate || new Date(); const newDate = new Date(currentDate); if (type === "hour") { const hour = parseInt(value, 10); newDate.setHours(hour); } else if (type === "minute") { newDate.setMinutes(parseInt(value, 10)); } setData(name, newDate); } return (
{hasTime && (
{hours.map((hour) => ( ))}
{minutes.map((minute) => ( ))}
)}
); }