Skip to content

Commit

Permalink
Apply rule only on updated field and delete default switch case not n…
Browse files Browse the repository at this point in the history
…eeded
  • Loading branch information
anagperal committed Aug 20, 2024
1 parent e05d8a2 commit 3136ecc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export function applyRulesInFormState(
toggleSectionVisibilityByFieldValue(section, updatedField.value, rule)
),
};
default:
return formState;
}
}, currentFormState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ export function updateDiseaseOutbreakEventFormState(
currentUserUsername: string
): FormState {
const updatedForm = updateFormStateAndApplySideEffects(prevFormState, updatedField);
const updatedFormWithRulesApplied = diseaseOutbreakEventWithOptions.rules.length
? applyRulesInFormState(updatedForm, updatedField, diseaseOutbreakEventWithOptions.rules)
: updatedForm;

const updatedFormWithRulesApplied =
diseaseOutbreakEventWithOptions.rules.filter(rule => rule.fieldId === updatedField.id)
.length > 0
? applyRulesInFormState(
updatedForm,
updatedField,
diseaseOutbreakEventWithOptions.rules
)
: updatedForm;

const fieldValidationErrors = validateDiseaseOutbreakEventFormState(
updatedFormWithRulesApplied,
Expand Down

0 comments on commit 3136ecc

Please sign in to comment.