import { useRouter } from "next/navigation"; import Shell from "@calcom/features/shell/Shell"; import { ErrorCode } from "@calcom/lib/errorCodes"; import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams"; import { PERMISSIONS_GROUPED_MAP } from "@calcom/platform-constants/permissions"; import { showToast } from "@calcom/ui"; import { useCreateOAuthClient } from "@lib/hooks/settings/platform/oauth-clients/usePersistOAuthClient"; import PageWrapper from "@components/PageWrapper"; import NoPlatformPlan from "@components/settings/platform/dashboard/NoPlatformPlan"; import { useGetUserAttributes } from "@components/settings/platform/hooks/useGetUserAttributes"; import type { FormValues } from "@components/settings/platform/oauth-clients/oauth-client-form"; import { OAuthClientForm } from "@components/settings/platform/oauth-clients/oauth-client-form"; export default function CreateOAuthClient() { const searchParams = useCompatSearchParams(); const router = useRouter(); const clientId = searchParams?.get("clientId") || ""; const { isUserLoading, isPlatformUser, isPaidUser } = useGetUserAttributes(); const { mutateAsync: save, isPending: isSaving } = useCreateOAuthClient({ onSuccess: () => { showToast("OAuth client created successfully", "success"); router.push("/settings/platform/"); }, onError: () => { showToast(ErrorCode.CreatingOauthClientError, "error"); }, }); const onSubmit = (data: FormValues) => { let userPermissions = 0; const userRedirectUris = data.redirectUris.map((uri) => uri.uri).filter((uri) => !!uri); Object.keys(PERMISSIONS_GROUPED_MAP).forEach((key) => { const entity = key as keyof typeof PERMISSIONS_GROUPED_MAP; const entityKey = PERMISSIONS_GROUPED_MAP[entity].key; const read = PERMISSIONS_GROUPED_MAP[entity].read; const write = PERMISSIONS_GROUPED_MAP[entity].write; if (data[`${entityKey}Read`]) userPermissions |= read; if (data[`${entityKey}Write`]) userPermissions |= write; }); save({ name: data.name, permissions: userPermissions, // logo: data.logo, redirectUris: userRedirectUris, bookingRedirectUri: data.bookingRedirectUri, bookingCancelRedirectUri: data.bookingCancelRedirectUri, bookingRescheduleRedirectUri: data.bookingRescheduleRedirectUri, areEmailsEnabled: data.areEmailsEnabled, }); }; if (isUserLoading) return
Loading...
; if (isPlatformUser && isPaidUser) { return (

OAuth client creation form

This is the form to create a new OAuth client

); } return (
}>
); } CreateOAuthClient.PageWrapper = PageWrapper;