From 0f80f46935ee01a7cfff9ad33bdae6230c518cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Kj=C3=A6rg=C3=A5rd?= Date: Tue, 24 Jun 2025 20:42:45 +0200 Subject: [PATCH 1/3] feat: Enhance group editing functionality with initial value tracking and custom data formatting - Added state to store initial values for comparison during form submission. - Implemented a custom data formatter to only send changed values for 'allowExternal' and 'sendCopies'. - Updated form reset logic to include initial values for better state management. --- .../identity/administration/groups/edit.jsx | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/pages/identity/administration/groups/edit.jsx b/src/pages/identity/administration/groups/edit.jsx index f9a6a42a9aa2..4453541ba4d7 100644 --- a/src/pages/identity/administration/groups/edit.jsx +++ b/src/pages/identity/administration/groups/edit.jsx @@ -18,6 +18,7 @@ const EditGroup = () => { const [groupIdReady, setGroupIdReady] = useState(false); const [showMembershipTable, setShowMembershipTable] = useState(false); const [combinedData, setCombinedData] = useState([]); + const [initialValues, setInitialValues] = useState({}); const tenantFilter = useSettings().currentTenant; const groupInfo = ApiGetCall({ @@ -65,8 +66,8 @@ const EditGroup = () => { ]; setCombinedData(combinedData); - // Reset the form with all values - formControl.reset({ + // Create initial values object + const formValues = { tenantFilter: tenantFilter, mail: group.mail, mailNickname: group.mailNickname || "", @@ -103,11 +104,37 @@ const EditGroup = () => { RemoveOwner: [], AddContact: [], RemoveContact: [], + }; + + // Store initial values for comparison + setInitialValues({ + allowExternal: groupInfo?.data?.allowExternal, + sendCopies: groupInfo?.data?.sendCopies, }); + + // Reset the form with all values + formControl.reset(formValues); } } }, [groupInfo.isSuccess, router.query, groupInfo.isFetching]); + // Custom data formatter to only send changed values + const customDataFormatter = (formData) => { + const cleanedData = { ...formData }; + + // Only include allowExternal if it has changed from the initial value + if (formData.allowExternal === initialValues.allowExternal) { + delete cleanedData.allowExternal; + } + + // Only include sendCopies if it has changed from the initial value + if (formData.sendCopies === initialValues.sendCopies) { + delete cleanedData.sendCopies; + } + + return cleanedData; + }; + return ( <> { formPageType="Edit" backButtonTitle="Group Overview" postUrl="/api/EditGroup" + customDataformatter={customDataFormatter} titleButton={ <>