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-11-23 02:55:25 +00:00
|
|
|
import { ITimezoneOption, TimezoneSelect } from "@calcom/ui";
|
2022-05-23 11:12:41 +00:00
|
|
|
|
2022-10-25 00:14:06 +00:00
|
|
|
import { timeZone } from "../../lib/clock";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
type Props = {
|
|
|
|
onSelectTimeZone: (selectedTimeZone: string) => void;
|
|
|
|
};
|
|
|
|
|
2022-10-25 00:14:06 +00:00
|
|
|
const TimeOptions: FC<Props> = ({ onSelectTimeZone }) => {
|
2021-06-30 01:35:08 +00:00
|
|
|
const [selectedTimeZone, setSelectedTimeZone] = useState("");
|
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
|
|
|
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]);
|
2022-10-14 19:15:03 +00:00
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
return selectedTimeZone !== "" ? (
|
2022-10-05 13:11:26 +00:00
|
|
|
<div className="dark:border-darkgray-300 dark:bg-darkgray-200 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>
|
2021-06-20 14:19:41 +00:00
|
|
|
</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;
|