mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* feat: add api v2 endpoint to fetch all user schedules * chore: update typing * feat: custom hook to fetch all user schedules * refactor: shift logic to transform schedules into function of its own * init: list schedules atom * feat: api endpoints for list schedules atom * refactor: accept redirect url as prop * fix: pass redirect url prop * integrate list schedules atom with availability settings * refactor: extract types to be reused in api v2 endpoints * skip availability settings page for the time being until we have api v2 endpoints in prod * feat: add docs for list schedules atom * fixup * export Schedule type * make sure we always have a default schedule if user deletes his default schedule * chore: implement code rabbit feedback * chore: implement PR feedback * fix: resolve merge conflicts * fix: import path * update platform libraries * fix: type check * resolve merge conflicts * update atoms export * update platform libraries schedule * chore: arrange atoms in alphabetical order * update atoms controller to include endpoints for list schedules atom * add create atom scheule atom * fix: invalidate schedules on new schedule creation * chore: add changesets
31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
|
import type { ApiResponse } from "@calcom/platform-types";
|
|
import type { GetAvailabilityListHandlerReturn } from "@calcom/trpc/server/routers/viewer/availability/list.handler";
|
|
|
|
import http from "../../lib/http";
|
|
import { useAtomsContext } from "../useAtomsContext";
|
|
|
|
export const QUERY_KEY = "use-atom-user-schedules";
|
|
|
|
export const useAtomGetAllSchedules = () => {
|
|
const pathname = "atoms/schedules/all";
|
|
const { isInit, accessToken } = useAtomsContext();
|
|
|
|
const { isLoading, error, data, refetch } = useQuery({
|
|
queryKey: [QUERY_KEY],
|
|
queryFn: () => {
|
|
return http.get<ApiResponse<GetAvailabilityListHandlerReturn>>(pathname).then((res) => {
|
|
if (res.data.status === SUCCESS_STATUS) {
|
|
return res.data.data;
|
|
}
|
|
throw new Error(res.data.error?.message);
|
|
});
|
|
},
|
|
enabled: isInit && !!accessToken,
|
|
});
|
|
|
|
return { isLoading, error, data, refetch };
|
|
};
|