Skip to content

Commit

Permalink
feat: show de minimis status in the decision box for applicant (#3085)…
Browse files Browse the repository at this point in the history
… (HL-1266)
  • Loading branch information
EmiliaMakelaVincit authored Jun 13, 2024
1 parent c3b0820 commit e511717
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 71 deletions.
15 changes: 14 additions & 1 deletion backend/benefit/applications/api/v1/serializers/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class Meta:
"ahjo_case_id",
"changes",
"archived_for_applicant",
"is_granted_as_de_minimis_aid",
"alterations",
"calculated_benefit_amount",
"ahjo_decision_date",
Expand Down Expand Up @@ -233,6 +234,7 @@ class Meta:
"total_deminimis_amount",
"changes",
"archived_for_applicant",
"is_granted_as_de_minimis_aid",
"alterations",
"calculated_benefit_amount",
"ahjo_decision_date",
Expand Down Expand Up @@ -465,7 +467,12 @@ class Meta:

archived_for_applicant = serializers.SerializerMethodField(
method_name="get_archived_for_applicant",
help_text=("Should be shown in the archive view for an applicant"),
help_text="Should be shown in the archive view for an applicant",
)

is_granted_as_de_minimis_aid = serializers.SerializerMethodField(
method_name="get_is_granted_as_de_minimis_aid",
help_text="Granted as de minimis aid",
)

def get_applicant_terms_approval_needed(self, obj):
Expand Down Expand Up @@ -1424,6 +1431,12 @@ def get_archived_for_applicant(self, application):
ApplicationBatchStatus.COMPLETED,
] and application.batch.decision_date < date.today() + relativedelta(days=-14)

def get_is_granted_as_de_minimis_aid(self, application):
if not hasattr(application, "calculation"):
return None

return application.calculation.granted_as_de_minimis_aid


