"use client"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc"; import { Avatar } from "@calcom/ui/components/avatar"; import { Button } from "@calcom/ui/components/button"; import { Form } 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; }; export default function OAuthView() { const oAuthForm = useForm(); 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 clientfailed: ${error.message}`, "error"); }, }); return (
{!clientId ? (
{ mutation.mutate({ name: values.name, redirectUri: values.redirectUri, logo: values.logo, }); }}>
} 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")}
) : ( <> )}
)}
); }