fix: platform booker timezone select (#18277)
This commit is contained in:
@@ -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);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user