Skip to content

Commit

Permalink
chore: revisit logic on how and when to show alteration summary (hl-1…
Browse files Browse the repository at this point in the history
…472) (#3335)

* chore: add missing field values to fixtures

* chore: remove env flag to display alterations

* refactor: change has_batch to batch_status for applicant

* chore: add typing for handledByAhjoAutomation for applicant

* chore: refactor and change logic on when alteration summary is shown
  • Loading branch information
sirtawast authored Sep 26, 2024
1 parent 508b66c commit f494c05
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 65 deletions.
1 change: 0 additions & 1 deletion .env.benefit-applicant.example
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ NEXTJS_SENTRY_DEBUG=true
NEXTJS_SENTRY_TRACING=true
NEXT_PUBLIC_SENTRY_ATTACH_STACKTRACE=
NEXT_PUBLIC_SENTRY_MAX_BREADCRUMBS=
NEXT_PUBLIC_ENABLE_ALTERATION_FEATURES=

NEXT_PUBLIC_ASKEM_API_KEY=
NEXT_PUBLIC_SHOW_COOKIE_BANNER=0
1 change: 0 additions & 1 deletion .env.benefit-handler.example
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ NEXTJS_SENTRY_DEBUG=true
NEXTJS_SENTRY_TRACING=true
NEXT_PUBLIC_SENTRY_ATTACH_STACKTRACE=
NEXT_PUBLIC_SENTRY_MAX_BREADCRUMBS=
NEXT_PUBLIC_ENABLE_ALTERATION_FEATURES=
Original file line number Diff line number Diff line change
Expand Up @@ -1511,10 +1511,10 @@ class ApplicantApplicationSerializer(BaseApplicationSerializer):
),
)

has_batch = serializers.SerializerMethodField()
batch_status = serializers.SerializerMethodField()

def get_has_batch(self, obj):
return obj.batch is not None
def get_batch_status(self, obj):
return getattr(obj.batch, "status", False) if obj.batch else False

