diff --git a/apps/dokploy/__test__/drop/drop.test.ts b/apps/dokploy/__test__/drop/drop.test.ts index d22c1c4b0..bd2d3c981 100644 --- a/apps/dokploy/__test__/drop/drop.test.ts +++ b/apps/dokploy/__test__/drop/drop.test.ts @@ -33,6 +33,7 @@ const baseApp: ApplicationNested = { buildServerId: "", buildRegistryId: "", buildRegistry: null, + args: [], giteaBuildPath: "", previewRequireCollaboratorPermissions: false, giteaId: "", diff --git a/apps/dokploy/__test__/traefik/traefik.test.ts b/apps/dokploy/__test__/traefik/traefik.test.ts index f63175748..e6b98c3ba 100644 --- a/apps/dokploy/__test__/traefik/traefik.test.ts +++ b/apps/dokploy/__test__/traefik/traefik.test.ts @@ -16,6 +16,7 @@ const baseApp: ApplicationNested = { buildRegistry: null, giteaBuildPath: "", giteaId: "", + args: [], cleanCache: false, applicationStatus: "done", endpointSpecSwarm: null, diff --git a/apps/dokploy/components/dashboard/application/advanced/general/add-command.tsx b/apps/dokploy/components/dashboard/application/advanced/general/add-command.tsx index 1bf69394a..e57f21895 100644 --- a/apps/dokploy/components/dashboard/application/advanced/general/add-command.tsx +++ b/apps/dokploy/components/dashboard/application/advanced/general/add-command.tsx @@ -1,6 +1,7 @@ import { zodResolver } from "@hookform/resolvers/zod"; +import { Plus, Trash2 } from "lucide-react"; import { useEffect } from "react"; -import { useForm } from "react-hook-form"; +import { useFieldArray, useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; import { Button } from "@/components/ui/button"; @@ -28,6 +29,13 @@ interface Props { const AddRedirectSchema = z.object({ command: z.string(), + args: z + .array( + z.object({ + value: z.string().min(1, "Argument cannot be empty"), + }), + ) + .optional(), }); type AddCommand = z.infer; @@ -47,22 +55,36 @@ export const AddCommand = ({ applicationId }: Props) => { const form = useForm({ defaultValues: { command: "", + args: [], }, resolver: zodResolver(AddRedirectSchema), }); + const { fields, append, remove } = useFieldArray({ + control: form.control, + name: "args", + }); + useEffect(() => { if (data?.command) { form.reset({ command: data?.command || "", + args: data?.args?.map((arg) => ({ value: arg })) || [], }); } - }, [form, form.reset, form.formState.isSubmitSuccessful, data?.command]); + }, [ + form, + form.reset, + form.formState.isSubmitSuccessful, + data?.command, + data?.args, + ]); const onSubmit = async (data: AddCommand) => { await mutateAsync({ applicationId, command: data?.command, + args: data?.args?.map((arg) => arg.value).filter(Boolean), }) .then(async () => { toast.success("Command Updated"); @@ -100,13 +122,65 @@ export const AddCommand = ({ applicationId }: Props) => { Command - + )} /> + +
+
+ Arguments (Args) + +
+ + {fields.length === 0 && ( +

+ No arguments added yet. Click "Add Argument" to add one. +

+ )} + + {fields.map((field, index) => ( + ( + +
+ + + + +
+ +
+ )} + /> + ))} +
+
+ + {fields.length === 0 && ( +

+ No arguments added yet. Click "Add Argument" to add one. +

+ )} + + {fields.map((field, index) => ( + ( + +
+ + + + +
+ +
+ )} + /> + ))} + +