2021-09-29 21:33:18 +00:00
|
|
|
import { FC, useEffect, useState } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-07-26 18:02:44 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-07-28 19:58:26 +00:00
|
|
|
import TimezoneSelect, { ITimezoneOption } from "@calcom/ui/form/TimezoneSelect";
|
2022-09-10 17:52:35 +00:00
|
|
|
import { Switch } from "@calcom/ui/v2";
|
2022-05-23 11:12:41 +00:00
|
|
|
|
2021-09-22 19:52:38 +00:00
|
|
|
import { is24h, timeZone } from "../../lib/clock";
|
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
type Props = {
|
|
|
|
onSelectTimeZone: (selectedTimeZone: string) => void;
|
|
|
|
onToggle24hClock: (is24hClock: boolean) => void;
|
2022-07-26 18:02:44 +00:00
|
|
|
timeFormat: string;
|
2021-09-29 21:33:18 +00:00
|
|
|
};
|
|
|
|
|
2022-07-26 18:02:44 +00:00
|
|
|
const TimeOptions: FC<Props> = ({ onToggle24hClock, onSelectTimeZone, timeFormat }) => {
|
2021-06-30 01:35:08 +00:00
|
|
|
const [selectedTimeZone, setSelectedTimeZone] = useState("");
|
2022-07-26 18:02:44 +00:00
|
|
|
const [is24hClock, setIs24hClock] = useState(timeFormat === "HH:mm" && true);
|
2021-10-12 13:11:33 +00:00
|
|
|
const { t } = useLocale();
|
2021-06-20 14:19:41 +00:00
|
|
|
|
2021-06-30 01:35:08 +00:00
|
|
|
useEffect(() => {
|
2021-06-20 14:19:41 +00:00
|
|
|
setIs24hClock(is24h());
|
|
|
|
setSelectedTimeZone(timeZone());
|
|
|
|
}, []);
|
|
|
|
|
2021-06-30 01:35:08 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (selectedTimeZone && timeZone() && selectedTimeZone !== timeZone()) {
|
2022-02-23 12:37:15 +00:00
|
|
|
onSelectTimeZone(timeZone(selectedTimeZone));
|
2021-06-30 01:35:08 +00:00
|
|
|
}
|
2022-02-23 12:37:15 +00:00
|
|
|
}, [selectedTimeZone, onSelectTimeZone]);
|
2021-08-19 12:36:17 +00:00
|
|
|
const handle24hClockToggle = (is24hClock: boolean) => {
|
|
|
|
setIs24hClock(is24hClock);
|
2022-02-23 12:37:15 +00:00
|
|
|
onToggle24hClock(is24h(is24hClock));
|
2021-08-19 12:36:17 +00:00
|
|
|
};
|
2021-06-20 14:19:41 +00:00
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
return selectedTimeZone !== "" ? (
|
2022-09-02 21:16:36 +00:00
|
|
|
<div className="max-w-80 dark:border-darkgray-300 dark:bg-darkgray-200 absolute z-10 w-full rounded-sm border border-gray-200 bg-white px-4 pt-4 pb-3 shadow-sm">
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mb-4 flex">
|
2022-08-05 08:46:44 +00:00
|
|
|
<div className="text-sm font-medium text-gray-600 dark:text-white">{t("time_options")}</div>
|
2022-03-11 00:26:42 +00:00
|
|
|
<div className="ml-auto flex items-center">
|
|
|
|
<label className="ltl:mr-3 mr-2 align-text-top text-sm font-medium text-neutral-700 ltr:ml-3 rtl:mr-3 dark:text-white">
|
|
|
|
{t("am_pm")}
|
|
|
|
</label>
|
|
|
|
<Switch
|
|
|
|
name="24hClock"
|
|
|
|
label={t("24_h")}
|
|
|
|
defaultChecked={is24hClock}
|
|
|
|
onCheckedChange={handle24hClockToggle}
|
|
|
|
/>
|
2021-06-20 14:19:41 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-29 21:33:18 +00:00
|
|
|
<TimezoneSelect
|
|
|
|
id="timeZone"
|
|
|
|
value={selectedTimeZone}
|
|
|
|
onChange={(tz: ITimezoneOption) => setSelectedTimeZone(tz.value)}
|
2022-07-27 02:24:00 +00:00
|
|
|
className="focus:border-brand mt-1 mb-2 block w-full rounded-md border-gray-300 text-sm focus:ring-black"
|
2021-09-29 21:33:18 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : null;
|
2021-06-30 01:35:08 +00:00
|
|
|
};
|
2021-06-20 14:19:41 +00:00
|
|
|
|
2021-06-30 01:35:08 +00:00
|
|
|
export default TimeOptions;
|