2021-06-24 22:15:18 +00:00
|
|
|
import { ClockIcon } from "@heroicons/react/outline";
|
|
|
|
import { useRef } from "react";
|
2021-06-16 22:27:27 +00:00
|
|
|
|
2021-10-15 10:53:42 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
2022-02-10 09:37:00 +00:00
|
|
|
import showToast from "@lib/notification";
|
2021-11-29 06:37:31 +00:00
|
|
|
import Button from "@components/ui/Button";
|
|
|
|
|
2022-02-09 00:05:13 +00:00
|
|
|
interface SetTimesModalProps {
|
|
|
|
startTime: number;
|
|
|
|
endTime: number;
|
|
|
|
onChange: (times: { startTime: number; endTime: number }) => void;
|
|
|
|
onExit: (...p: unknown[]) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function SetTimesModal(props: SetTimesModalProps) {
|
2021-10-15 10:53:42 +00:00
|
|
|
const { t } = useLocale();
|
2021-06-29 22:00:25 +00:00
|
|
|
const [startHours, startMinutes] = [Math.floor(props.startTime / 60), props.startTime % 60];
|
|
|
|
const [endHours, endMinutes] = [Math.floor(props.endTime / 60), props.endTime % 60];
|
2022-02-09 00:05:13 +00:00
|
|
|
const startHoursRef = useRef<HTMLInputElement>(null!);
|
|
|
|
const startMinsRef = useRef<HTMLInputElement>(null!);
|
|
|
|
const endHoursRef = useRef<HTMLInputElement>(null!);
|
|
|
|
const endMinsRef = useRef<HTMLInputElement>(null!);
|
2021-06-16 22:27:27 +00:00
|
|
|
|
2022-02-10 09:37:00 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2021-06-16 22:27:27 +00:00
|
|
|
return (
|
2021-06-24 22:15:18 +00:00
|
|
|
<div
|
2021-11-29 06:37:31 +00:00
|
|
|
className="fixed inset-0 z-50 overflow-y-auto"
|
2021-06-24 22:15:18 +00:00
|
|
|
aria-labelledby="modal-title"
|
|
|
|
role="dialog"
|
|
|
|
aria-modal="true">
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="flex min-h-screen items-end justify-center px-4 pt-4 pb-20 text-center sm:block sm:p-0">
|
2021-08-08 19:21:33 +00:00
|
|
|
<div
|
2022-02-09 00:05:13 +00:00
|
|
|
className="fixed inset-0 z-0 bg-gray-500 bg-opacity-75 transition-opacity"
|
2021-08-08 19:21:33 +00:00
|
|
|
aria-hidden="true"></div>
|
2021-06-16 22:27:27 +00:00
|
|
|
|
2022-02-09 00:05:13 +00:00
|
|
|
<span className="hidden sm:inline-block sm:h-screen sm:align-middle" aria-hidden="true">
|
2021-06-24 22:15:18 +00:00
|
|
|
​
|
|
|
|
</span>
|
2021-06-16 22:27:27 +00:00
|
|
|
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="inline-block transform overflow-hidden rounded-lg bg-white px-4 pt-5 pb-4 text-left align-bottom shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6 sm:align-middle">
|
2021-11-29 06:37:31 +00:00
|
|
|
<div className="mb-4 sm:flex sm:items-start">
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-blue-100 sm:mx-0 sm:h-10 sm:w-10">
|
|
|
|
<ClockIcon className="h-6 w-6 text-black" />
|
2021-06-16 22:27:27 +00:00
|
|
|
</div>
|
|
|
|
<div className="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
|
2021-11-29 06:37:31 +00:00
|
|
|
<h3 className="text-lg font-medium leading-6 text-gray-900" id="modal-title">
|
2021-10-15 10:53:42 +00:00
|
|
|
{t("change_bookings_availability")}
|
2021-06-16 22:27:27 +00:00
|
|
|
</h3>
|
|
|
|
<div>
|
2021-10-15 10:53:42 +00:00
|
|
|
<p className="text-sm text-gray-500">{t("set_work_schedule")}</p>
|
2021-06-16 22:27:27 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mb-4 flex">
|
2021-11-29 06:37:31 +00:00
|
|
|
<label className="block w-1/4 pt-2 text-sm font-medium text-gray-700">{t("start_time")}</label>
|
2021-06-16 22:27:27 +00:00
|
|
|
<div>
|
2021-06-24 22:15:18 +00:00
|
|
|
<label htmlFor="startHours" className="sr-only">
|
2021-10-15 10:53:42 +00:00
|
|
|
{t("hours")}
|
2021-06-24 22:15:18 +00:00
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
ref={startHoursRef}
|
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
max="23"
|
2022-02-09 00:05:13 +00:00
|
|
|
maxLength={2}
|
2021-06-24 22:15:18 +00:00
|
|
|
name="hours"
|
|
|
|
id="startHours"
|
2022-02-09 22:32:31 +00:00
|
|
|
className="focus:border-brand block w-full rounded-md border-gray-300 shadow-sm focus:ring-black sm:text-sm"
|
2021-06-24 22:15:18 +00:00
|
|
|
placeholder="9"
|
2021-06-29 22:00:25 +00:00
|
|
|
defaultValue={startHours}
|
2021-06-24 22:15:18 +00:00
|
|
|
/>
|
2021-06-16 22:27:27 +00:00
|
|
|
</div>
|
2022-02-09 00:05:13 +00:00
|
|
|
<span className="mx-2 pt-1">:</span>
|
2021-06-16 22:27:27 +00:00
|
|
|
<div>
|
2021-06-24 22:15:18 +00:00
|
|
|
<label htmlFor="startMinutes" className="sr-only">
|
2021-10-15 10:53:42 +00:00
|
|
|
{t("minutes")}
|
2021-06-24 22:15:18 +00:00
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
ref={startMinsRef}
|
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
max="59"
|
|
|
|
step="15"
|
2022-02-09 00:05:13 +00:00
|
|
|
maxLength={2}
|
2021-06-24 22:15:18 +00:00
|
|
|
name="minutes"
|
|
|
|
id="startMinutes"
|
2022-02-09 22:32:31 +00:00
|
|
|
className="focus:border-brand block w-full rounded-md border-gray-300 shadow-sm focus:ring-black sm:text-sm"
|
2021-06-24 22:15:18 +00:00
|
|
|
placeholder="30"
|
2021-06-29 22:00:25 +00:00
|
|
|
defaultValue={startMinutes}
|
2021-06-24 22:15:18 +00:00
|
|
|
/>
|
2021-06-16 22:27:27 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex">
|
2021-11-29 06:37:31 +00:00
|
|
|
<label className="block w-1/4 pt-2 text-sm font-medium text-gray-700">{t("end_time")}</label>
|
2021-06-16 22:27:27 +00:00
|
|
|
<div>
|
2021-06-24 22:15:18 +00:00
|
|
|
<label htmlFor="endHours" className="sr-only">
|
2021-10-15 10:53:42 +00:00
|
|
|
{t("hours")}
|
2021-06-24 22:15:18 +00:00
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
ref={endHoursRef}
|
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
max="24"
|
2022-02-09 00:05:13 +00:00
|
|
|
maxLength={2}
|
2021-06-24 22:15:18 +00:00
|
|
|
name="hours"
|
|
|
|
id="endHours"
|
2022-02-09 22:32:31 +00:00
|
|
|
className="focus:border-brand block w-full rounded-md border-gray-300 shadow-sm focus:ring-black sm:text-sm"
|
2021-06-24 22:15:18 +00:00
|
|
|
placeholder="17"
|
2021-06-29 22:00:25 +00:00
|
|
|
defaultValue={endHours}
|
2021-06-24 22:15:18 +00:00
|
|
|
/>
|
2021-06-16 22:27:27 +00:00
|
|
|
</div>
|
2022-02-09 00:05:13 +00:00
|
|
|
<span className="mx-2 pt-1">:</span>
|
2021-06-16 22:27:27 +00:00
|
|
|
<div>
|
2021-06-24 22:15:18 +00:00
|
|
|
<label htmlFor="endMinutes" className="sr-only">
|
2021-10-15 10:53:42 +00:00
|
|
|
{t("minutes")}
|
2021-06-24 22:15:18 +00:00
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
ref={endMinsRef}
|
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
max="59"
|
2022-02-09 00:05:13 +00:00
|
|
|
maxLength={2}
|
2021-06-24 22:15:18 +00:00
|
|
|
step="15"
|
|
|
|
name="minutes"
|
|
|
|
id="endMinutes"
|
2022-02-09 22:32:31 +00:00
|
|
|
className="focus:border-brand block w-full rounded-md border-gray-300 shadow-sm focus:ring-black sm:text-sm"
|
2021-06-24 22:15:18 +00:00
|
|
|
placeholder="30"
|
2021-06-29 22:00:25 +00:00
|
|
|
defaultValue={endMinutes}
|
2021-06-24 22:15:18 +00:00
|
|
|
/>
|
2021-06-16 22:27:27 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
|
2022-02-09 00:05:13 +00:00
|
|
|
<Button
|
|
|
|
onClick={(event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
const enteredStartHours = parseInt(startHoursRef.current.value);
|
|
|
|
const enteredStartMins = parseInt(startMinsRef.current.value);
|
|
|
|
const enteredEndHours = parseInt(endHoursRef.current.value);
|
|
|
|
const enteredEndMins = parseInt(endMinsRef.current.value);
|
|
|
|
|
2022-02-10 09:37:00 +00:00
|
|
|
if (
|
|
|
|
isValidTime(
|
|
|
|
enteredStartHours * 60 + enteredStartMins,
|
|
|
|
enteredEndHours * 60 + enteredEndMins
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
props.onChange({
|
|
|
|
startTime: enteredStartHours * 60 + enteredStartMins,
|
|
|
|
endTime: enteredEndHours * 60 + enteredEndMins,
|
|
|
|
});
|
|
|
|
props.onExit(0);
|
|
|
|
}
|
2022-02-09 00:05:13 +00:00
|
|
|
}}
|
|
|
|
type="submit">
|
2021-10-15 10:53:42 +00:00
|
|
|
{t("save")}
|
2021-11-29 06:37:31 +00:00
|
|
|
</Button>
|
2022-02-01 22:17:37 +00:00
|
|
|
<Button onClick={props.onExit} type="button" color="secondary" className="ltr:mr-2">
|
2021-10-15 10:53:42 +00:00
|
|
|
{t("cancel")}
|
2021-11-29 06:37:31 +00:00
|
|
|
</Button>
|
2021-06-16 22:27:27 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-24 22:15:18 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|