Skip to content

Commit

Permalink
fix: repair some app crashing bugs when drafting the decision proposa…
Browse files Browse the repository at this point in the history
…l (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
  • Loading branch information
sirtawast authored Oct 30, 2024
1 parent bd48949 commit 4cb17ac
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]

Expand All @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const CalculationReview: React.FC<ApplicationReviewStepProps> = ({
calculation,
});

if (!decisionProposalDraft) return null;

return (
<>
<$GridCell $colSpan={12}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
? [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -36,7 +36,7 @@ const ApplicationReviewStep2: React.FC<HandlingStepProps> = ({
application,
}) => {
const { applicantLanguage, id } = application;

const { t } = useTranslation();
const translationBase = 'common:review.decisionProposal';
const { handledApplication, setHandledApplication } =
Expand All @@ -46,7 +46,7 @@ const ApplicationReviewStep2: React.FC<HandlingStepProps> = ({
React.useState<string>(handledApplication?.justificationText || '');
const [templateForDecisionText, setTemplateForDecisionText] =
React.useState<string>(handledApplication?.decisionText || '');

const [selectedDecisionMaker, setSelectedDecisionMaker] =
React.useState<DecisionMaker | null>(null);

Expand All @@ -55,7 +55,10 @@ const ApplicationReviewStep2: React.FC<HandlingStepProps> = ({
? 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 => {
Expand Down Expand Up @@ -89,6 +92,14 @@ const ApplicationReviewStep2: React.FC<HandlingStepProps> = ({
});
};

if (isLoading) {
return (
<Container>
<LoadingSpinner />
</Container>
);
}

if (!sections || sections?.length === 0) {
const language =
applicantLanguage === 'en' ? 'fi' : (applicantLanguage as 'fi' | 'sv');
Expand Down Expand Up @@ -119,7 +130,7 @@ const ApplicationReviewStep2: React.FC<HandlingStepProps> = ({
/>
</$GridCell>
<$GridCell $colSpan={12}>
<SelectionGroup
<SelectionGroup
label={t(`${translationBase}.role.fields.decisionMaker.label`)}
tooltipText={t(
`${translationBase}.role.fields.decisionMaker.tooltipText`
Expand Down

0 comments on commit 4cb17ac

Please sign in to comment.