fix:CityNotShownInOption (#17064)

Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
Shrey TannaandAlex van Andel authored and GitHub committed 2024-10-24 09:10:27 -04:00
1 parent 0949bbf167
commit 14ae664941
10 files changed
+104 -219

No files matched your search

@@ -6,22 +6,40 @@ import BaseSelect from "react-timezone-select";
import { classNames } from "@calcom/lib";
import { CALCOM_VERSION } from "@calcom/lib/constants";
import { filterByCities, addCitiesToDropdown, handleOptionLabel } from "@calcom/lib/timezone";
import { filterBySearchText, addTimezonesToDropdown, handleOptionLabel } from "@calcom/lib/timezone";
import type { Timezones } from "@calcom/lib/timezone";
import { trpc } from "@calcom/trpc/react";
import { getReactSelectProps } from "../select";
export interface ICity {
city: string;
timezone: string;
}
const SELECT_SEARCH_DATA: Timezones = [
{ label: "San Francisco", timezone: "America/Los_Angeles" },
{ label: "Sao Francisco do Sul", timezone: "America/Sao_Paulo" },
{ label: "San Francisco de Macoris", timezone: "America/Santo_Domingo" },
{ label: "San Francisco Gotera", timezone: "America/El_Salvador" },
{ label: "Eastern Time - US & Canada", timezone: "America/New_York" },
{ label: "Pacific Time - US & Canada", timezone: "America/Los_Angeles" },
{ label: "Central Time - US & Canada", timezone: "America/Chicago" },
{ label: "Mountain Time - US & Canada", timezone: "America/Denver" },
{ label: "Atlantic Time - Canada", timezone: "America/Halifax" },
{ label: "Eastern European Time", timezone: "Europe/Bucharest" },
{ label: "Central European Time", timezone: "Europe/Berlin" },
{ label: "Western European Time", timezone: "Europe/London" },
{ label: "Australian Eastern Time", timezone: "Australia/Sydney" },
{ label: "Japan Standard Time", timezone: "Asia/Tokyo" },
{ label: "India Standard Time", timezone: "Asia/Kolkata" },
{ label: "Gulf Standard Time", timezone: "Asia/Dubai" },
{ label: "South Africa Standard Time", timezone: "Africa/Johannesburg" },
{ label: "Brazil Time", timezone: "America/Sao_Paulo" },
{ label: "Hawaii-Aleutian Standard Time", timezone: "Pacific/Honolulu" },
];
export type TimezoneSelectProps = SelectProps & {
variant?: "default" | "minimal";
timezoneSelectCustomClassname?: string;
};
export function TimezoneSelect(props: TimezoneSelectProps) {
const { data, isPending } = trpc.viewer.timezones.cityTimezones.useQuery(
const { data = [], isPending } = trpc.viewer.timezones.cityTimezones.useQuery(
{
CalComVersion: CALCOM_VERSION,
},
@@ -29,14 +47,19 @@ export function TimezoneSelect(props: TimezoneSelectProps) {
trpc: { context: { skipBatch: true } },
}
);
return <TimezoneSelectComponent data={data} isPending={isPending} {...props} />;
return (
<TimezoneSelectComponent
data={data.map(({ city, timezone }) => ({ label: city, timezone }))}
isPending={isPending}
{...props}
/>
);
}
export type TimezoneSelectComponentProps = SelectProps & {
variant?: "default" | "minimal";
isPending: boolean;
data: ICity[] | undefined;
data?: Timezones;
timezoneSelectCustomClassname?: string;
};
export function TimezoneSelectComponent({
@@ -45,14 +68,21 @@ export function TimezoneSelectComponent({
timezoneSelectCustomClassname,
components,
variant = "default",
data,
isPending,
value,
...props
}: TimezoneSelectComponentProps) {
const [cities, setCities] = useState<ICity[]>([]);
const handleInputChange = (tz: string) => {
if (data) setCities(filterByCities(tz, data));
const data = [...(props.data || []), ...SELECT_SEARCH_DATA];
/*
* we support multiple timezones for the different labels
* e.g. 'Sao Paulo' and 'Brazil Time' both being 'America/Sao_Paulo'
* but react-timezone-select does not.
*
* We make sure to be able to search through both options, and flip the key/value on final display.
*/
const [additionalTimezones, setAdditionalTimezones] = useState<Timezones>([]);
const handleInputChange = (searchText: string) => {
if (data) setAdditionalTimezones(filterBySearchText(searchText, data));
};
const reactSelectProps = useMemo(() => {
@@ -70,15 +100,15 @@ export function TimezoneSelectComponent({
isDisabled={isPending}
{...reactSelectProps}
timezones={{
...(data ? addCitiesToDropdown(data) : {}),
...addCitiesToDropdown(cities),
...(props.data ? addTimezonesToDropdown(data) : {}),
...addTimezonesToDropdown(additionalTimezones),
}}
onInputChange={handleInputChange}
{...props}
formatOptionLabel={(option) => (
<p className="truncate">{(option as ITimezoneOption).value.replace(/_/g, " ")}</p>
)}
getOptionLabel={(option) => handleOptionLabel(option as ITimezoneOption, cities)}
getOptionLabel={(option) => handleOptionLabel(option as ITimezoneOption, additionalTimezones)}
classNames={{
...timezoneClassNames,
input: (state) =>
@@ -2,7 +2,6 @@ export { TimezoneSelect, TimezoneSelectComponent } from "./TimezoneSelect";
export type {
ITimezone,
ITimezoneOption,
ICity,
TimezoneSelectProps,
TimezoneSelectComponentProps,
} from "./TimezoneSelect";
+5
View File
@@ -6,6 +6,11 @@
"main": "./index.tsx",
"exports": {
".": "./index.tsx",
"./button": "./components/button/index.ts",
"./form/timezone-select": "./components/form/timezone-select/index.ts",
"./toast": "./components/toast/index.tsx",
"./icon": "./components/icon/index.ts",
"./unpublished-entity/UnpublishedEntity": "./components/unpublished-entity/index.ts",
"./components/toast": "./components/toast/index.tsx",
"./components/icon": "./components/icon/index.ts",
"./components/icon/SatSymbol": "./components/icon/SatSymbol.tsx",