* add endpoint to fetch managed user from client id * update typings * minor tweaks * custom hook to fetch managed users from client id * add translations for platform onboarding * add isPlatformOrg boolean to figure out which is platform and which is not * set isPlatform hook based on data obtained from org * add limitWidth prop to control component width * add props to shell to make sidebar display different tabs based on if the shell isPlattform or not * platform related pages * fix merge conflicts * fix merge conflicts * platform oauth client form and card * remove everything related to platform from organization * update oauth client card and form * fixup * fix imports and remove logs * fixup * update redirect url * split oauth client form into separate update and create forms * separate forms for create and edit oauth clients * fixup * fixup * dynamic routes for oauth client edit page * fixup fixup * fix to not show error when redirect uri is empty * refactor create handler for org * cleaup comments * add custom hook to check user billing * export managed user type * refactor platform index page * refactor edit and create pages * dashboard component containing oauth client list and managed user * common oauth client form used for create and edit form * platform pricing helper * platform pricing component * fix typing and data response for billing * use custom hook to check team billing info * fix type checks * upgrade conditional rendering for upgrade to org banner * add isLoading prop to check button loading state * pass in button handler * add custom hook to subscribe to stripe and typings * update typings * fix incorrect endpoint * pass in team id as prop * fix type check * update stripe success and cancel redirect url * add and pass redirect url param to custom hook * custom hooks for platform * cleanup * update imports * fix merge conflicts * fixup * fixup fixup * fixup * merge conflicts fixup * merge conlficts battle :( * minor fixes * skip admin checks for a platform client * fix typo * append slug with _platform for a platform user * PR feedback * dashboard refactor * bring back org form to its orginal state * add platform folder to ee * update typings * use new create platform form * fixup * fix typo and update plans * simplifying rendering * remove managed users endpoint since it already exists * url for endpoint * rename tabs * pr feedback * managed users endpoint * update endpoint * remove form --------- Co-authored-by: Morgan <[email protected]> Co-authored-by: exception <[email protected]> Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: Keith Williams <[email protected]> Co-authored-by: Peer Richelsen <[email protected]>
177 lines
4.0 KiB
TypeScript
177 lines
4.0 KiB
TypeScript
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
|
|
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
|
import type {
|
|
ApiResponse,
|
|
CreateOAuthClientInput,
|
|
DeleteOAuthClientInput,
|
|
SubscribeTeamInput,
|
|
} from "@calcom/platform-types";
|
|
import type { OAuthClient } from "@calcom/prisma/client";
|
|
|
|
interface IPersistOAuthClient {
|
|
onSuccess?: () => void;
|
|
onError?: () => void;
|
|
}
|
|
|
|
export const useCreateOAuthClient = (
|
|
{ onSuccess, onError }: IPersistOAuthClient = {
|
|
onSuccess: () => {
|
|
return;
|
|
},
|
|
onError: () => {
|
|
return;
|
|
},
|
|
}
|
|
) => {
|
|
return useMutation<
|
|
ApiResponse<{ clientId: string; clientSecret: string }>,
|
|
unknown,
|
|
CreateOAuthClientInput
|
|
>({
|
|
mutationFn: (data) => {
|
|
return fetch("/api/v2/oauth-clients", {
|
|
method: "post",
|
|
headers: { "Content-type": "application/json" },
|
|
body: JSON.stringify(data),
|
|
}).then((res) => res.json());
|
|
},
|
|
onSuccess: (data) => {
|
|
if (data.status === SUCCESS_STATUS) {
|
|
onSuccess?.();
|
|
} else {
|
|
onError?.();
|
|
}
|
|
},
|
|
onError: () => {
|
|
onError?.();
|
|
},
|
|
});
|
|
};
|
|
|
|
export const useUpdateOAuthClient = (
|
|
{ onSuccess, onError, clientId }: IPersistOAuthClient & { clientId?: string } = {
|
|
onSuccess: () => {
|
|
return;
|
|
},
|
|
onError: () => {
|
|
return;
|
|
},
|
|
}
|
|
) => {
|
|
const mutation = useMutation<
|
|
ApiResponse<{ clientId: string; clientSecret: string }>,
|
|
unknown,
|
|
Omit<CreateOAuthClientInput, "permissions">
|
|
>({
|
|
mutationFn: (data) => {
|
|
return fetch(`/api/v2/oauth-clients/${clientId}`, {
|
|
method: "PATCH",
|
|
headers: { "Content-type": "application/json" },
|
|
body: JSON.stringify(data),
|
|
}).then((res) => res?.json());
|
|
},
|
|
onSuccess: (data) => {
|
|
if (data.status === SUCCESS_STATUS) {
|
|
onSuccess?.();
|
|
} else {
|
|
onError?.();
|
|
}
|
|
},
|
|
onError: () => {
|
|
onError?.();
|
|
},
|
|
});
|
|
|
|
return mutation;
|
|
};
|
|
|
|
export const useDeleteOAuthClient = (
|
|
{ onSuccess, onError }: IPersistOAuthClient = {
|
|
onSuccess: () => {
|
|
return;
|
|
},
|
|
onError: () => {
|
|
return;
|
|
},
|
|
}
|
|
) => {
|
|
const mutation = useMutation<ApiResponse<OAuthClient>, unknown, DeleteOAuthClientInput>({
|
|
mutationFn: (data) => {
|
|
const { id } = data;
|
|
return fetch(`/api/v2/oauth-clients/${id}`, {
|
|
method: "delete",
|
|
headers: { "Content-type": "application/json" },
|
|
}).then((res) => res?.json());
|
|
},
|
|
onSuccess: (data) => {
|
|
if (data.status === SUCCESS_STATUS) {
|
|
onSuccess?.();
|
|
} else {
|
|
onError?.();
|
|
}
|
|
},
|
|
onError: () => {
|
|
onError?.();
|
|
},
|
|
});
|
|
|
|
return mutation;
|
|
};
|
|
|
|
export const useCheckTeamBilling = (teamId?: number | null) => {
|
|
const QUERY_KEY = "check-team-billing";
|
|
const isTeamBilledAlready = useQuery({
|
|
queryKey: [QUERY_KEY, teamId],
|
|
queryFn: async () => {
|
|
const response = await fetch(`/api/v2/billing/${teamId}/check`, {
|
|
method: "get",
|
|
headers: { "Content-type": "application/json" },
|
|
});
|
|
const data = await response.json();
|
|
|
|
return data.data;
|
|
},
|
|
enabled: !!teamId,
|
|
});
|
|
|
|
return isTeamBilledAlready;
|
|
};
|
|
|
|
export const useSubscribeTeamToStripe = (
|
|
{
|
|
onSuccess,
|
|
onError,
|
|
teamId,
|
|
}: { teamId?: number | null; onSuccess: (redirectUrl: string) => void; onError: () => void } = {
|
|
onSuccess: () => {
|
|
return;
|
|
},
|
|
onError: () => {
|
|
return;
|
|
},
|
|
}
|
|
) => {
|
|
const mutation = useMutation<ApiResponse<{ action: string; url: string }>, unknown, SubscribeTeamInput>({
|
|
mutationFn: (data) => {
|
|
return fetch(`/api/v2/billing/${teamId}/subscribe`, {
|
|
method: "post",
|
|
headers: { "Content-type": "application/json" },
|
|
body: JSON.stringify(data),
|
|
}).then((res) => res?.json());
|
|
},
|
|
onSuccess: (data) => {
|
|
if (data.status === SUCCESS_STATUS) {
|
|
onSuccess?.(data.data?.url);
|
|
} else {
|
|
onError?.();
|
|
}
|
|
},
|
|
onError: () => {
|
|
onError?.();
|
|
},
|
|
});
|
|
|
|
return mutation;
|
|
};
|