Skip to content

Commit

Permalink
fix: no need for paysubsidy attachment when no subsidies (HL-1011) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjturt authored Oct 12, 2023
1 parent e0536a8 commit d28703c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ATTACHMENT_TYPES,
ORGANIZATION_TYPES,
PAY_SUBSIDY_GRANTED,
TRUTHY_SUBSIDIES,
} from 'benefit-shared/constants';
import {
ApplicationData,
Expand Down Expand Up @@ -91,11 +92,6 @@ const FormContent: React.FC<Props> = ({
getErrorMessage,
} = useFormContent(formik, fields);

const truthySubsidies = new Set([
PAY_SUBSIDY_GRANTED.GRANTED,
PAY_SUBSIDY_GRANTED.GRANTED_AGED,
]);

const theme = useTheme();
useAlertBeforeLeaving(formik.dirty);

Expand Down Expand Up @@ -518,7 +514,7 @@ const FormContent: React.FC<Props> = ({
/>
</SelectionGroup>
</$GridCell>
{truthySubsidies.has(formik.values.paySubsidyGranted) && (
{TRUTHY_SUBSIDIES.has(formik.values.paySubsidyGranted) && (
<$GridCell
as={$Grid}
$colSpan={12}
Expand Down Expand Up @@ -660,7 +656,7 @@ const FormContent: React.FC<Props> = ({
/>
</$GridCell>
)}
{truthySubsidies.has(formik.values.paySubsidyGranted) && (
{TRUTHY_SUBSIDIES.has(formik.values.paySubsidyGranted) && (
<$GridCell $colSpan={12}>
<AttachmentsList
attachments={attachments}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ReviewChildProps } from 'benefit/handler/types/common';
import { TRUTHY_SUBSIDIES } from 'benefit-shared/constants';
import camelCase from 'lodash/camelCase';
import { useTranslation } from 'next-i18next';
import React from 'react';
Expand Down Expand Up @@ -107,11 +108,13 @@ const EmploymentSection: React.FC<ReviewChildProps> = ({
{t(`${translationsBase}.fields.paySubsidyGranted.review`)}
</$ViewFieldBold>
<$ViewField>
{t(
`${translationsBase}.fields.paySubsidyGranted.${camelCase(
data.paySubsidyGranted
)}`
)}
{TRUTHY_SUBSIDIES.has(data.paySubsidyGranted)
? t(
`${translationsBase}.fields.paySubsidyGranted.${camelCase(
data.paySubsidyGranted
)}`
)
: '-'}
</$ViewField>
</$GridCell>
<$GridCell $colSpan={6}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
} from 'benefit/handler/types/application';
import {
ATTACHMENT_TYPES,
BENEFIT_TYPES,
EMPLOYEE_KEYS,
PAY_SUBSIDY_OPTIONS,
TRUTHY_SUBSIDIES,
} from 'benefit-shared/constants';
import { ApplicationData } from 'benefit-shared/types/application';
import camelcaseKeys from 'camelcase-keys';
Expand Down Expand Up @@ -173,48 +173,42 @@ const getSubsidyOptions = (): OptionType[] =>
}));

const requiredAttachments = (values: Application): boolean => {
if (
values.benefitType === BENEFIT_TYPES.EMPLOYMENT ||
values.benefitType === BENEFIT_TYPES.SALARY
) {
const hasWorkContract = !isEmpty(
values.attachments?.find(
const hasWorkContract = !isEmpty(
values.attachments?.find(
(att: BenefitAttachment) =>
att.attachmentType === ATTACHMENT_TYPES.EMPLOYMENT_CONTRACT
)
);
const hasFullApplication = !isEmpty(
values.attachments?.find(
(att: BenefitAttachment) =>
att.attachmentType === ATTACHMENT_TYPES.FULL_APPLICATION
)
);
let hasPaySubsidyDecision = true;
if (TRUTHY_SUBSIDIES.has(values.paySubsidyGranted)) {
hasPaySubsidyDecision = !isEmpty(
values?.attachments?.find(
(att: BenefitAttachment) =>
att.attachmentType === ATTACHMENT_TYPES.EMPLOYMENT_CONTRACT
att.attachmentType === ATTACHMENT_TYPES.PAY_SUBSIDY_CONTRACT
)
);
const hasFullApplication = !isEmpty(
values.attachments?.find(
}
let hasApprenticeshipProgram = true;
if (values.apprenticeshipProgram) {
hasApprenticeshipProgram = !isEmpty(
values?.attachments?.find(
(att: BenefitAttachment) =>
att.attachmentType === ATTACHMENT_TYPES.FULL_APPLICATION
att.attachmentType === ATTACHMENT_TYPES.EDUCATION_CONTRACT
)
);
let hasPaySubsidyDecision = true;
if (values.paySubsidyGranted) {
hasPaySubsidyDecision = !isEmpty(
values?.attachments?.find(
(att: BenefitAttachment) =>
att.attachmentType === ATTACHMENT_TYPES.PAY_SUBSIDY_CONTRACT
)
);
}
let hasApprenticeshipProgram = true;
if (values.apprenticeshipProgram) {
hasApprenticeshipProgram = !isEmpty(
values?.attachments?.find(
(att: BenefitAttachment) =>
att.attachmentType === ATTACHMENT_TYPES.EDUCATION_CONTRACT
)
);
}
return (
hasWorkContract &&
hasFullApplication &&
hasPaySubsidyDecision &&
hasApprenticeshipProgram
);
}
return false;
return (
hasWorkContract &&
hasFullApplication &&
hasPaySubsidyDecision &&
hasApprenticeshipProgram
);
};

export {
Expand Down
5 changes: 5 additions & 0 deletions frontend/benefit/shared/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,9 @@ export enum PAY_SUBSIDY_GRANTED {
NOT_GRANTED = 'not_granted',
}

export const TRUTHY_SUBSIDIES = new Set([
PAY_SUBSIDY_GRANTED.GRANTED,
PAY_SUBSIDY_GRANTED.GRANTED_AGED,
]);

export const APPLICATION_START_DATE = new Date(new Date().getFullYear(), 0, 1);

0 comments on commit d28703c

Please sign in to comment.