Skip to content

Commit

Permalink
fix: calculation changed notification (HL-1057) (#2552)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjturt authored Dec 7, 2023
1 parent 8df0441 commit ea65e7c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ const SalaryBenefitCalculatorView: React.FC<
<CalculatorErrors data={calculationsErrors} />
</$GridCell>

{isRecalculationRequired && (
{isRecalculationRequired && data?.calculation?.rows.length > 0 && (
<$GridCell $colStart={1} $colSpan={11}>
<$Notification
type="alert"
Expand Down
13 changes: 5 additions & 8 deletions frontend/benefit/handler/src/hooks/useCalculatorData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CalculationFormProps } from 'benefit/handler/types/application';
import { getErrorText } from 'benefit/handler/utils/forms';
import { FormikProps } from 'formik';
import { TFunction, useTranslation } from 'next-i18next';
import { useEffect, useRef, useState } from 'react';
import { useEffect, useState } from 'react';
import useLocale from 'shared/hooks/useLocale';
import { Language } from 'shared/i18n/i18n';
import { focusAndScroll } from 'shared/utils/dom.utils';
Expand All @@ -29,9 +29,7 @@ const useCalculatorData = (
const translationsBase = `common:calculators.${calculatorType}`;
const { t } = useTranslation();

const { errors, touched, values } = formik;

const didMount = useRef(false);
const { errors, touched, values, dirty } = formik;

const [isSubmitted, setIsSubmitted] = useState<boolean>(false);

Expand All @@ -45,6 +43,7 @@ const useCalculatorData = (
void formik.validateForm().then((errs) => {
const fieldName = Object.keys(errs)[0];
if (!fieldName) {
setIsRecalculationRequired(false);
return formik.submitForm();
}
return focusAndScroll(fieldName);
Expand All @@ -56,10 +55,8 @@ const useCalculatorData = (
};

useEffect(() => {
if (didMount.current && !isRecalculationRequired)
setIsRecalculationRequired(true);
else didMount.current = true;
}, [isRecalculationRequired, values]);
if (dirty) setIsRecalculationRequired(true);
}, [dirty, values]);

return {
t,
Expand Down

0 comments on commit ea65e7c

Please sign in to comment.