import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; const addServerDomain = z.object({ domain: z.string().min(1, { message: "URL is required" }), letsEncryptEmail: z.string().min(1, "Email is required").email(), certificateType: z.enum(["letsencrypt", "none"]), }); type AddServerDomain = z.infer; export const WebDomain = () => { const { data: user, refetch } = api.admin.one.useQuery(); const { mutateAsync, isLoading } = api.settings.assignDomainServer.useMutation(); const form = useForm({ defaultValues: { domain: "", certificateType: "none", letsEncryptEmail: "", }, resolver: zodResolver(addServerDomain), }); useEffect(() => { if (user) { form.reset({ domain: user?.host || "", certificateType: user?.certificateType, letsEncryptEmail: user?.letsEncryptEmail || "", }); } }, [form, form.reset, user]); const onSubmit = async (data: AddServerDomain) => { await mutateAsync({ host: data.domain, letsEncryptEmail: data.letsEncryptEmail, certificateType: data.certificateType, }) .then(async () => { await refetch(); toast.success("Domain Assigned"); }) .catch(() => { toast.error("Error to assign the domain"); }); }; return (
Server Domain Add your server domain to your application
{ return ( Domain ); }} /> { return ( Letsencrypt Email ); }} /> { return ( Certificate ); }} />
); };