mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* move delegation credential repository to features * mv credential repository to features * update imports * mv * fix * fix * fix * fix * fix * update imports * update imports * update eslint rule * fix * fix * mv getConnectedDestinationCalendars * fix import errors * mv getCalendarsEvents * remove getUsersCredentials * wip * revert eslint rule change for now * fix type checks * fix * format * cleanup * fix * fix * fix * fix * fix tests * migrate getUserAvailability * migrate * fix tests * fix type checks * fix * fix * migrate crmManager * update imports * migrate raqbUtils to appstore * migrate getLuckyUser to features * migrate findTeamMembersMatchingAttributeLogic to appstore * update imports * fix * fix * fix test * fix unit tests * fix * fix * add eslint config
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import type { ConnectedDestinationCalendars } from "@calcom/features/calendars/lib/getConnectedDestinationCalendars";
|
|
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
|
import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
|
|
|
|
import http from "../lib/http";
|
|
import { useAtomsContext } from "./useAtomsContext";
|
|
|
|
export const QUERY_KEY = "get-connected-calendars";
|
|
export const useConnectedCalendars = (props: { enabled?: boolean }) => {
|
|
const { isInit } = useAtomsContext();
|
|
|
|
const calendars = useQuery({
|
|
queryKey: [QUERY_KEY],
|
|
queryFn: () => {
|
|
return http.get<ApiResponse<ConnectedDestinationCalendars>>("/calendars").then((res) => {
|
|
if (res.data.status === SUCCESS_STATUS) {
|
|
return (res.data as ApiSuccessResponse<ConnectedDestinationCalendars>)?.data;
|
|
}
|
|
throw new Error(res.data.error.message);
|
|
});
|
|
},
|
|
enabled: props?.enabled !== undefined ? props.enabled && isInit : isInit,
|
|
staleTime: 5000,
|
|
});
|
|
|
|
return calendars;
|
|
};
|