From 7d62ea3f5fdd6494588d1abda5480985ee422fff Mon Sep 17 00:00:00 2001 From: TIDJANI Bachir <144597750+Tidjani1Bachir@users.noreply.github.com> Date: Wed, 6 May 2026 15:29:07 +0100 Subject: [PATCH] fix(client): privacy save button state (#67230) --- .../components/profile/components/profile-privacy.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/client/src/components/profile/components/profile-privacy.tsx b/client/src/components/profile/components/profile-privacy.tsx index af9c510f415..52ddfda51eb 100644 --- a/client/src/components/profile/components/profile-privacy.tsx +++ b/client/src/components/profile/components/profile-privacy.tsx @@ -1,3 +1,4 @@ +import isEqual from 'lodash/isEqual'; import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { connect } from 'react-redux'; @@ -32,12 +33,15 @@ function ProfilePrivacyComponent({ }: ProfilePrivacyProps): JSX.Element { const { t } = useTranslation(); const [isExpanded, setIsExpanded] = useState(user.profileUI.isLocked); + // Snapshot of the original values to detect unsaved changes + const [initialPrivacyValues, setInitialPrivacyValues] = useState({ + ...user.profileUI + }); const [privacyValues, setPrivacyValues] = useState({ ...user.profileUI }); - const [madeChanges, setMadeChanges] = useState(false); + const madeChanges = !isEqual(privacyValues, initialPrivacyValues); function toggleFlag(flag: keyof ProfileUI): () => void { return () => { - setMadeChanges(true); setPrivacyValues({ ...privacyValues, [flag]: !privacyValues[flag] }); }; } @@ -46,7 +50,7 @@ function ProfilePrivacyComponent({ e.preventDefault(); if (!madeChanges) return; submitProfileUI(privacyValues); - setMadeChanges(false); + setInitialPrivacyValues({ ...privacyValues }); // reset baseline after saving } return (