From 6afd1bf531be7c050bb4b27e4c66569dc4df2048 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 8 Mar 2025 19:17:59 -0600 Subject: [PATCH] feat(environment): add unsaved changes handling for environment settings - Implement form change tracking for environment variables - Add cancel and save buttons with conditional rendering - Disable save button when no changes are detected - Show unsaved changes warning in description - Improve user experience with form state management --- .../environment/show-enviroment.tsx | 39 ++++++++++-- .../application/environment/show.tsx | 59 ++++++++++++++++--- 2 files changed, 85 insertions(+), 13 deletions(-) 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 (