Skip to content

Commit

Permalink
feat: Hl 1575 instalment to accepted (#3642)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke authored Dec 10, 2024
1 parent 3889847 commit 9981a73
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 76 deletions.
1 change: 1 addition & 0 deletions backend/benefit/calculator/api/v1/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class InstalmentStatusValidator(StatusTransitionValidator):
),
InstalmentStatus.ERROR_IN_TALPA: (
InstalmentStatus.WAITING,
InstalmentStatus.ACCEPTED,
InstalmentStatus.PAID,
),
InstalmentStatus.PAID: (InstalmentStatus.COMPLETED,),
Expand Down
8 changes: 6 additions & 2 deletions frontend/benefit/handler/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@
"accepted": "Hyväksytty",
"waiting": "Odottaa",
"completed": "Maksettu",
"error_in_talpa": "Virhe maksussa"
"error_in_talpa": "Virhe maksussa",
"paid": "Merkitty maksetuksi manuaalisesti"
},
"calculationEndDate": "Viim. tukipäivä",
"calculatedBenefitAmount": "Tukisumma",
Expand Down Expand Up @@ -282,7 +283,10 @@
"return": "Palauta",
"confirm": "Hyväksy",
"cancel": "Peru",
"finish": "Siirrä arkistoon"
"finish": "Siirrä arkistoon",
"return_as_waiting": "Palauta odottamaan",
"return_as_accepted": "Palauta hyväksytyksi",
"mark_as_paid": "Merkitse maksetuksi"
}
},
"pageHeaders": {
Expand Down
8 changes: 6 additions & 2 deletions frontend/benefit/handler/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@
"accepted": "Hyväksytty",
"waiting": "Odottaa",
"completed": "Maksettu",
"error_in_talpa": "Virhe maksussa"
"error_in_talpa": "Virhe maksussa",
"paid": "Merkitty maksetuksi manuaalisesti"
},
"calculationEndDate": "Viim. tukipäivä",
"calculatedBenefitAmount": "Tukisumma",
Expand Down Expand Up @@ -282,7 +283,10 @@
"return": "Palauta",
"confirm": "Hyväksy",
"cancel": "Peru",
"finish": "Siirrä arkistoon"
"finish": "Siirrä arkistoon",
"return_as_waiting": "Palauta odottamaan",
"return_as_accepted": "Palauta hyväksytyksi",
"mark_as_paid": "Merkitse maksetuksi"
}
},
"pageHeaders": {
Expand Down
8 changes: 6 additions & 2 deletions frontend/benefit/handler/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@
"accepted": "Hyväksytty",
"waiting": "Odottaa",
"completed": "Maksettu",
"error_in_talpa": "Virhe maksussa"
"error_in_talpa": "Virhe maksussa",
"paid": "Merkitty maksetuksi manuaalisesti"
},
"calculationEndDate": "Viim. tukipäivä",
"calculatedBenefitAmount": "Tukisumma",
Expand Down Expand Up @@ -282,7 +283,10 @@
"return": "Palauta",
"confirm": "Hyväksy",
"cancel": "Peru",
"finish": "Siirrä arkistoon"
"finish": "Siirrä arkistoon",
"return_as_waiting": "Palauta odottamaan",
"return_as_accepted": "Palauta hyväksytyksi",
"mark_as_paid": "Merkitse maksetuksi"
}
},
"pageHeaders": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import {
} from 'benefit-shared/constants';
import { ApplicationListItemData } from 'benefit-shared/types/application';
import {
Button,
IconArrowUndo,
IconCheck,
IconCross,
IconErrorFill,
Table,
Tag,
Expand All @@ -38,14 +34,14 @@ import {
$Column,
$Wrapper,
} from '../applicationReview/actions/handlingApplicationActions/HandlingApplicationActions.sc';
import { $HintText, $TableFooter } from '../table/TableExtras.sc';
import {
$AlterationBadge,
$EmptyHeading,
$Heading,
$InstalmentList,
$TagWrapper,
} from './ApplicationList.sc';
import ApplicationTableFooter from './ApplicationTableFooter';
import { useApplicationList } from './useApplicationList';

export interface ApplicationListProps {
Expand Down Expand Up @@ -241,71 +237,17 @@ const ApplicationListForInstalments: React.FC<ApplicationListProps> = ({
setSelectedRows={setSelectedRows}
zebra
/>
<$TableFooter>
<$Wrapper>
<$Column>
{(selectedRows.length === 0 || selectedRows.length > 1) && (
<$HintText>Valitse yksi hakemus</$HintText>
)}

{selectedApplication &&
selectedRows.length === 1 &&
selectedInstalment && (
<>
{selectedInstalment.status ===
INSTALMENT_STATUSES.WAITING && (
<Button
disabled={isLoading || isLoadingStatusChange}
theme="coat"
iconLeft={<IconCheck />}
onClick={() =>
changeInstalmentStatus({
id: selectedInstalment.id,
status: INSTALMENT_STATUSES.ACCEPTED,
})
}
>
{t(`${translationsBase}.actions.confirm`)}
</Button>
)}

{selectedInstalment.status ===
INSTALMENT_STATUSES.WAITING && (
<Button
disabled={isLoading || isLoadingStatusChange}
theme="coat"
iconLeft={<IconCross />}
onClick={() => setIsInstalmentCancelModalShown(true)}
>
{t(`${translationsBase}.actions.cancel`)}
</Button>
)}

{[
INSTALMENT_STATUSES.ACCEPTED,
INSTALMENT_STATUSES.CANCELLED,
].includes(
selectedInstalment?.status as INSTALMENT_STATUSES
) && (
<Button
disabled={isLoading || isLoadingStatusChange}
theme="coat"
iconLeft={<IconArrowUndo />}
onClick={() =>
changeInstalmentStatus({
id: selectedInstalment.id,
status: INSTALMENT_STATUSES.WAITING,
})
}
>
{t(`${translationsBase}.actions.return`)}
</Button>
)}
</>
)}
</$Column>
</$Wrapper>
</$TableFooter>
{selectedRows.length > 0 && (
<ApplicationTableFooter
selectedRows={selectedRows}
list={list}
isLoading={isLoading}
isLoadingStatusChange={isLoadingStatusChange}
translationsBase={translationsBase}
changeInstalmentStatus={changeInstalmentStatus}
setIsInstalmentCancelModalShown={setIsInstalmentCancelModalShown}
/>
)}
<Modal
id="instalment-cancel-confirm"
isOpen={isInstalmentCancelModalShown}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { INSTALMENT_STATUSES } from 'benefit-shared/constants';
import { ApplicationListItemData } from 'benefit-shared/types/application';
import { useTranslation } from 'next-i18next';
import React from 'react';

import {
$Column,
$Wrapper,
} from '../applicationReview/actions/handlingApplicationActions/HandlingApplicationActions.sc';
import { $HintText, $TableFooter } from '../table/TableExtras.sc';
import InstalmentButton from "./InstalmentButton";

interface TableFooterProps {
selectedRows: string[];
list: ApplicationListItemData[];
isLoading: boolean;
isLoadingStatusChange: boolean;
translationsBase: string;
changeInstalmentStatus: (params: {
id?: string;
status: INSTALMENT_STATUSES
}) => void;
setIsInstalmentCancelModalShown: (show: boolean) => void;
}

const ApplicationTableFooter: React.FC<TableFooterProps> = ({
selectedRows,
list,
isLoading,
isLoadingStatusChange,
translationsBase,
changeInstalmentStatus,
setIsInstalmentCancelModalShown
}) => {
const { t } = useTranslation();


const selectedApplication = list.find((app) => app.id === selectedRows[0]);
const selectedInstalment =
list.find(
(app: ApplicationListItemData) =>
app.id === String(selectedApplication?.id)
)?.pendingInstalment || null;

const handleStatusChange = (status: INSTALMENT_STATUSES): void => {
changeInstalmentStatus({
id: selectedInstalment.id,
status,
});
};

// If no rows or multiple rows selected, show hint
if (selectedRows.length !== 1) {
return (
<$TableFooter>
<$Wrapper>
<$Column>
<$HintText>Valitse yksi hakemus</$HintText>
</$Column>
</$Wrapper>
</$TableFooter>
);
}

// If no selected application or instalment, return null
if (!selectedApplication || !selectedInstalment) {
return null;
}

return (
<$TableFooter>
<$Wrapper>
<$Column>
{/* Waiting Status Buttons */}
{selectedInstalment.status === INSTALMENT_STATUSES.WAITING && (
<>
<InstalmentButton
isLoading={isLoading}
isLoadingStatusChange={isLoadingStatusChange}
onClick={() => handleStatusChange(INSTALMENT_STATUSES.ACCEPTED)}
>
{t(`${translationsBase}.actions.confirm`)}
</InstalmentButton>
<InstalmentButton
isLoading={isLoading}
isLoadingStatusChange={isLoadingStatusChange}
onClick={() => setIsInstalmentCancelModalShown(true)}
>
{t(`${translationsBase}.actions.cancel`)}
</InstalmentButton>
</>
)}

{/* Error in Talpa Buttons */}
{selectedInstalment.status === INSTALMENT_STATUSES.ERROR_IN_TALPA && (
<>
<InstalmentButton
isLoading={isLoading}
isLoadingStatusChange={isLoadingStatusChange}
onClick={() => handleStatusChange(INSTALMENT_STATUSES.ACCEPTED)}
>
{t(`${translationsBase}.actions.return_as_accepted`)}
</InstalmentButton>
<InstalmentButton
isLoading={isLoading}
isLoadingStatusChange={isLoadingStatusChange}
onClick={() => handleStatusChange(INSTALMENT_STATUSES.PAID)}
>
{t(`${translationsBase}.actions.mark_as_paid`)}
</InstalmentButton>
</>
)}

{/* Return Button for Accepted/Cancelled Statuses */}
{[
INSTALMENT_STATUSES.ACCEPTED,
INSTALMENT_STATUSES.CANCELLED,
].includes(selectedInstalment?.status as INSTALMENT_STATUSES) && (
<InstalmentButton
isLoading={isLoading}
isLoadingStatusChange={isLoadingStatusChange}
onClick={() => handleStatusChange(INSTALMENT_STATUSES.WAITING)}
>
{t(`${translationsBase}.actions.return`)}
</InstalmentButton>
)}
</$Column>
</$Wrapper>
</$TableFooter>
);
};

export default ApplicationTableFooter;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
Button,
IconCheck,
} from 'hds-react';
import React from "react";


interface InstalmentButtonProps {
isLoading: boolean;
isLoadingStatusChange: boolean;
onClick: () => void;
children: React.ReactNode;
}

const InstalmentButton: React.FC<InstalmentButtonProps> = ({
isLoading,
isLoadingStatusChange,
onClick,
children
}) => (
<Button
disabled={isLoading || isLoadingStatusChange}
theme="coat"
iconLeft={<IconCheck />}
onClick={onClick}
>
{children}
</Button>
);

export default InstalmentButton;

0 comments on commit 9981a73

Please sign in to comment.