diff --git a/components/ui/form/Schedule.tsx b/components/ui/form/Schedule.tsx index 649d0652f3..9487f63dbb 100644 --- a/components/ui/form/Schedule.tsx +++ b/components/ui/form/Schedule.tsx @@ -48,34 +48,52 @@ type TimeRangeFieldProps = { const TimeRangeField = ({ name }: TimeRangeFieldProps) => { // Lazy-loaded options, otherwise adding a field has a noticable redraw delay. const [options, setOptions] = useState([]); + const [selected, setSelected] = useState(); // const { i18n } = useLocale(); + + const handleSelected = (value: number | undefined) => { + setSelected(value); + }; + const getOption = (time: ConfigType) => ({ value: dayjs(time).toDate().valueOf(), label: dayjs(time).utc().format("HH:mm"), // .toLocaleTimeString(i18n.language, { minute: "numeric", hour: "numeric" }), }); - const timeOptions = useCallback((offsetOrLimit: { offset?: number; limit?: number } = {}) => { - const { limit, offset } = offsetOrLimit; - return TIMES.filter((time) => (!limit || time.isBefore(limit)) && (!offset || time.isAfter(offset))).map( - (t) => getOption(t) - ); - }, []); + const timeOptions = useCallback( + (offsetOrLimitorSelected: { offset?: number; limit?: number; selected?: number } = {}) => { + const { limit, offset, selected } = offsetOrLimitorSelected; + return TIMES.filter( + (time) => + (!limit || time.isBefore(limit)) && + (!offset || time.isAfter(offset)) && + (!selected || time.isAfter(selected)) + ).map((t) => getOption(t)); + }, + [] + ); return ( <> ( - setOptions(timeOptions())} + onBlur={() => setOptions([])} + defaultValue={getOption(value)} + onChange={(option) => { + onChange(new Date(option?.value as number)); + handleSelected(option?.value); + }} + /> + ); + }} /> - { 0} @@ -136,7 +154,7 @@ const ScheduleBlock = ({ name, day, weekday }: ScheduleBlockProps) => {
{fields.map((field, index) => (
-
+
+ {form.formState.errors.schedule && ( + + )}
diff --git a/public/static/locales/en/common.json b/public/static/locales/en/common.json index 67a349acad..7ce1583843 100644 --- a/public/static/locales/en/common.json +++ b/public/static/locales/en/common.json @@ -231,6 +231,14 @@ "failed": "Failed", "password_has_been_reset_login": "Your password has been reset. You can now login with your newly created password.", "unexpected_error_try_again": "An unexpected error occurred. Try again.", + "sunday_time_error":"Invalid time on Sunday", + "monday_time_error":"Invalid time on Monday", + "tuesday_time_error":"Invalid time on Tuesday", + "wednesday_time_error":"Invalid time on Wednesday", + "thursday_time_error":"Invalid time on Thursday", + "friday_time_error":"Invalid time on Friday", + "saturday_time_error":"Invalid time on Saturday", + "error_end_time_before_start_time": "End time cannot be before start time", "back_to_bookings": "Back to bookings", "free_to_pick_another_event_type": "Feel free to pick another event anytime.", "cancelled": "Cancelled",