Skip to content

Commit

Permalink
fix: conditional pay subsidy percentage for not_granted
Browse files Browse the repository at this point in the history
* fix: conditional pay subsidy percentage for not_granted

* fix: conditional pay subsidy percentage for not_granted (handler)
  • Loading branch information
sirtawast authored Oct 4, 2023
1 parent 453d4ec commit 536dbe4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,10 @@ const ApplicationFormStep2: React.FC<DynamicFormStepComponentProps> = ({
/>
</SelectionGroup>
</$GridCell>
{(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>
<SelectionGroup
Expand Down
26 changes: 19 additions & 7 deletions frontend/benefit/applicant/src/hooks/useFormActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
getApplicationStepFromString,
getApplicationStepString,
} from 'benefit/applicant/utils/common';
import { BENEFIT_TYPES, PAY_SUBSIDY_OPTIONS } from 'benefit-shared/constants';
import {
BENEFIT_TYPES,
PAY_SUBSIDY_GRANTED,
PAY_SUBSIDY_OPTIONS,
} from 'benefit-shared/constants';
import {
Application,
ApplicationData,
Expand Down Expand Up @@ -94,6 +98,13 @@ const useFormActions = (application: Partial<Application>): 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()))
Expand All @@ -115,14 +126,14 @@ const useFormActions = (application: Partial<Application>): 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;
Expand All @@ -144,6 +155,7 @@ const useFormActions = (application: Partial<Application>): FormActions => {
{
...values,
applicationStep: getApplicationStepString(step),
benefit_type: BENEFIT_TYPES.SALARY,
calculation: values.calculation
? {
...values.calculation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ const FormContent: React.FC<Props> = ({
</$GridCell>
)}
</FormSection>

<FormSection
header={t(`${translationsBase}.headings.employment5Employment`)}
>
Expand Down Expand Up @@ -413,7 +412,6 @@ const FormContent: React.FC<Props> = ({
</$GridCell>
</>
</FormSection>

<FormSection header={t(`${translationsBase}.headings.employment2`)}>
<$GridCell $colSpan={8}>
<SelectionGroup
Expand Down Expand Up @@ -471,22 +469,28 @@ const FormContent: React.FC<Props> = ({
<$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
}
/>
</SelectionGroup>
</$GridCell>
{[
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}
Expand Down Expand Up @@ -540,7 +544,6 @@ const FormContent: React.FC<Props> = ({
</$GridCell>
)}
</FormSection>

<FormSection
header={t(`${translationsBase}.headings.employment4`)}
columns={32}
Expand Down Expand Up @@ -593,7 +596,6 @@ const FormContent: React.FC<Props> = ({
/>
</$GridCell>
</FormSection>

<FormSection
paddingBottom
withoutDivider
Expand Down
28 changes: 21 additions & 7 deletions frontend/benefit/handler/src/hooks/useFormActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Application } from 'benefit/handler/types/application';
import {
APPLICATION_STATUSES,
BENEFIT_TYPES,
PAY_SUBSIDY_GRANTED,
PAY_SUBSIDY_OPTIONS,
} from 'benefit-shared/constants';
import { ApplicationData, Employee } from 'benefit-shared/types/application';
Expand Down Expand Up @@ -102,7 +103,11 @@ const useFormActions = (application: Partial<Application>): FormActions => {
)[0];
}
if (key === 'approveTerms') {
return <p>{t('common:error.terms.text')}</p>;
return (
<p key={`${key}-${String(value)}`}>
{t('common:error.terms.text')}
</p>
);
}
return (
<a key={key} href={`#${key}`}>
Expand All @@ -124,6 +129,15 @@ const useFormActions = (application: Partial<Application>): 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()))
Expand All @@ -144,15 +158,15 @@ const useFormActions = (application: Partial<Application>): 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 =
Expand Down
4 changes: 2 additions & 2 deletions frontend/benefit/handler/src/types/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CALCULATION_SALARY_KEYS,
EMPLOYEE_KEYS,
ORGANIZATION_TYPES,
PAY_SUBSIDY_TYPES,
PAY_SUBSIDY_GRANTED,
} from 'benefit-shared/constants';
import {
ApplicantTerms,
Expand Down Expand Up @@ -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 | '';
Expand Down

0 comments on commit 536dbe4

Please sign in to comment.