From ba7cee8afab121166fa5b1c7fbcdf51c41046c34 Mon Sep 17 00:00:00 2001 From: Dawn Carrasco Date: Wed, 6 Mar 2024 15:22:17 +0800 Subject: [PATCH] chore: update on datepicker --- src/components/Datepicker/Datepicker.tsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/Datepicker/Datepicker.tsx b/src/components/Datepicker/Datepicker.tsx index 4630fad..1a31720 100644 --- a/src/components/Datepicker/Datepicker.tsx +++ b/src/components/Datepicker/Datepicker.tsx @@ -19,7 +19,7 @@ export interface DatepickerProps { * Callback fired when the date changes */ onChange?: (date: Date | null) => void; - onTimeChange?: (time: string) => void; + onTimeChange?: (time: string, date: Date | null) => void; onClose?: () => void; popoverCs?: customStyles; isBlock?: boolean; @@ -30,11 +30,12 @@ export interface DatepickerProps { } interface TimePickerProps { - selectedTime: any; // Assuming selectedTime is a string in the format "HH:mm" - onTimeChange: (time: string) => void; + selectedTime: string; // Assuming selectedTime is a string in the format "HH:mm" + selectedDate?: Date | null; + onTimeChange: (time: string, date: Date | null) => void; } -const TimePicker: React.FC = ({selectedTime, onTimeChange}) => { +const TimePicker: React.FC = ({selectedTime, selectedDate = null, onTimeChange}) => { const [inputValue, setInputValue] = useState(selectedTime); useEffect(() => { @@ -50,7 +51,7 @@ const TimePicker: React.FC = ({selectedTime, onTimeChange}) => setInputValue(newTime); if (onTimeChange) { - onTimeChange(newTime); + onTimeChange(newTime, selectedDate); } }; @@ -84,8 +85,8 @@ const TimePicker: React.FC = ({selectedTime, onTimeChange}) => * */ const Datepicker = ({ - defaultDate, - defaultTime, + defaultDate = null, + defaultTime = "", onChange, onTimeChange, onClose, @@ -122,7 +123,7 @@ const Datepicker = ({ const todaysTime = `NA:${seconds.toString().padStart(2, "0")}`; setSelectedTime(todaysTime); if (onTimeChange) { - onTimeChange(""); + onTimeChange("", null); } } }; @@ -146,7 +147,7 @@ const Datepicker = ({ } if (onTimeChange && hasTime) { - onTimeChange(todaysTime.substring(0, 5)); + onTimeChange(todaysTime.substring(0, 5), todaysDate); } }; @@ -177,6 +178,7 @@ const Datepicker = ({ {hasTime && ( {})} /> )}