2021-09-29 21:33:18 +00:00
|
|
|
import { FC, useEffect, useState } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2023-02-08 12:08:00 +00:00
|
|
|
import useTheme from "@calcom/lib/hooks/useTheme";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { ITimezoneOption, TimezoneSelect } from "@calcom/ui";
|
2022-05-23 11:12:41 +00:00
|
|
|
|
2023-02-08 12:08:00 +00:00
|
|
|
import useMeQuery from "@lib/hooks/useMeQuery";
|
|
|
|
|
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("");
|
2023-02-08 12:08:00 +00:00
|
|
|
const query = useMeQuery();
|
|
|
|
const userTheme = useTheme(query?.data?.theme).resolvedTheme;
|
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
|
|
|
const customStyles = {
|
|
|
|
option: (_provided: object, state: { isSelected: boolean; isFocused: boolean }) => ({
|
|
|
|
padding: "10px 12px !important",
|
|
|
|
color: state.isSelected || state.isFocused ? "#101010" : "#374151",
|
|
|
|
backgroundColor: state.isSelected ? "#E5E7EB !important" : "white",
|
|
|
|
...(userTheme === "dark" && {
|
|
|
|
color: state.isSelected || state.isFocused ? "white" : "#80868B",
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
control: () => ({
|
|
|
|
display: "flex",
|
|
|
|
cursor: "pointer",
|
|
|
|
backgroundColor: "transparent !important",
|
|
|
|
minWidth: "5rem",
|
|
|
|
height: "24px",
|
|
|
|
minHeight: "24px !important",
|
|
|
|
boxShadow: "none !important",
|
|
|
|
}),
|
|
|
|
singleValue: (provided: object, state: { selectProps: { menuIsOpen: boolean } }) => ({
|
|
|
|
...provided,
|
|
|
|
color: state.selectProps.menuIsOpen ? "#111827" : "#4B5563",
|
|
|
|
...(userTheme === "dark" && {
|
|
|
|
color: "#a5a5a5 !important",
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
menu: (provided: object) => ({
|
|
|
|
...provided,
|
|
|
|
minWidth: "20rem",
|
|
|
|
margin: "8px 0 0 -20px",
|
|
|
|
}),
|
|
|
|
valueContainer: (provided: object) => ({
|
|
|
|
...provided,
|
|
|
|
padding: "0 0 0 6px",
|
|
|
|
}),
|
|
|
|
dropdownIndicator: (provided: object, state: { selectProps: { menuIsOpen: boolean } }) => ({
|
|
|
|
...provided,
|
|
|
|
transform: state.selectProps.menuIsOpen ? "rotate(180deg)" : "",
|
|
|
|
color: state.selectProps.menuIsOpen ? "#111827" : "#4B5563",
|
|
|
|
marginLeft: 4,
|
|
|
|
padding: 0,
|
|
|
|
...(userTheme === "dark" && {
|
|
|
|
color: "#80868B",
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
return !!selectedTimeZone ? (
|
|
|
|
<TimezoneSelect
|
|
|
|
id="timeZone"
|
|
|
|
value={selectedTimeZone}
|
|
|
|
onChange={(tz: ITimezoneOption) => setSelectedTimeZone(tz.value)}
|
|
|
|
className="flex h-6 text-sm font-medium"
|
|
|
|
styles={customStyles}
|
|
|
|
/>
|
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;
|