Scheduling infrastructure for absolutely everyone.
adds validation to event type availability (#1778)
Syed Ali Shahbazc4862c4b9283
diff --git a/components/ui/modal/SetTimesModal.tsx b/components/ui/modal/SetTimesModal.tsxindex ea8d9483582..25e202294d0 100644--- a/components/ui/modal/SetTimesModal.tsx+++ b/components/ui/modal/SetTimesModal.tsx@@ -2,7 +2,7 @@ import { ClockIcon } from "@heroicons/react/outline";import { useRef } from "react";import { useLocale } from "@lib/hooks/useLocale";-+import showToast from "@lib/notification";import Button from "@components/ui/Button";interface SetTimesModalProps {@@ -21,6 +21,18 @@ export default function SetTimesModal(props: SetTimesModalProps) {const endHoursRef = useRef<HTMLInputElement>(null!);const endMinsRef = useRef<HTMLInputElement>(null!);+ const isValidTime = (startTime: number, endTime: number) => {+ if (new Date(startTime) > new Date(endTime)) {+ showToast(t("error_end_time_before_start_time"), "error");+ return false;+ }+ if (endTime > 1440) {+ showToast(t("error_end_time_next_day"), "error");+ return false;+ }+ return true;+ };+return (<divclassName="fixed inset-0 z-50 overflow-y-auto"@@ -138,12 +150,18 @@ export default function SetTimesModal(props: SetTimesModalProps) {const enteredEndHours = parseInt(endHoursRef.current.value);const enteredEndMins = parseInt(endMinsRef.current.value);- props.onChange({- startTime: enteredStartHours * 60 + enteredStartMins,- endTime: enteredEndHours * 60 + enteredEndMins,- });-- props.onExit(0);+ if (+ isValidTime(+ enteredStartHours * 60 + enteredStartMins,+ enteredEndHours * 60 + enteredEndMins+ )+ ) {+ props.onChange({+ startTime: enteredStartHours * 60 + enteredStartMins,+ endTime: enteredEndHours * 60 + enteredEndMins,+ });+ props.onExit(0);+ }}}type="submit">{t("save")}diff --git a/public/static/locales/en/common.json b/public/static/locales/en/common.jsonindex 8711346e42b..08751484eda 100644--- a/public/static/locales/en/common.json+++ b/public/static/locales/en/common.json@@ -251,6 +251,7 @@"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",+ "error_end_time_next_day": "End time cannot be greater than 24 hours","back_to_bookings": "Back to bookings","free_to_pick_another_event_type": "Feel free to pick another event anytime.","cancelled": "Cancelled",