2021-09-29 21:33:18 +00:00
|
|
|
import { FC, useEffect, useState } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-03-11 00:26:42 +00:00
|
|
|
import Switch from "@calcom/ui/Switch";
|
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
2021-06-20 14:19:41 +00:00
|
|
|
|
2022-05-23 11:12:41 +00:00
|
|
|
import TimezoneSelect, { ITimezoneOption } from "@components/ui/form/TimezoneSelect";
|
|
|
|
|
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-02-23 12:37:15 +00:00
|
|
|
const TimeOptions: FC<Props> = ({ onToggle24hClock, onSelectTimeZone }) => {
|
2021-06-30 01:35:08 +00:00
|
|
|
const [selectedTimeZone, setSelectedTimeZone] = useState("");
|
2021-06-20 14:19:41 +00:00
|
|
|
const [is24hClock, setIs24hClock] = useState(false);
|
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-02-09 22:32:31 +00:00
|
|
|
<div className="max-w-80 absolute z-10 w-full rounded-sm border border-gray-200 bg-white px-4 py-2 dark:border-0 dark:bg-gray-700">
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mb-4 flex">
|
2022-03-11 00:26:42 +00:00
|
|
|
<div className="font-medium text-gray-600 dark:text-white">{t("time_options")}</div>
|
|
|
|
<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-02-09 22:32:31 +00:00
|
|
|
className="focus:border-brand mt-1 mb-2 block w-full rounded-md border-gray-300 shadow-sm focus:ring-black sm:text-sm"
|
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;
|