From e0f5900c0a9aaaf28ca50f27ceeb123344e60c66 Mon Sep 17 00:00:00 2001 From: Piyush Gupta Date: Tue, 25 Nov 2025 22:40:26 +0530 Subject: [PATCH] fix: populate slug conditionally --- .../AddEnvironmentModal.tsx | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/EnvironmentSection/AddEnvironmentModal.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/EnvironmentSection/AddEnvironmentModal.tsx index 95f1ebd47..5ff1a1535 100644 --- a/frontend/src/pages/secret-manager/SettingsPage/components/EnvironmentSection/AddEnvironmentModal.tsx +++ b/frontend/src/pages/secret-manager/SettingsPage/components/EnvironmentSection/AddEnvironmentModal.tsx @@ -32,7 +32,13 @@ type ContentProps = { const Content = ({ onComplete }: ContentProps) => { const { currentProject } = useProject(); const { mutateAsync, isPending } = useCreateWsEnvironment(); - const { control, handleSubmit, setValue } = useForm({ + const { + control, + handleSubmit, + setValue, + getValues, + formState: { dirtyFields } + } = useForm({ resolver: zodResolver(schema) }); @@ -53,9 +59,10 @@ const Content = ({ onComplete }: ContentProps) => { onComplete(env); }; - const handleEnvironmentNameChange = (e: React.ChangeEvent) => { - const { value } = e.target; - setValue("environmentName", value); + const handleEnvironmentNameChange = () => { + if (dirtyFields.environmentSlug) return; + + const value = getValues("environmentName"); setValue("environmentSlug", slugify(value, { lowercase: true })); }; @@ -67,7 +74,13 @@ const Content = ({ onComplete }: ContentProps) => { name="environmentName" render={({ field: { onChange, ...field }, fieldState: { error } }) => ( - + { + onChange(e); + handleEnvironmentNameChange(); + }} + /> )} />