Skip to content

Commit

Permalink
filter edited fields correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Da-Colon committed Aug 28, 2024
1 parent 9314ab7 commit 2ad95de
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/pages/Roles/forms/useRoleFormEditedRole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2ad95de

Please sign in to comment.