Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
chore: update on datepicker
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawn Carrasco authored and Dawn Carrasco committed Mar 6, 2024
1 parent 7db50dd commit ba7cee8
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/components/Datepicker/Datepicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<TimePickerProps> = ({selectedTime, onTimeChange}) => {
const TimePicker: React.FC<TimePickerProps> = ({selectedTime, selectedDate = null, onTimeChange}) => {
const [inputValue, setInputValue] = useState(selectedTime);

useEffect(() => {
Expand All @@ -50,7 +51,7 @@ const TimePicker: React.FC<TimePickerProps> = ({selectedTime, onTimeChange}) =>
setInputValue(newTime);

if (onTimeChange) {
onTimeChange(newTime);
onTimeChange(newTime, selectedDate);
}
};

Expand Down Expand Up @@ -84,8 +85,8 @@ const TimePicker: React.FC<TimePickerProps> = ({selectedTime, onTimeChange}) =>
*
*/
const Datepicker = ({
defaultDate,
defaultTime,
defaultDate = null,
defaultTime = "",
onChange,
onTimeChange,
onClose,
Expand Down Expand Up @@ -122,7 +123,7 @@ const Datepicker = ({
const todaysTime = `NA:${seconds.toString().padStart(2, "0")}`;
setSelectedTime(todaysTime);
if (onTimeChange) {
onTimeChange("");
onTimeChange("", null);
}
}
};
Expand All @@ -146,7 +147,7 @@ const Datepicker = ({
}

if (onTimeChange && hasTime) {
onTimeChange(todaysTime.substring(0, 5));
onTimeChange(todaysTime.substring(0, 5), todaysDate);
}
};

Expand Down Expand Up @@ -177,6 +178,7 @@ const Datepicker = ({
{hasTime && (
<TimePicker
selectedTime={selectedTime}
selectedDate={selectedDate}
onTimeChange={onTimeChange || (() => {})}
/>
)}
Expand Down

0 comments on commit ba7cee8

Please sign in to comment.