feat: api endpoints for calendar settings atom (#15761)
* 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 <[email protected]> Co-authored-by: Morgan Vernay <[email protected]>
This commit is contained in:
17 files changed
+681
-2
No files matched your search
@@ -0,0 +1,54 @@
|
||||
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;
|
||||
};
|
||||
@@ -0,0 +1,62 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
|
||||
import type { CALENDARS } from "@calcom/platform-constants";
|
||||
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { ApiErrorResponse, ApiResponse } from "@calcom/platform-types";
|
||||
|
||||
import http from "../../lib/http";
|
||||
|
||||
interface IUseDeleteCalendarCredentials {
|
||||
onSuccess?: (res: ApiResponse) => void;
|
||||
onError?: (err: ApiErrorResponse | Error) => void;
|
||||
}
|
||||
|
||||
export const useDeleteCalendarCredentials = (
|
||||
{ onSuccess, onError }: IUseDeleteCalendarCredentials = {
|
||||
onSuccess: () => {
|
||||
return;
|
||||
},
|
||||
onError: () => {
|
||||
return;
|
||||
},
|
||||
}
|
||||
) => {
|
||||
const deleteCalendarCredentials = useMutation<
|
||||
ApiResponse<{
|
||||
status: string;
|
||||
data: {
|
||||
id: number;
|
||||
type: string;
|
||||
userId: number | null;
|
||||
teamId: number | null;
|
||||
appId: string | null;
|
||||
invalid: boolean | null;
|
||||
};
|
||||
}>,
|
||||
unknown,
|
||||
{ id: number; calendar: (typeof CALENDARS)[number] }
|
||||
>({
|
||||
mutationFn: (data) => {
|
||||
const { id, calendar } = data;
|
||||
const body = {
|
||||
id,
|
||||
};
|
||||
|
||||
return http.post(`/calendars/${calendar}/disconnect`, body).then((res) => {
|
||||
return res.data;
|
||||
});
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
if (data.status === SUCCESS_STATUS) {
|
||||
onSuccess?.(data);
|
||||
} else {
|
||||
onError?.(data);
|
||||
}
|
||||
},
|
||||
onError: (err) => {
|
||||
onError?.(err as ApiErrorResponse);
|
||||
},
|
||||
});
|
||||
|
||||
return deleteCalendarCredentials;
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
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 IUseRemoveSelectedCalendar {
|
||||
onSuccess?: (res: ApiResponse) => void;
|
||||
onError?: (err: ApiErrorResponse | Error) => void;
|
||||
}
|
||||
|
||||
export const useRemoveSelectedCalendar = (
|
||||
{ onSuccess, onError }: IUseRemoveSelectedCalendar = {
|
||||
onSuccess: () => {
|
||||
return;
|
||||
},
|
||||
onError: () => {
|
||||
return;
|
||||
},
|
||||
}
|
||||
) => {
|
||||
const deletedCalendarEntry = useMutation<
|
||||
ApiResponse<{
|
||||
status: string;
|
||||
data: {
|
||||
userId: number;
|
||||
integration: string;
|
||||
externalId: string;
|
||||
credentialId: number | null;
|
||||
};
|
||||
}>,
|
||||
unknown,
|
||||
{ credentialId: number; integration: string; externalId: string }
|
||||
>({
|
||||
mutationFn: (data) => {
|
||||
const { credentialId, externalId, integration } = data;
|
||||
|
||||
return http
|
||||
.delete(
|
||||
`/selected-calendars?credentialId=${credentialId}&integration=${integration}&externalId=${externalId}`
|
||||
)
|
||||
.then((res) => {
|
||||
return res.data;
|
||||
});
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
if (data.status === SUCCESS_STATUS) {
|
||||
onSuccess?.(data);
|
||||
} else {
|
||||
onError?.(data);
|
||||
}
|
||||
},
|
||||
onError: (err) => {
|
||||
onError?.(err as ApiErrorResponse);
|
||||
},
|
||||
});
|
||||
|
||||
return deletedCalendarEntry;
|
||||
};
|
||||
@@ -15,3 +15,6 @@ export { useMe } from "./hooks/useMe";
|
||||
export { OutlookConnect } from "./connect/outlook/OutlookConnect";
|
||||
export * as Connect from "./connect";
|
||||
export { BookerEmbed } from "./booker-embed";
|
||||
export { useDeleteCalendarCredentials } from "./hooks/calendars/useDeleteCalendarCredentials";
|
||||
export { useAddSelectedCalendar } from "./hooks/calendars/useAddSelectedCalendar";
|
||||
export { useRemoveSelectedCalendar } from "./hooks/calendars/useRemoveSelectedCalendar";
|
||||
Reference in new issue
Block a user