Skip to content

Commit

Permalink
fix: platform booker timezone select (#18277)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThyMinimalDev authored Dec 19, 2024
1 parent 42d78f8 commit d1c2872
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
13 changes: 11 additions & 2 deletions packages/platform/atoms/hooks/useGetCityTimezones.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { useQuery } from "@tanstack/react-query";

import { SUCCESS_STATUS } from "@calcom/platform-constants";
import type { ApiResponse } from "@calcom/platform-types";

import http from "../lib/http";

type Timezones = { city: string; timezone: string }[];
const useGetCityTimezones = () => {
const pathname = `/timezones`;

const { isLoading, data } = useQuery({
const { isLoading, data } = useQuery<ApiResponse<Timezones>>({
queryKey: ["city-timezones"],
queryFn: () => {
return http?.get(pathname).then((res) => res.data);
return http?.get<ApiResponse<Timezones>>(pathname).then((res) => {
if (res.data.status === SUCCESS_STATUS) {
return res.data;
}
throw new Error(res.data.error.message);
});
},
});

Expand Down
15 changes: 14 additions & 1 deletion packages/platform/atoms/timezone/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,18 @@ import useGetCityTimezones from "../hooks/useGetCityTimezones";
export function Timezone(props: TimezoneSelectProps) {
const { isLoading, data } = useGetCityTimezones();

return <TimezoneSelectComponent {...props} data={data?.data} isPending={isLoading} />;
return (
<TimezoneSelectComponent
{...props}
data={
Array.isArray(data)
? data.map(({ city, timezone }) => ({
label: city,
timezone,
}))
: []
}
isPending={isLoading}
/>
);
}

0 comments on commit d1c2872

Please sign in to comment.