import { AlertBlock } from "@/components/shared/alert-block"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Form, FormControl, FormDescription, 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 { Switch } from "@/components/ui/switch"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; import { PlusIcon } from "lucide-react"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; // const hostnameRegex = /^[a-zA-Z0-9][a-zA-Z0-9\.-]*\.[a-zA-Z]{2,}$/; // .regex(hostnameRegex const addDomain = z.object({ host: z.string().min(1, "Hostname is required"), path: z.string().min(1), port: z.number(), https: z.boolean(), certificateType: z.enum(["letsencrypt", "none"]), }); type AddDomain = z.infer; interface Props { applicationId: string; children?: React.ReactNode; } export const AddDomain = ({ applicationId, children = , }: Props) => { const utils = api.useUtils(); const { mutateAsync, isError, error } = api.domain.create.useMutation(); const form = useForm({ defaultValues: { host: "", https: false, path: "/", port: 3000, certificateType: "none", }, resolver: zodResolver(addDomain), }); useEffect(() => { form.reset(); }, [form, form.reset, form.formState.isSubmitSuccessful]); const onSubmit = async (data: AddDomain) => { await mutateAsync({ applicationId, host: data.host, https: data.https, path: data.path, port: data.port, certificateType: data.certificateType, }) .then(async () => { toast.success("Domain Created"); await utils.domain.byApplicationId.invalidate({ applicationId, }); await utils.application.readTraefikConfig.invalidate({ applicationId }); }) .catch(() => { toast.error("Error to create the domain"); }); }; return ( Domain In this section you can add custom domains {isError && {error?.message}}
( Host )} /> { return ( Path ); }} /> { return ( Container Port { field.onChange(Number.parseInt(e.target.value)); }} /> ); }} /> ( Certificate )} /> (
HTTPS Automatically provision SSL Certificate.
)} />
); };