changes = serializers.SerializerMethodField(
help_text=("Possible changes made by handler to the application."),
Expand Down Expand Up @@ -1553,7 +1553,7 @@ def update(self, instance, validated_data):
class Meta(BaseApplicationSerializer.Meta):
fields = BaseApplicationSerializer.Meta.fields + [
"batch",
"has_batch",
"batch_status",
"handled_by_ahjo_automation",
]

Expand Down
5 changes: 3 additions & 2 deletions backend/benefit/applications/fixtures/test_applications.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
"paper_application_date": null,
"de_minimis_aid": false,
"batch": null,
"ahjo_case_id": null,
"ahjo_case_guid": null,
"ahjo_case_id": "HEL 2024-123",
"ahjo_case_guid": "ad2b11c6-4223-4af4-99ca-5b9208c5251f",
"handled_by_ahjo_automation": true,
"bases": []
}
Expand Down Expand Up @@ -447,6 +447,7 @@
"de_minimis_aid": true,
"batch": "18938478-5bf9-4192-888d-804af997f76d",
"ahjo_case_id": "HEL 2024-999992",
"handled_by_ahjo_automation": true,
"ahjo_case_guid": "dbb01a61-2937-4613-9052-e1c2ecae183f",
"handler": "47ecedfa-351b-4815-bfac-96bdbc640178",
"bases": []
Expand Down
6 changes: 3 additions & 3 deletions backend/benefit/applications/tests/test_applications_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def test_application_single_read_without_ahjo_decision_as_applicant(
assert response.data["ahjo_decision"] is None
assert response.data["application_number"] is not None
assert response.data["status"] == visible_status
assert response.data["has_batch"] is False
assert response.data["batch_status"] is False
assert Decimal(response.data["duration_in_months_rounded"]) == duration_in_months(
application.start_date, application.end_date, decimal_places=2
)
Expand All @@ -385,7 +385,7 @@ def test_application_single_read_without_ahjo_decision_as_applicant(
response = api_client.get(get_detail_url(application))

assert response.status_code == 200
assert response.data["has_batch"] is True
assert response.data["batch_status"] in ApplicationBatchStatus.values
assert isinstance(response.data["batch"], uuid.UUID)


Expand All @@ -409,7 +409,7 @@ def test_application_single_read_with_ahjo_decision_as_applicant(
assert response.data["ahjo_decision"] is not None
assert response.data["application_number"] is not None
assert response.data["status"] == visible_status
assert response.data["has_batch"] is True
assert response.data["batch_status"] in ApplicationBatchStatus.values

assert isinstance(response.data["batch"], uuid.UUID)
assert Decimal(response.data["duration_in_months_rounded"]) == duration_in_months(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
ALTERATION_TYPE,
APPLICATION_STATUSES,
} from 'benefit-shared/constants';
import { isTruthy } from 'benefit-shared/utils/common';
import { Button, IconArrowLeft, LoadingSpinner } from 'hds-react';
import { useRouter } from 'next/router';
import React from 'react';
Expand Down Expand Up @@ -49,11 +48,7 @@ const AlterationPage = (): JSX.Element => {
);
}

if (
!isTruthy(process.env.NEXT_PUBLIC_ENABLE_ALTERATION_FEATURES) ||
isError ||
!id
) {
if (isError || !id) {
return (
<ErrorPage
title={t('common:errorPage.title')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import ApplicationFormStep5 from 'benefit/applicant/components/applications/form
import ApplicationFormStep6 from 'benefit/applicant/components/applications/forms/application/step6/ApplicationFormStep6';
import NoCookieConsentsNotification from 'benefit/applicant/components/cookieConsent/NoCookieConsentsNotification';
import { $Hr } from 'benefit/applicant/components/pages/Pages.sc';
import { ROUTES, SUBMITTED_STATUSES } from 'benefit/applicant/constants';
import {
ROUTES,
SUBMITTED_STATUSES,
SUPPORTED_LANGUAGES,
} 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';
Expand All @@ -26,6 +30,7 @@ import {
ALTERATION_STATE,
ALTERATION_TYPE,
APPLICATION_STATUSES,
BATCH_STATUSES,
} from 'benefit-shared/constants';
import { DecisionDetailList } from 'benefit-shared/types/application';
import { Button, IconInfoCircleFill, LoadingSpinner, Stepper } from 'hds-react';
Expand Down Expand Up @@ -159,7 +164,7 @@ const PageContent: React.FC = () => {
),
})}
/>
{router.locale === 'fi' && (
{router.locale === SUPPORTED_LANGUAGES.FI && (
<Container>
<$Hr />
{canShowAskem ? (
Expand Down Expand Up @@ -193,6 +198,17 @@ const PageContent: React.FC = () => {
alteration.alterationType === ALTERATION_TYPE.TERMINATION
);

const passesAhjoDecisionMaking =
application?.handledByAhjoAutomation &&
application?.ahjoCaseId &&
application?.ahjoStatus === AHJO_STATUSES.DETAILS_RECEIVED;

const passesManualDecisionMaking =
!application?.handledByAhjoAutomation &&
[BATCH_STATUSES.SENT_TO_TALPA, BATCH_STATUSES.COMPLETED].includes(
application?.batchStatus
);

return (
<Container>
<$PageHeader>
Expand Down Expand Up @@ -226,7 +242,7 @@ const PageContent: React.FC = () => {
</$HeaderRightColumnItem>
)}
</$PageHeader>
{application.ahjoStatus === AHJO_STATUSES.DETAILS_RECEIVED && (
{(passesAhjoDecisionMaking || passesManualDecisionMaking) && (
<DecisionSummary
application={application}
actions={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ const usePageContent = (): ExtendedComponentProps => {
}, [existingApplicationStatus, id, existingApplication]);

useEffect(() => {
if (id && !isLoading && !isApplicationLoaded(id, existingApplicationStatus)) {
if (
id &&
!isLoading &&
!isApplicationLoaded(id, existingApplicationStatus)
) {
setIsLoading(true);
}
}, [existingApplicationStatus, id, isLoading]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ROUTES, SUBMITTED_STATUSES } from 'benefit/applicant/constants';
import ApplicationListContext from 'benefit/applicant/context/ApplicationListContext';
import { Trans, useTranslation } from 'benefit/applicant/i18n';
import { APPLICATION_STATUSES } from 'benefit-shared/constants';
import { isTruthy } from 'benefit-shared/utils/common';
import { Button, IconArrowLeft, Notification } from 'hds-react';
import { useRouter } from 'next/router';
import React from 'react';
Expand Down Expand Up @@ -46,10 +45,6 @@ const DecisionsApplicationList = (): JSX.Element => {
beforeList={
<ApplicationListContext.Consumer>
{({ list }) => {
if (!isTruthy(process.env.NEXT_PUBLIC_ENABLE_ALTERATION_FEATURES)) {
return null;
}

if (
!list.some(
(item) => item.status === APPLICATION_STATUSES.ACCEPTED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ALTERATION_STATE,
APPLICATION_STATUSES,
} from 'benefit-shared/constants';
import { isTruthy } from 'benefit-shared/utils/common';
import { Button } from 'hds-react';
import { useRouter } from 'next/router';
import React from 'react';
Expand All @@ -23,11 +22,7 @@ const NewAlteration: React.FC = () => {
return <PageLoadingSpinner />;
}

if (
!isTruthy(process.env.NEXT_PUBLIC_ENABLE_ALTERATION_FEATURES) ||
isError ||
!id
) {
if (isError || !id) {
return (
<ErrorPage
title={t('common:errorPage.title')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
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';
Expand All @@ -38,16 +37,20 @@ const DecisionSummary = ({
}: Props): JSX.Element => {
const { t } = useTranslation();

const isAccepted = ![
const isNotRejected = ![
APPLICATION_STATUSES.REJECTED,
APPLICATION_STATUSES.CANCELLED,
].includes(application.status);

if (!application.ahjoCaseId && isAccepted) {
if (
isNotRejected &&
application?.handledByAhjoAutomation &&
!application?.ahjoCaseId
) {
return null;
}

const displayDecision = (): void => {
const openDecisionLink = (): void => {
const id = application.ahjoCaseId.split(' ').join('-');

// eslint-disable-next-line security/detect-non-literal-fs-filename
Expand All @@ -63,7 +66,7 @@ const DecisionSummary = ({
<$DecisionBoxTitle>
{t('common:applications.decision.headings.mainHeading')}
</$DecisionBoxTitle>
{isAccepted && (
{isNotRejected && application.handledByAhjoAutomation && (
<$DecisionNumber>
{t('common:applications.decision.headings.caseId')}
{': '}
Expand Down Expand Up @@ -97,11 +100,11 @@ const DecisionSummary = ({
})}
</$DecisionDetails>
{extraInformation}
{isAccepted && (
{isNotRejected && application.handledByAhjoAutomation && (
<$DecisionActionContainer>
<Button
iconRight={<IconLinkExternal />}
onClick={displayDecision}
onClick={openDecisionLink}
theme="black"
variant="secondary"
role="link"
Expand All @@ -110,31 +113,30 @@ const DecisionSummary = ({
</Button>
</$DecisionActionContainer>
)}
{isTruthy(process.env.NEXT_PUBLIC_ENABLE_ALTERATION_FEATURES) &&
isAccepted && (
<>
<$Subheading>
{t('common:applications.decision.headings.existingAlterations')}
</$Subheading>
<$AlterationListCount>
{application.alterations?.length > 0
? t('common:applications.decision.alterationList.count', {
count: application.alterations.length,
})
: t('common:applications.decision.alterationList.empty')}
</$AlterationListCount>
<div data-testid="alteration-list">
{sortedAlterations.map((alteration) => (
<ItemComponent
key={alteration.id}
alteration={alteration}
application={application}
/>
))}
</div>
<$AlterationActionContainer>{actions}</$AlterationActionContainer>
</>
)}
{isNotRejected && (
<>
<$Subheading>
{t('common:applications.decision.headings.existingAlterations')}
</$Subheading>
<$AlterationListCount>
{application.alterations?.length > 0
? t('common:applications.decision.alterationList.count', {
count: application.alterations.length,
})
: t('common:applications.decision.alterationList.empty')}
</$AlterationListCount>
<div data-testid="alteration-list">
{sortedAlterations.map((alteration) => (
<ItemComponent
key={alteration.id}
alteration={alteration}
application={application}
/>
))}
</div>
<$AlterationActionContainer>{actions}</$AlterationActionContainer>
</>
)}
</$DecisionBox>
);
};
Expand Down
4 changes: 3 additions & 1 deletion frontend/benefit/shared/src/types/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ export type Application = {
applicationOrigin?: APPLICATION_ORIGINS;
handler?: User;
ahjoStatus?: string;
handledByAhjoAutomation?: boolean;
batchStatus?: BATCH_STATUSES;
} & Step1 &
Step2;

Expand Down Expand Up @@ -474,7 +476,7 @@ export type ApplicationData = {
training_compensations: TrainingCompensationData[];
handled_at?: string;
batch?: BatchData;
has_batch?: boolean;
batch_status?: BATCH_STATUSES;
latest_decision_comment?: string;
unread_messages_count?: number;
application_origin?: APPLICATION_ORIGINS;
Expand Down

0 comments on commit f494c05

Please sign in to comment.