"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 { Meta, Form, Button, Icon, TextField, showToast, Tooltip, ImageUploader, Avatar } from "@calcom/ui"; 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")}
Client Id
{" "} {clientId}
{clientSecret ? ( <>
Client Secret
{" "} {clientSecret}
{t("copy_client_secret_info")}
) : ( <> )}
)}
); }