From 0117237988a02fffb23da2e4f0021844cd2acd66 Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Tue, 19 Dec 2023 09:18:00 -0800 Subject: [PATCH] IO-2506 Correct for variable immutibility and nested ifs --- .../bill-form/bill-form.component.jsx | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/client/src/components/bill-form/bill-form.component.jsx b/client/src/components/bill-form/bill-form.component.jsx index 579d11b7b..ba9f937ba 100644 --- a/client/src/components/bill-form/bill-form.component.jsx +++ b/client/src/components/bill-form/bill-form.component.jsx @@ -80,15 +80,17 @@ export function BillFormComponent({ }; const handleFederalTaxExemptSwitchToggle = (checked) => { - if (checked) { - const values = form.getFieldsValue("billlines"); - if (values && values.billlines && values.billlines.length > 0) { - values.billlines.forEach((b) => { - b.applicable_taxes.federal = false; - }); - } - form.setFieldsValue({ billlines: values.billlines }); - } + // Early gate + if (!checked) return; + const values = form.getFieldsValue("billlines"); + // Gate bill lines + if (!values?.billlines?.length) return; + + const billlines = values.billlines.map((b) => { + b.applicable_taxes.federal = false; + return b; + }); + form.setFieldsValue({ billlines }); }; useEffect(() => {