2023-02-16 22:39:57 +00:00
|
|
|
import type { FC } from "react";
|
|
|
|
import { useEffect, useState } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { ITimezoneOption } from "@calcom/ui";
|
|
|
|
import { 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-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
|
|
|
|
2023-02-08 12:08:00 +00:00
|
|
|
return !!selectedTimeZone ? (
|
|
|
|
<TimezoneSelect
|
|
|
|
id="timeZone"
|
2023-03-26 19:19:13 +00:00
|
|
|
classNames={{
|
2023-04-05 18:14:46 +00:00
|
|
|
singleValue: () => "text-default",
|
|
|
|
dropdownIndicator: () => "text-default",
|
2023-03-26 19:19:13 +00:00
|
|
|
menu: () => "!w-64 max-w-[90vw]",
|
|
|
|
}}
|
|
|
|
variant="minimal"
|
2023-02-08 12:08:00 +00:00
|
|
|
value={selectedTimeZone}
|
|
|
|
onChange={(tz: ITimezoneOption) => setSelectedTimeZone(tz.value)}
|
|
|
|
/>
|
2021-09-29 21:33:18 +00:00
|
|
|
) : 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;
|