import dayjs from "dayjs"; import { isEqual } from "lodash-es"; import toast from "react-hot-toast"; import { cn } from "@/utils"; // Helper function to convert Date to local datetime string. const toLocalDateTimeString = (date: Date | undefined): string => { if (!date) return ""; return dayjs(date).format("YYYY-MM-DDTHH:mm:ss"); }; interface Props { value: Date | undefined; originalValue: Date | undefined; onChange: (date: Date) => void; } const DateTimeInput: React.FC = ({ value, originalValue, onChange }) => { return ( { const inputValue = e.target.value; if (inputValue) { const date = new Date(inputValue); if (!isNaN(date.getTime())) { onChange(date); } else { toast.error("Invalid datetime format. Use format: 2023-12-31T23:59:59"); e.target.value = toLocalDateTimeString(value); } } }} placeholder="YYYY-MM-DDTHH:mm:ss" /> ); }; export default DateTimeInput;