From 16d8ac02280f3121da09e7b98312a94acaf20fbb Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Tue, 25 Jun 2024 07:54:54 -0400 Subject: [PATCH] Make default eligibility criteria editable (#101) * Make benefit plan default eligibility criteria editable * Prevent circular useEffect triggering Effectively the first useEffect is triggered at initialization Then the second useEffect depending on `filters` handles criteria update --- .../BenefitPlanEligibilityCriteriaPanel.js | 84 +++++++++---------- 1 file changed, 38 insertions(+), 46 deletions(-) diff --git a/src/components/BenefitPlanEligibilityCriteriaPanel.js b/src/components/BenefitPlanEligibilityCriteriaPanel.js index cceadeb..1b9751a 100644 --- a/src/components/BenefitPlanEligibilityCriteriaPanel.js +++ b/src/components/BenefitPlanEligibilityCriteriaPanel.js @@ -45,8 +45,6 @@ function BenefitPlanEligibilityCriteriaPanel({ } }; - const isReadOnly = () => getAdvancedCriteria().length > 0; - const handleRemoveFilter = () => { setFilters([]); }; @@ -88,10 +86,10 @@ function BenefitPlanEligibilityCriteriaPanel({ ); fetchFilters(paramsToFetchFilters); } - }, [editedBenefitPlan]); + }, [editedBenefitPlan?.id]); useEffect(() => { - if (editedBenefitPlan?.id && !isReadOnly()) { + if (editedBenefitPlan?.id) { const { jsonExt } = editedBenefitPlan; const jsonData = JSON.parse(jsonExt); const json = { ...jsonData, advanced_criteria: filters }; @@ -130,50 +128,44 @@ function BenefitPlanEligibilityCriteriaPanel({ setCurrentFilter={() => {}} filters={filters} setFilters={setFilters} - readOnly={isReadOnly()} /> ))} - {!isReadOnly() && ( - // eslint-disable-next-line react/jsx-no-useless-fragment - <> -
- - -
-
- -
- - )} +
+ + +
+
+ +