Skip to content

Commit

Permalink
Creation of payment plan reads status linked criteria (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
weilu authored Aug 7, 2024
1 parent 29c51cb commit 942e737
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/dialogs/AdvancedCriteriaDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,25 @@ const AdvancedCriteriaDialog = ({
const [filters, setFilters] = useState(getDefaultAppliedCustomFilters());

const getBenefitPlanDefaultCriteria = () => {
const { jsonExt } = edited?.benefitPlan ?? {};
try {
const jsonData = JSON.parse(jsonExt);
return jsonData.advanced_criteria || [];
} catch (error) {
return [];
const jsonExt = edited?.benefitPlan?.jsonExt ?? '{}';
const jsonData = JSON.parse(jsonExt);

// Note: advanced_criteria is migrated from [filters] to {status: filters}
// For backward compatibility default status take on the old filters
let criteria = jsonData?.advanced_criteria || {};
if (Array.isArray(criteria)) {
return criteria;
}

return criteria['ACTIVE'] || [];
};

useEffect(() => {
if (!getDefaultAppliedCustomFilters().length) {
const defaultAppliedCustomFilters = getDefaultAppliedCustomFilters();
if (!defaultAppliedCustomFilters.length) {
setFilters(getBenefitPlanDefaultCriteria());
} else {
setFilters(defaultAppliedCustomFilters);
}
}, [edited]);

Expand Down

0 comments on commit 942e737

Please sign in to comment.