diff --git a/frontend/benefit/applicant/src/components/applications/forms/application/step2/ApplicationFormStep2.tsx b/frontend/benefit/applicant/src/components/applications/forms/application/step2/ApplicationFormStep2.tsx index af8d3f00d1..fac0cdead0 100644 --- a/frontend/benefit/applicant/src/components/applications/forms/application/step2/ApplicationFormStep2.tsx +++ b/frontend/benefit/applicant/src/components/applications/forms/application/step2/ApplicationFormStep2.tsx @@ -416,9 +416,10 @@ const ApplicationFormStep2: React.FC = ({ /> - {(formik.values.paySubsidyGranted === PAY_SUBSIDY_GRANTED.GRANTED || - formik.values.paySubsidyGranted === - PAY_SUBSIDY_GRANTED.GRANTED_AGED) && ( + {[ + PAY_SUBSIDY_GRANTED.GRANTED, + PAY_SUBSIDY_GRANTED.GRANTED_AGED, + ].includes(formik.values.paySubsidyGranted) && ( <$GridCell $colSpan={12}> <$SubFieldContainer> ): FormActions => { // eslint-disable-next-line sonarjs/cognitive-complexity const getModifiedValues = (currentValues: Application): Application => { const employee: Employee | undefined = currentValues?.employee ?? undefined; + const { paySubsidyGranted, startDate, endDate, apprenticeshipProgram } = + currentValues; + const paySubsidyPercent = + paySubsidyGranted === PAY_SUBSIDY_GRANTED.NOT_GRANTED + ? null + : PAY_SUBSIDY_OPTIONS[0]; + if (employee) { employee.commissionAmount = employee.commissionAmount ? String(getNumberValue(employee.commissionAmount.toString())) @@ -115,14 +126,14 @@ const useFormActions = (application: Partial): FormActions => { const normalizedValues = { ...currentValues, employee, - paySubsidyPercent: PAY_SUBSIDY_OPTIONS[0], - startDate: currentValues.startDate - ? convertToBackendDateFormat(parseDate(currentValues.startDate)) + paySubsidyPercent, + startDate: startDate + ? convertToBackendDateFormat(parseDate(startDate)) : undefined, - endDate: currentValues.endDate - ? convertToBackendDateFormat(parseDate(currentValues.endDate)) + endDate: endDate + ? convertToBackendDateFormat(parseDate(endDate)) : undefined, - apprenticeshipProgram: currentValues.apprenticeshipProgram, + apprenticeshipProgram, }; const deMinimisAidSet = deMinimisAids; @@ -144,6 +155,7 @@ const useFormActions = (application: Partial): FormActions => { { ...values, applicationStep: getApplicationStepString(step), + benefit_type: BENEFIT_TYPES.SALARY, calculation: values.calculation ? { ...values.calculation, diff --git a/frontend/benefit/handler/src/components/newApplication/formContent/FormContent.tsx b/frontend/benefit/handler/src/components/newApplication/formContent/FormContent.tsx index 8e7581ae9c..8b0942e03f 100644 --- a/frontend/benefit/handler/src/components/newApplication/formContent/FormContent.tsx +++ b/frontend/benefit/handler/src/components/newApplication/formContent/FormContent.tsx @@ -257,7 +257,6 @@ const FormContent: React.FC = ({ )} - @@ -413,7 +412,6 @@ const FormContent: React.FC = ({ - <$GridCell $colSpan={8}> = ({ <$RadioButton id={`${fields.paySubsidyGranted.name}.null`} name={fields.paySubsidyGranted.name} - value={null} + value={PAY_SUBSIDY_GRANTED.NOT_GRANTED} label={t( `${translationsBase}.fields.${fields.paySubsidyGranted.name}.no` )} onBlur={formik.handleBlur} onChange={() => { - formik.setFieldValue(fields.paySubsidyGranted.name, null); + formik.setFieldValue( + fields.paySubsidyGranted.name, + PAY_SUBSIDY_GRANTED.NOT_GRANTED + ); }} - checked={formik.values.paySubsidyGranted === null} + checked={ + formik.values.paySubsidyGranted === + PAY_SUBSIDY_GRANTED.NOT_GRANTED + } /> {[ PAY_SUBSIDY_GRANTED.GRANTED, PAY_SUBSIDY_GRANTED.GRANTED_AGED, - ].includes(formik.values.paySubsidyGranted as PAY_SUBSIDY_GRANTED) && ( + ].includes(formik.values.paySubsidyGranted) && ( <$GridCell as={$Grid} $colSpan={12} @@ -540,7 +544,6 @@ const FormContent: React.FC = ({ )} - = ({ /> - ): FormActions => { )[0]; } if (key === 'approveTerms') { - return

{t('common:error.terms.text')}

; + return ( +

+ {t('common:error.terms.text')} +

+ ); } return ( @@ -124,6 +129,15 @@ const useFormActions = (application: Partial): FormActions => { // eslint-disable-next-line sonarjs/cognitive-complexity const getModifiedValues = (currentValues: Application): Application => { const employee: Employee | undefined = currentValues?.employee ?? undefined; + + const { paySubsidyGranted, startDate, endDate, apprenticeshipProgram } = + currentValues; + + const paySubsidyPercent = + paySubsidyGranted === PAY_SUBSIDY_GRANTED.NOT_GRANTED + ? null + : PAY_SUBSIDY_OPTIONS[0]; + if (employee) { employee.commissionAmount = employee.commissionAmount ? String(getNumberValue(employee.commissionAmount.toString())) @@ -144,15 +158,15 @@ const useFormActions = (application: Partial): FormActions => { const normalizedValues = { ...currentValues, - paySubsidyPercent: PAY_SUBSIDY_OPTIONS[0], + paySubsidyPercent, employee: employee || {}, - startDate: currentValues.startDate - ? convertToBackendDateFormat(parseDate(currentValues.startDate)) + startDate: startDate + ? convertToBackendDateFormat(parseDate(startDate)) : undefined, - endDate: currentValues.endDate - ? convertToBackendDateFormat(parseDate(currentValues.endDate)) + endDate: endDate + ? convertToBackendDateFormat(parseDate(endDate)) : undefined, - apprenticeshipProgram: currentValues.apprenticeshipProgram, + apprenticeshipProgram, }; const deMinimisAidSet = diff --git a/frontend/benefit/handler/src/types/application.d.ts b/frontend/benefit/handler/src/types/application.d.ts index 3e2ee5b1fa..ec7f4aa9c5 100644 --- a/frontend/benefit/handler/src/types/application.d.ts +++ b/frontend/benefit/handler/src/types/application.d.ts @@ -6,7 +6,7 @@ import { CALCULATION_SALARY_KEYS, EMPLOYEE_KEYS, ORGANIZATION_TYPES, - PAY_SUBSIDY_TYPES, + PAY_SUBSIDY_GRANTED, } from 'benefit-shared/constants'; import { ApplicantTerms, @@ -151,7 +151,7 @@ export interface ApplicationForm { [APPLICATION_FIELD_KEYS.CO_OPERATION_NEGOTIATIONS_DESCRIPTION]?: string; [APPLICATION_FIELD_KEYS.DE_MINIMIS_AID]?: boolean | null; [APPLICATION_FIELD_KEYS.DE_MINIMIS_AID_SET]?: DeMinimisAid[]; - [APPLICATION_FIELD_KEYS.PAY_SUBSIDY_GRANTED]?: PAY_SUBSIDY_TYPES | null; + [APPLICATION_FIELD_KEYS.PAY_SUBSIDY_GRANTED]?: PAY_SUBSIDY_GRANTED | null; [APPLICATION_FIELD_KEYS.APPRENTICESHIP_PROGRAM]?: boolean | null; [APPLICATION_FIELD_KEYS.BENEFIT_TYPE]?: BENEFIT_TYPES | ''; [APPLICATION_FIELD_KEYS.START_DATE]?: string | '';