diff --git a/src/app/(dashboard)/project/[projectId]/service/[serviceId]/domains/DomainsList.tsx b/src/app/(dashboard)/project/[projectId]/service/[serviceId]/domains/DomainsList.tsx index d29cba4..48050eb 100644 --- a/src/app/(dashboard)/project/[projectId]/service/[serviceId]/domains/DomainsList.tsx +++ b/src/app/(dashboard)/project/[projectId]/service/[serviceId]/domains/DomainsList.tsx @@ -1,9 +1,30 @@ "use client"; +import { ArrowRight, PlusIcon } from "lucide-react"; import { useFieldArray } from "react-hook-form"; import { z } from "zod"; -import { Form } from "~/components/ui/form"; -import { FormSubmit, SimpleFormField, useForm } from "~/hooks/forms"; +import { Button } from "~/components/ui/button"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "~/components/ui/form"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "~/components/ui/select"; +import { + FormSubmit, + FormUnsavedChangesIndicator, + SimpleFormField, + useForm, +} from "~/hooks/forms"; const formValidator = z.object({ domains: z.array( @@ -15,9 +36,9 @@ const formValidator = z.object({ { message: "Invalid domain name" }, ), - internalPort: z.number().int().min(1).max(65535), - https: z.boolean(), - forceSSL: z.boolean(), + internalPort: z.coerce.number().int().min(1).max(65535).default(8080), + https: z.boolean().default(true), + forceSSL: z.boolean().default(true), }), ), }); @@ -30,14 +51,14 @@ export default function DomainsList( }, ) { const form = useForm(formValidator, { - defaultValues: {}, - }); - const { fields, append, prepend, remove, swap, move, insert } = useFieldArray( - { - control: form.control, - name: "domains", + defaultValues: { + domains: [], }, - ); + }); + const domainsForm = useFieldArray({ + control: form.control, + name: "domains", + }); return (
@@ -45,23 +66,79 @@ export default function DomainsList( onSubmit={form.handleSubmit(async (data) => { console.log(data); })} - className="grid grid-cols-2 gap-4" + className="flex flex-col gap-4" >

Domains

- {fields.map((field, index) => ( -
+ {domainsForm.fields.map((field, index) => ( +
+ ( + + Protocol + + + + )} + /> + {/* toggle */} + {/* } + /> */} + + + + +
))} - +
+ + + + + +
); diff --git a/src/app/(dashboard)/project/[projectId]/service/[serviceId]/domains/page.tsx b/src/app/(dashboard)/project/[projectId]/service/[serviceId]/domains/page.tsx index 862d8c6..2e58c29 100644 --- a/src/app/(dashboard)/project/[projectId]/service/[serviceId]/domains/page.tsx +++ b/src/app/(dashboard)/project/[projectId]/service/[serviceId]/domains/page.tsx @@ -1,7 +1,9 @@ +import DomainsList from "./DomainsList"; + export default function DomainsPage() { return (
-
- ) -} \ No newline at end of file + ); +} diff --git a/src/hooks/forms.tsx b/src/hooks/forms.tsx index d4eb03a..76dd3c8 100644 --- a/src/hooks/forms.tsx +++ b/src/hooks/forms.tsx @@ -115,10 +115,12 @@ export function SimpleFormField< export function FormSubmit({ form, className, + hideUnsavedChangesIndicator, }: { // eslint-disable-next-line @typescript-eslint/no-explicit-any form: UseFormReturn>; className?: string; + hideUnsavedChangesIndicator?: boolean; }) { return (
@@ -126,13 +128,28 @@ export function FormSubmit({ Save {/* unsaved changes indicator */} -

- You have unsaved changes! -

+ {!hideUnsavedChangesIndicator && ( + + )}
); } + +export function FormUnsavedChangesIndicator({ + form, + className, +}: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + form: UseFormReturn>; + className?: string; +}) { + return ( +

+ You have unsaved changes! +

+ ); +}