"use client"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Avatar } from "@calcom/ui/components/avatar"; import { Button } from "@calcom/ui/components/button"; import { Form } from "@calcom/ui/components/form"; import { Label } from "@calcom/ui/components/form"; import { Switch } from "@calcom/ui/components/form"; import { TextField } from "@calcom/ui/components/form"; import { Icon } from "@calcom/ui/components/icon"; import { ImageUploader } from "@calcom/ui/components/image-uploader"; import { showToast } from "@calcom/ui/components/toast"; import { Tooltip } from "@calcom/ui/components/tooltip"; type FormValues = { name: string; redirectUri: string; logo: string; enablePkce: boolean; }; export default function OAuthView() { const oAuthForm = useForm({ defaultValues: { logo: "", enablePkce: false, }, }); const [clientSecret, setClientSecret] = useState(""); const [clientId, setClientId] = useState(""); const [logo, setLogo] = useState(""); const { t } = useLocale(); const mutation = trpc.viewer.oAuth.addClient.useMutation({ onSuccess: async (data) => { setClientSecret(data.clientSecret || ""); setClientId(data.clientId); showToast(`Successfully added ${data.name} as new client`, "success"); }, onError: (error) => { showToast(`Adding client failed: ${error.message}`, "error"); }, }); return (
{!clientId ? (
{ mutation.mutate({ name: values.name, redirectUri: values.redirectUri, logo: values.logo, enablePkce: values.enablePkce, }); }}>
oAuthForm.setValue("enablePkce", checked)} /> Use PKCE (recommended for mobile/SPA applications)
} className="mr-5 items-center" imageSrc={logo} size="lg" /> { setLogo(newLogo); oAuthForm.setValue("logo", newLogo); }} imageSrc={logo} />
) : (
{oAuthForm.getValues("name")}
{t("client_id")}
{clientId}
{clientSecret ? ( <>
{t("client_secret")}
{clientSecret}
{t("copy_client_secret_info")}
) : (
This client uses PKCE authentication (no client secret required).
)}
)}
); }