From 4cb17ac7fadedbdd308e41eae44cfe390f400a98 Mon Sep 17 00:00:00 2001 From: Sampo Tawast <5328394+sirtawast@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:23:44 +0200 Subject: [PATCH] fix: repair some app crashing bugs when drafting the decision proposal (hl-1522) (#3478) * fix: crash when benefit is rejected * fix: crash when decision proposal was not created/fetched yet * feat: add a loading spinner when fetching decision templates * test: use single test url --- .../tests/test_application_batch_api.py | 7 +++---- .../applicationReview/CalculationReview.tsx | 2 ++ .../calculationTable/useCalculationTable.ts | 11 ++++++---- .../handlingView/HandlingStep2.tsx | 21 ++++++++++++++----- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/backend/benefit/applications/tests/test_application_batch_api.py b/backend/benefit/applications/tests/test_application_batch_api.py index 02cedf122f..7fdd5700ab 100755 --- a/backend/benefit/applications/tests/test_application_batch_api.py +++ b/backend/benefit/applications/tests/test_application_batch_api.py @@ -825,7 +825,8 @@ def test_application_batch_export(mock_export, handler_api_client, application_b def test_application_batches_talpa_export(anonymous_client, application_batch): - response = anonymous_client.get(reverse("v1:applicationbatch-talpa-export-batch")) + url = reverse("v1:applicationbatch-talpa-export-batch") + response = anonymous_client.get(url) assert response.status_code == 401 # Add basic auth header @@ -837,7 +838,7 @@ def test_application_batches_talpa_export(anonymous_client, application_batch): # Export invalid batch application_batch.status = ApplicationBatchStatus.DECIDED_REJECTED fill_as_valid_batch_completion_and_save(application_batch) - response = anonymous_client.get(reverse("v1:applicationbatch-talpa-export-batch")) + response = anonymous_client.get(url) assert response.status_code == 404 assert "There is no available application to export" in response.data["detail"] @@ -849,8 +850,6 @@ def test_application_batches_talpa_export(anonymous_client, application_batch): app_batch_2.status = ApplicationBatchStatus.DECIDED_ACCEPTED fill_as_valid_batch_completion_and_save(app_batch_2) - url = reverse("v1:applicationbatch-talpa-export-batch") - # Export accepted batches then change it status response = anonymous_client.get(f"{url}?skip_update=0") diff --git a/frontend/benefit/handler/src/components/applicationReview/CalculationReview.tsx b/frontend/benefit/handler/src/components/applicationReview/CalculationReview.tsx index 06e3df1ba7..12f9e5f857 100644 --- a/frontend/benefit/handler/src/components/applicationReview/CalculationReview.tsx +++ b/frontend/benefit/handler/src/components/applicationReview/CalculationReview.tsx @@ -28,6 +28,8 @@ const CalculationReview: React.FC = ({ calculation, }); + if (!decisionProposalDraft) return null; + return ( <> <$GridCell $colSpan={12}> diff --git a/frontend/benefit/handler/src/components/applicationReview/calculationTable/useCalculationTable.ts b/frontend/benefit/handler/src/components/applicationReview/calculationTable/useCalculationTable.ts index c916ea8183..af75a0cd38 100644 --- a/frontend/benefit/handler/src/components/applicationReview/calculationTable/useCalculationTable.ts +++ b/frontend/benefit/handler/src/components/applicationReview/calculationTable/useCalculationTable.ts @@ -72,10 +72,13 @@ const useCalculationTable = ({ calculation }: Props): CalculationTableProps => { ) ); - const duration = diffMonths( - new Date(calculation.rows.at(0).endDate), - new Date(calculation.rows.at(0).startDate) - ); + const duration = + calculation?.rows?.length > 0 + ? diffMonths( + new Date(calculation.rows.at(0).endDate), + new Date(calculation.rows.at(0).startDate) + ) + : 0; const tableRows: BenefitRow[] = calculation.overrideMonthlyBenefitAmount ? [ diff --git a/frontend/benefit/handler/src/components/applicationReview/handlingView/HandlingStep2.tsx b/frontend/benefit/handler/src/components/applicationReview/handlingView/HandlingStep2.tsx index bb12eed220..aadad7f35d 100644 --- a/frontend/benefit/handler/src/components/applicationReview/handlingView/HandlingStep2.tsx +++ b/frontend/benefit/handler/src/components/applicationReview/handlingView/HandlingStep2.tsx @@ -3,7 +3,7 @@ import useAhjoSettingsQuery from 'benefit/handler/hooks/useAhjoSettingsQuery'; import { DecisionProposalTemplateData } from 'benefit/handler/types/common'; import { DECISION_TYPES } from 'benefit-shared/constants'; import { Application, DecisionMaker } from 'benefit-shared/types/application'; -import { Select, SelectionGroup } from 'hds-react'; +import { LoadingSpinner, Select, SelectionGroup } from 'hds-react'; import { useTranslation } from 'next-i18next'; import * as React from 'react'; import Container from 'shared/components/container/Container'; @@ -36,7 +36,7 @@ const ApplicationReviewStep2: React.FC = ({ application, }) => { const { applicantLanguage, id } = application; - + const { t } = useTranslation(); const translationBase = 'common:review.decisionProposal'; const { handledApplication, setHandledApplication } = @@ -46,7 +46,7 @@ const ApplicationReviewStep2: React.FC = ({ React.useState(handledApplication?.justificationText || ''); const [templateForDecisionText, setTemplateForDecisionText] = React.useState(handledApplication?.decisionText || ''); - + const [selectedDecisionMaker, setSelectedDecisionMaker] = React.useState(null); @@ -55,7 +55,10 @@ const ApplicationReviewStep2: React.FC = ({ ? DECISION_TYPES.ACCEPTED : DECISION_TYPES.DENIED; - const { data: sections } = useDecisionProposalTemplateQuery(id, decisionType); + const { data: sections, isLoading } = useDecisionProposalTemplateQuery( + id, + decisionType + ); const { data: decisionMakerOptions } = useAhjoSettingsQuery(); const selectTemplate = (option: DecisionProposalTemplateData): void => { @@ -89,6 +92,14 @@ const ApplicationReviewStep2: React.FC = ({ }); }; + if (isLoading) { + return ( + + + + ); + } + if (!sections || sections?.length === 0) { const language = applicantLanguage === 'en' ? 'fi' : (applicantLanguage as 'fi' | 'sv'); @@ -119,7 +130,7 @@ const ApplicationReviewStep2: React.FC = ({ /> <$GridCell $colSpan={12}> -