class ApplicantApplicationStatusChoiceField(serializers.ChoiceField):
"""
Expand Down
4 changes: 3 additions & 1 deletion frontend/benefit/applicant/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@
"decisionDate": "Decision made on",
"benefitPeriod": "Benefit period",
"benefitAmount": "Total benefit granted",
"existingAlterations": "Change to employment"
"existingAlterations": "Change to employment",
"extraDetails": "Additional details"
},
"alterationList": {
"count_one": "{{count}} change in employment reported",
Expand Down Expand Up @@ -471,6 +472,7 @@
"cancel": "Cancel"
}
},
"grantedAsDeMinimisAid": "Benefit was granted as de minimis aid",
"actions": {
"showDecision": "View decision",
"reportAlteration": "Report changes to employment"
Expand Down
4 changes: 3 additions & 1 deletion frontend/benefit/applicant/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@
"decisionDate": "Päätös tehty",
"benefitPeriod": "Tukiaika",
"benefitAmount": "Myönnetty tuki yhteensä",
"existingAlterations": "Muutokset työsuhteessa"
"existingAlterations": "Muutokset työsuhteessa",
"extraDetails": "Lisätiedot"
},
"alterationList": {
"count_one": "{{count}} ilmoitettu muutos työsuhteessa",
Expand Down Expand Up @@ -471,6 +472,7 @@
"cancel": "Peruuta"
}
},
"grantedAsDeMinimisAid": "Tuki on myönnetty de minimis -tukena",
"actions": {
"showDecision": "Tarkastele päätöstä",
"reportAlteration": "Ilmoita työsuhteen muutoksesta"
Expand Down
4 changes: 3 additions & 1 deletion frontend/benefit/applicant/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@
"decisionDate": "Beslutet fattades",
"benefitPeriod": "Stödtid",
"benefitAmount": "Beviljat stöd sammanlagt",
"existingAlterations": "Ändring i anställningen"
"existingAlterations": "Ändring i anställningen",
"extraDetails": "Ytterligare information"
},
"alterationList": {
"count_one": "{{count}} ändring i anställningen anmälde",
Expand Down Expand Up @@ -471,6 +472,7 @@
"cancel": "Ångra"
}
},
"grantedAsDeMinimisAid": "Stödet har beviljats som de minimis-stöd",
"actions": {
"showDecision": "Kontrollera beslutet",
"reportAlteration": "Anmäl ändring i anställningen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ import { ROUTES, SUBMITTED_STATUSES } from 'benefit/applicant/constants';
import { useAskem } from 'benefit/applicant/hooks/useAnalytics';
import DecisionSummary from 'benefit-shared/components/decisionSummary/DecisionSummary';
import StatusIcon from 'benefit-shared/components/statusIcon/StatusIcon';
import { ALTERATION_STATE, ALTERATION_TYPE, APPLICATION_STATUSES } from 'benefit-shared/constants';
import {
ALTERATION_STATE,
ALTERATION_TYPE,
APPLICATION_STATUSES,
} from 'benefit-shared/constants';
import { DecisionDetailList } from 'benefit-shared/types/application';
import { Button, IconInfoCircleFill, LoadingSpinner, Stepper } from 'hds-react';
import { useRouter } from 'next/router';
import React, { useEffect, useMemo } from 'react';
import Container from 'shared/components/container/Container';
import { getFullName } from 'shared/utils/application.utils';
import { convertToUIDateAndTimeFormat, convertToUIDateFormat } from 'shared/utils/date.utils';
import {
convertToUIDateAndTimeFormat,
convertToUIDateFormat,
} from 'shared/utils/date.utils';
import { formatFloatToCurrency } from 'shared/utils/string.utils';
import { useTheme } from 'styled-components';

Expand Down Expand Up @@ -75,27 +82,41 @@ const PageContent: React.FC = () => {
window.scrollTo(0, 0);
}, [currentStep]);

const decisionDetailList = useMemo<DecisionDetailList>(() => [
{
accessor: (app) => <>
<StatusIcon status={app.status} />
{t(`common:applications.statuses.${app.status}`)}
</>,
key: 'status',
},
{
accessor: (app) => formatFloatToCurrency(app.calculatedBenefitAmount),
key: 'benefitAmount',
},
{
accessor: (app) => `${convertToUIDateFormat(app.startDate)}${convertToUIDateFormat(app.endDate)}`,
key: 'benefitPeriod',
},
{
accessor: (app) => convertToUIDateFormat(app.ahjoDecisionDate),
key: 'decisionDate',
}
], [t]);
const decisionDetailList = useMemo<DecisionDetailList>(
() => [
{
accessor: (app) => (
<>
<StatusIcon status={app.status} />
{t(`common:applications.statuses.${app.status}`)}
</>
),
key: 'status',
},
{
accessor: (app) => formatFloatToCurrency(app.calculatedBenefitAmount),
key: 'benefitAmount',
},
{
accessor: (app) =>
`${convertToUIDateFormat(app.startDate)}${convertToUIDateFormat(
app.endDate
)}`,
key: 'benefitPeriod',
},
{
accessor: (app) => convertToUIDateFormat(app.ahjoDecisionDate),
key: 'decisionDate',
},
{
accessor: () => t('common:applications.decision.grantedAsDeMinimisAid'),
key: 'extraDetails',
width: 6,
showIf: (app) => app.isGrantedAsDeMinimisAid === true,
},
],
[t]
);

if (isLoading) {
return (
Expand Down Expand Up @@ -198,7 +219,8 @@ const PageContent: React.FC = () => {
</$PageHeader>
<DecisionSummary
application={application}
actions={application.status === APPLICATION_STATUSES.ACCEPTED ? (
actions={
application.status === APPLICATION_STATUSES.ACCEPTED ? (
<Button
theme="coat"
onClick={() =>
Expand All @@ -210,7 +232,8 @@ const PageContent: React.FC = () => {
>
{t('common:applications.decision.actions.reportAlteration')}
</Button>
) : null}
) : null
}
itemComponent={AlterationAccordionItem}
detailList={decisionDetailList}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { respondAbove } from 'shared/styles/mediaQueries';
import { $Grid } from 'shared/components/forms/section/FormSection.sc';
import styled from 'styled-components';

export const $DecisionBox = styled.section`
Expand Down Expand Up @@ -28,26 +28,10 @@ export const $Subheading = styled.h2`
font-size: ${(props) => props.theme.fontSize.heading.s};
`;

export const $DecisionDetails = styled.dl`
display: flex;
flex-direction: column;
flex-wrap: wrap;
box-sizing: border-box;
margin: 0 calc(${(props) => props.theme.spacing.s} * -1);
${respondAbove('md')`
flex-direction: row;
justify-content: stretch;
div {
width: 25%;
}
`};
div {
box-sizing: border-box;
padding: ${(props) => props.theme.spacing.s};
}
export const $DecisionDetails = styled($Grid)`
margin: ${(props) => props.theme.spacing.l} 0
${(props) => props.theme.spacing.s};
row-gap: ${(props) => props.theme.spacing.l};
dt {
font-weight: 500;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import {
$DecisionNumber,
$Subheading,
} from 'benefit-shared/components/decisionSummary/DecisionSummary.sc';
import { AlterationAccordionItemProps, Application, DecisionDetailList } from 'benefit-shared/types/application';
import {
AlterationAccordionItemProps,
Application,
DecisionDetailList,
} from 'benefit-shared/types/application';
import { isTruthy } from 'benefit-shared/utils/common';
import { Button, IconLinkExternal } from 'hds-react';
import { useTranslation } from 'next-i18next';
import React, { ReactNode } from 'react';
import { $GridCell } from 'shared/components/forms/section/FormSection.sc';
import { convertToUIDateFormat } from 'shared/utils/date.utils';

type Props = {
Expand All @@ -23,7 +28,13 @@ type Props = {
extraInformation?: ReactNode;
};

const DecisionSummary = ({ application, actions, itemComponent: ItemComponent, detailList, extraInformation }: Props): JSX.Element => {
const DecisionSummary = ({
application,
actions,
itemComponent: ItemComponent,
detailList,
extraInformation,
}: Props): JSX.Element => {
const { t } = useTranslation();

if (!application.ahjoCaseId) {
Expand Down Expand Up @@ -57,13 +68,21 @@ const DecisionSummary = ({ application, actions, itemComponent: ItemComponent, d
dateRangeEnd: convertToUIDateFormat(application.endDate),
})}
</$Subheading>
<$DecisionDetails>
{detailList.map((detail) => <div key={detail.key}>
<dt>{t(`common:applications.decision.headings.${detail.key}`)}</dt>
<dd>
{detail.accessor(application) || '-'}
</dd>
</div>)}
<$DecisionDetails as="dl">
{detailList.map((detail) => {
if (detail.showIf && !detail.showIf(application)) {
return null;
}

return (
<$GridCell $colSpan={detail.width || 3} key={detail.key}>
<dt>
{t(`common:applications.decision.headings.${detail.key}`)}
</dt>
<dd>{detail.accessor(application) || '-'}</dd>
</$GridCell>
);
})}
</$DecisionDetails>
{extraInformation}
<$DecisionActionContainer>
Expand Down Expand Up @@ -96,9 +115,7 @@ const DecisionSummary = ({ application, actions, itemComponent: ItemComponent, d
application={application}
/>
))}
<$AlterationActionContainer>
{actions}
</$AlterationActionContainer>
<$AlterationActionContainer>{actions}</$AlterationActionContainer>
</>
)}
</$DecisionBox>
Expand Down
7 changes: 6 additions & 1 deletion frontend/benefit/shared/src/types/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export type Application = {
organizationType?: ORGANIZATION_TYPES;
associationImmediateManagerCheck?: boolean;
archivedForApplicant?: boolean;
isGrantedAsDeMinimisAid?: boolean | null;
ahjoCaseId?: string;
ahjoDecisionDate?: string;
calculatedBenefitAmount?: number;
Expand Down Expand Up @@ -451,6 +452,8 @@ export type ApplicationData = {
company_contact_person_last_name: string;
talpa_status: TALPA_STATUSES;
ahjo_case_id: string;
archived_for_applicant?: boolean;
is_granted_as_de_minimis_aid?: boolean | null;
};

export type EmployeeData = {
Expand Down Expand Up @@ -676,6 +679,8 @@ export type AlterationAccordionItemProps = {
export type DecisionDetailAccessorFunction = (app: Application) => ReactNode;

export type DecisionDetailList = Array<{
accessor: DecisionDetailAccessorFunction;
key: string;
accessor: DecisionDetailAccessorFunction;
width?: number;
showIf?: (app: Application) => boolean;
}>;
16 changes: 8 additions & 8 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4886,11 +4886,11 @@ brace-expansion@^2.0.1:
balanced-match "^1.0.0"

braces@^3.0.2, braces@~3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
version "3.0.3"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
dependencies:
fill-range "^7.0.1"
fill-range "^7.1.1"

broadcast-channel@^3.4.1:
version "3.7.0"
Expand Down Expand Up @@ -7665,10 +7665,10 @@ filelist@^1.0.4:
dependencies:
minimatch "^5.0.1"

fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==
fill-range@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292"
integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==
dependencies:
to-regex-range "^5.0.1"

Expand Down

0 comments on commit e511717

Please sign in to comment.