From 8baffea673893da837edca73b4cbb819c05cb2d8 Mon Sep 17 00:00:00 2001 From: Manuel Rodriguez Date: Wed, 24 Jul 2024 08:42:32 -0700 Subject: [PATCH 1/5] Added gst input to fixed payments and updated check component to have a handler --- .../src/components/common/form/Check.tsx | 5 ++++ .../payment/modal/period/PeriodForm.tsx | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/source/frontend/src/components/common/form/Check.tsx b/source/frontend/src/components/common/form/Check.tsx index d3ac6a5355..8975c44511 100644 --- a/source/frontend/src/components/common/form/Check.tsx +++ b/source/frontend/src/components/common/form/Check.tsx @@ -43,6 +43,7 @@ type OptionalAttributes = { toolTip?: string; /** id for tooltip */ toolTipId?: string; + handleChange?: (field: string, value: boolean) => void; }; // only "field" is required for , the rest are optional @@ -67,6 +68,7 @@ export const Check: React.FC> = ({ radioLabelTwo, toolTip, toolTipId, + handleChange, ...rest }) => { const { values, initialValues, setFieldValue, setFieldTouched, errors, touched, handleBlur } = @@ -113,8 +115,10 @@ export const Check: React.FC> = ({ onChange={() => { if (type !== 'radio') { setFieldValue(field, !checked); + handleChange(field, !checked); } else { setFieldValue(field, true); + handleChange(field, true); } }} onBlur={handleBlur} @@ -137,6 +141,7 @@ export const Check: React.FC> = ({ checked={checked === false} onChange={() => { setFieldValue(field, false); + handleChange(field, false); }} onBlur={handleBlur} /> diff --git a/source/frontend/src/features/leases/detail/LeasePages/payment/modal/period/PeriodForm.tsx b/source/frontend/src/features/leases/detail/LeasePages/payment/modal/period/PeriodForm.tsx index cbf99141a1..f043d2e686 100644 --- a/source/frontend/src/features/leases/detail/LeasePages/payment/modal/period/PeriodForm.tsx +++ b/source/frontend/src/features/leases/detail/LeasePages/payment/modal/period/PeriodForm.tsx @@ -20,6 +20,7 @@ import * as API from '@/constants/API'; import { LeasePeriodStatusTypes } from '@/constants/leaseStatusTypes'; import useLookupCodeHelpers from '@/hooks/useLookupCodeHelpers'; import { ApiGen_Concepts_Lease } from '@/models/api/generated/ApiGen_Concepts_Lease'; +import { round } from '@/utils'; import { toTypeCodeNullable } from '@/utils/formUtils'; import { defaultFormLeasePeriod, FormLeasePeriod } from '../../models'; @@ -64,6 +65,23 @@ export const PeriodForm: React.FunctionComponent, + field: string, + values: boolean, + ) => { + console.log(field, values); + if (values === true) { + const gstConstant = 8; + const calculated = round((formikState.values.paymentAmount as number) * (gstConstant / 100)); + formikState.setFieldValue('gstAmount', calculated); + console.log(calculated); + console.log(formikRef); + } else { + formikState.setFieldValue('gstAmount', null); + } + }; + return ( <> @@ -168,9 +186,17 @@ export const PeriodForm: React.FunctionComponent onGstCheckChange(formikProps, field, value)} /> + {formikProps.values.isGstEligible === true && ( + + + + + + )} + )} + + {formatMoney( + calculateTotal( + formikProps.values.paymentAmount, + formikProps.values.gstAmount, + ), + )} +