* calendars repository * add disconnect endpoint * update platform libraries to include getCalendar fn * cleanup * fix typings * update calendars service to include delete credentials handler * update typings * add missing return * refactor delete calendar credentials handler * update disconnect endpoint * fix typing * fixup * add handlers to insert and remove selected calendar * init selected calendars controller * fix naming * output response dto for deleting calendar credentials * fix typing * fix merge conflicts * resolve merge conflicts * fixup * cleanup * capitalize controller name * include selected calendars controller in selected calendars module * fix type error * cleanup * fixup * add calendars repository * custom hook for calendar credentials * fix typing * cleanup * take input from query params instead of body in delete request * custom hook to add selected calendar * custom hook to remove selected calendar * better naming * fix typo * fixup * update input for delete calendar query params * address PR feedback * add method to check calendar credentials * abstract logic to check calendar credentials in calendars service * resolve module errors * export custom hooks for calendar settings * e2e for deleting calendar credentials endpoint * fix typo * set authorization header to calendars post * e2e tests for selected calendars controller * fix output typing * better error messages * restructuring * fix imports * remove unused not found exception * fixup! remove unused not found exception --------- Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Co-authored-by: Morgan Vernay <morgan@cal.com>
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { useMutation } from "@tanstack/react-query";
|
|
|
|
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
|
import type { ApiErrorResponse, ApiResponse } from "@calcom/platform-types";
|
|
|
|
import http from "../../lib/http";
|
|
|
|
interface IUseAddSelectedCalendar {
|
|
onSuccess?: (res: ApiResponse) => void;
|
|
onError?: (err: ApiErrorResponse | Error) => void;
|
|
}
|
|
|
|
export const useAddSelectedCalendar = (
|
|
{ onSuccess, onError }: IUseAddSelectedCalendar = {
|
|
onSuccess: () => {
|
|
return;
|
|
},
|
|
onError: () => {
|
|
return;
|
|
},
|
|
}
|
|
) => {
|
|
const newlyAddedCalendarEntry = useMutation<
|
|
ApiResponse<{
|
|
status: string;
|
|
data: {
|
|
userId: number;
|
|
integration: string;
|
|
externalId: string;
|
|
credentialId: number | null;
|
|
};
|
|
}>,
|
|
unknown,
|
|
{ credentialId: number; integration: string; externalId: string }
|
|
>({
|
|
mutationFn: (data) => {
|
|
return http.post(`/selected-calendars`, data).then((res) => {
|
|
return res.data;
|
|
});
|
|
},
|
|
onSuccess: (data) => {
|
|
if (data.status === SUCCESS_STATUS) {
|
|
onSuccess?.(data);
|
|
} else {
|
|
onError?.(data);
|
|
}
|
|
},
|
|
onError: (err) => {
|
|
onError?.(err as ApiErrorResponse);
|
|
},
|
|
});
|
|
|
|
return newlyAddedCalendarEntry;
|
|
};
|