From 2ad95de89b986181610b117b6ceff14973b14375 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:34:30 -0400 Subject: [PATCH] filter edited fields correctly --- src/components/pages/Roles/forms/useRoleFormEditedRole.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/pages/Roles/forms/useRoleFormEditedRole.tsx b/src/components/pages/Roles/forms/useRoleFormEditedRole.tsx index c6ef34b0b3..b18d156193 100644 --- a/src/components/pages/Roles/forms/useRoleFormEditedRole.tsx +++ b/src/components/pages/Roles/forms/useRoleFormEditedRole.tsx @@ -3,9 +3,11 @@ import { useMemo } from 'react'; import { DecentTree } from '../../../../store/roles'; import { EditedRole, EditBadgeStatus, RoleFormValues } from '../types'; -const addRemoveField = (fieldNames: string[], fieldName: string, isRemoved: boolean) => { - if (fieldNames.includes(fieldName) && isRemoved) { +const addRemoveField = (fieldNames: string[], fieldName: string, hasChanges: boolean) => { + if (fieldNames.includes(fieldName) && !hasChanges) { return fieldNames.filter(field => field !== fieldName); + } else if (!fieldNames.includes(fieldName) && !hasChanges) { + return fieldNames; } return [...fieldNames, fieldName]; }; @@ -72,6 +74,7 @@ export function useRoleFormEditedRole({ hatsTree }: { hatsTree: DecentTree | und fieldNames = addRemoveField(fieldNames, 'member', isMemberUpdated); fieldNames = addRemoveField(fieldNames, 'payments', isPaymentsUpdated); + console.log('🚀 ~ fieldNames:', fieldNames); return { fieldNames, status: EditBadgeStatus.Updated,