diff --git a/apps/dokploy/components/dashboard/application/environment/show-enviroment.tsx b/apps/dokploy/components/dashboard/application/environment/show-enviroment.tsx index cc208d9bf..8a78c2745 100644 --- a/apps/dokploy/components/dashboard/application/environment/show-enviroment.tsx +++ b/apps/dokploy/components/dashboard/application/environment/show-enviroment.tsx @@ -71,15 +71,19 @@ export const ShowEnvironment = ({ id, type }: Props) => { resolver: zodResolver(addEnvironmentSchema), }); + // Watch form value + const currentEnvironment = form.watch("environment"); + const hasChanges = currentEnvironment !== (data?.env || ""); + useEffect(() => { if (data) { form.reset({ environment: data.env || "", }); } - }, [form.reset, data, form]); + }, [data, form]); - const onSubmit = async (data: EnvironmentSchema) => { + const onSubmit = async (formData: EnvironmentSchema) => { mutateAsync({ mongoId: id || "", postgresId: id || "", @@ -87,7 +91,7 @@ export const ShowEnvironment = ({ id, type }: Props) => { mysqlId: id || "", mariadbId: id || "", composeId: id || "", - env: data.environment, + env: formData.environment, }) .then(async () => { toast.success("Environments Added"); @@ -98,6 +102,12 @@ export const ShowEnvironment = ({ id, type }: Props) => { }); }; + const handleCancel = () => { + form.reset({ + environment: data?.env || "", + }); + }; + return (
@@ -106,6 +116,11 @@ export const ShowEnvironment = ({ id, type }: Props) => { Environment Settings You can add environment variables to your resource. + {hasChanges && ( + + (You have unsaved changes) + + )}
@@ -155,8 +170,22 @@ PORT=3000 )} /> -
- + )} +
diff --git a/apps/dokploy/components/dashboard/application/environment/show.tsx b/apps/dokploy/components/dashboard/application/environment/show.tsx index d97c39e2f..b574ce092 100644 --- a/apps/dokploy/components/dashboard/application/environment/show.tsx +++ b/apps/dokploy/components/dashboard/application/environment/show.tsx @@ -7,6 +7,7 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; +import { useEffect } from "react"; const addEnvironmentSchema = z.object({ env: z.string(), @@ -34,16 +35,32 @@ export const ShowEnvironment = ({ applicationId }: Props) => { const form = useForm({ defaultValues: { - env: data?.env || "", - buildArgs: data?.buildArgs || "", + env: "", + buildArgs: "", }, resolver: zodResolver(addEnvironmentSchema), }); - const onSubmit = async (data: EnvironmentSchema) => { + // Watch form values + const currentEnv = form.watch("env"); + const currentBuildArgs = form.watch("buildArgs"); + const hasChanges = + currentEnv !== (data?.env || "") || + currentBuildArgs !== (data?.buildArgs || ""); + + useEffect(() => { + if (data) { + form.reset({ + env: data.env || "", + buildArgs: data.buildArgs || "", + }); + } + }, [data, form]); + + const onSubmit = async (formData: EnvironmentSchema) => { mutateAsync({ - env: data.env, - buildArgs: data.buildArgs, + env: formData.env, + buildArgs: formData.buildArgs, applicationId, }) .then(async () => { @@ -55,6 +72,13 @@ export const ShowEnvironment = ({ applicationId }: Props) => { }); }; + const handleCancel = () => { + form.reset({ + env: data?.env || "", + buildArgs: data?.buildArgs || "", + }); + }; + return (
@@ -65,7 +89,16 @@ export const ShowEnvironment = ({ applicationId }: Props) => { + You can add environment variables to your resource. + {hasChanges && ( + + (You have unsaved changes) + + )} + + } placeholder={["NODE_ENV=production", "PORT=3000"].join("\n")} /> {data?.buildType === "dockerfile" && ( @@ -89,8 +122,18 @@ export const ShowEnvironment = ({ applicationId }: Props) => { placeholder="NPM_TOKEN=xyz" /> )} -
- + )} +