* refactor: group endpoints by tags * refactor: remove swagger header * feat: managed users docs * feat: gcal docs * feat: provider docs * feat: managed users docs * fix: event-types locations docs * refactor: schedules remove forAtom logic - return just for atoms * feat: schedules docs * feat: schedules docs * fix: me tests * fix: schedules tests * feat: me docs * feat: calendar busy times docs * feat: calendar connected and destination calendars docs * feat: some docs for bookings endpoints * fix: add OAuth id when updating user email + disallow updating username * fix: creating user with same e-mail results in 500 * fix: me e2e tests * fix: event-types e2e tests * fix: oauth-client-users e2e tests * fix: some bookings e2e * revert: re-add name for create update user * fix: schedule create isDefault required * lock file from main * lock file from main * comment broken bookings tests * fix: connected calendars output type * fix: connected calendars output type
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
|
|
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
|
import { V2_ENDPOINTS } from "@calcom/platform-constants";
|
|
import type { UpdateScheduleOutputType } from "@calcom/platform-libraries";
|
|
import type { ApiResponse, UpdateScheduleInput, ApiErrorResponse } from "@calcom/platform-types";
|
|
|
|
import http from "../lib/http";
|
|
import { QUERY_KEY as ScheduleQueryKey } from "./useClientSchedule";
|
|
|
|
interface IPUpdateOAuthClient {
|
|
onSuccess?: (res: ApiResponse<UpdateScheduleOutputType>) => void;
|
|
onError?: (err: ApiErrorResponse) => void;
|
|
}
|
|
|
|
const useUpdateSchedule = (
|
|
{ onSuccess, onError }: IPUpdateOAuthClient = {
|
|
onSuccess: () => {
|
|
return;
|
|
},
|
|
onError: () => {
|
|
return;
|
|
},
|
|
}
|
|
) => {
|
|
const queryClient = useQueryClient();
|
|
|
|
const mutation = useMutation<
|
|
ApiResponse<UpdateScheduleOutputType>,
|
|
unknown,
|
|
UpdateScheduleInput & { scheduleId: number }
|
|
>({
|
|
mutationFn: (data) => {
|
|
const pathname = `/${V2_ENDPOINTS.availability}/${data.scheduleId}?for=atom`;
|
|
|
|
return http.patch<ApiResponse<UpdateScheduleOutputType>>(pathname, data).then((res) => {
|
|
return res.data;
|
|
});
|
|
},
|
|
onSuccess: (data) => {
|
|
if (data.status === SUCCESS_STATUS) {
|
|
onSuccess?.(data);
|
|
queryClient.invalidateQueries({ queryKey: [ScheduleQueryKey] });
|
|
} else {
|
|
onError?.(data);
|
|
}
|
|
},
|
|
onError: (err) => {
|
|
onError?.(err as ApiErrorResponse);
|
|
},
|
|
});
|
|
|
|
return mutation;
|
|
};
|
|
|
|
export default useUpdateSchedule;
|