diff --git a/backend/benefit/calculator/api/v1/validators.py b/backend/benefit/calculator/api/v1/validators.py index a718845ad7..a37afb0466 100644 --- a/backend/benefit/calculator/api/v1/validators.py +++ b/backend/benefit/calculator/api/v1/validators.py @@ -16,6 +16,7 @@ class InstalmentStatusValidator(StatusTransitionValidator): ), InstalmentStatus.ERROR_IN_TALPA: ( InstalmentStatus.WAITING, + InstalmentStatus.ACCEPTED, InstalmentStatus.PAID, ), InstalmentStatus.PAID: (InstalmentStatus.COMPLETED,), diff --git a/frontend/benefit/handler/public/locales/en/common.json b/frontend/benefit/handler/public/locales/en/common.json index ed6f0b3bed..f4288210a0 100644 --- a/frontend/benefit/handler/public/locales/en/common.json +++ b/frontend/benefit/handler/public/locales/en/common.json @@ -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", @@ -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": { diff --git a/frontend/benefit/handler/public/locales/fi/common.json b/frontend/benefit/handler/public/locales/fi/common.json index 9214495f26..fe2a350705 100644 --- a/frontend/benefit/handler/public/locales/fi/common.json +++ b/frontend/benefit/handler/public/locales/fi/common.json @@ -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", @@ -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": { diff --git a/frontend/benefit/handler/public/locales/sv/common.json b/frontend/benefit/handler/public/locales/sv/common.json index 4f5c08c423..2f9a0d2c2c 100644 --- a/frontend/benefit/handler/public/locales/sv/common.json +++ b/frontend/benefit/handler/public/locales/sv/common.json @@ -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", @@ -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": { diff --git a/frontend/benefit/handler/src/components/applicationList/ApplicationListForInstalments.tsx b/frontend/benefit/handler/src/components/applicationList/ApplicationListForInstalments.tsx index f33f1bca2b..5772eb2a0f 100644 --- a/frontend/benefit/handler/src/components/applicationList/ApplicationListForInstalments.tsx +++ b/frontend/benefit/handler/src/components/applicationList/ApplicationListForInstalments.tsx @@ -12,10 +12,6 @@ import { } from 'benefit-shared/constants'; import { ApplicationListItemData } from 'benefit-shared/types/application'; import { - Button, - IconArrowUndo, - IconCheck, - IconCross, IconErrorFill, Table, Tag, @@ -38,7 +34,6 @@ import { $Column, $Wrapper, } from '../applicationReview/actions/handlingApplicationActions/HandlingApplicationActions.sc'; -import { $HintText, $TableFooter } from '../table/TableExtras.sc'; import { $AlterationBadge, $EmptyHeading, @@ -46,6 +41,7 @@ import { $InstalmentList, $TagWrapper, } from './ApplicationList.sc'; +import ApplicationTableFooter from './ApplicationTableFooter'; import { useApplicationList } from './useApplicationList'; export interface ApplicationListProps { @@ -241,71 +237,17 @@ const ApplicationListForInstalments: React.FC = ({ setSelectedRows={setSelectedRows} zebra /> - <$TableFooter> - <$Wrapper> - <$Column> - {(selectedRows.length === 0 || selectedRows.length > 1) && ( - <$HintText>Valitse yksi hakemus - )} - - {selectedApplication && - selectedRows.length === 1 && - selectedInstalment && ( - <> - {selectedInstalment.status === - INSTALMENT_STATUSES.WAITING && ( - - )} - - {selectedInstalment.status === - INSTALMENT_STATUSES.WAITING && ( - - )} - - {[ - INSTALMENT_STATUSES.ACCEPTED, - INSTALMENT_STATUSES.CANCELLED, - ].includes( - selectedInstalment?.status as INSTALMENT_STATUSES - ) && ( - - )} - - )} - - - + {selectedRows.length > 0 && ( + + )} void; + setIsInstalmentCancelModalShown: (show: boolean) => void; +} + +const ApplicationTableFooter: React.FC = ({ + 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 + + + + ); + } + + // 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 && ( + <> + handleStatusChange(INSTALMENT_STATUSES.ACCEPTED)} + > + {t(`${translationsBase}.actions.confirm`)} + + setIsInstalmentCancelModalShown(true)} + > + {t(`${translationsBase}.actions.cancel`)} + + + )} + + {/* Error in Talpa Buttons */} + {selectedInstalment.status === INSTALMENT_STATUSES.ERROR_IN_TALPA && ( + <> + handleStatusChange(INSTALMENT_STATUSES.ACCEPTED)} + > + {t(`${translationsBase}.actions.return_as_accepted`)} + + handleStatusChange(INSTALMENT_STATUSES.PAID)} + > + {t(`${translationsBase}.actions.mark_as_paid`)} + + + )} + + {/* Return Button for Accepted/Cancelled Statuses */} + {[ + INSTALMENT_STATUSES.ACCEPTED, + INSTALMENT_STATUSES.CANCELLED, + ].includes(selectedInstalment?.status as INSTALMENT_STATUSES) && ( + handleStatusChange(INSTALMENT_STATUSES.WAITING)} + > + {t(`${translationsBase}.actions.return`)} + + )} + + + + ); +}; + +export default ApplicationTableFooter; \ No newline at end of file diff --git a/frontend/benefit/handler/src/components/applicationList/InstalmentButton.tsx b/frontend/benefit/handler/src/components/applicationList/InstalmentButton.tsx new file mode 100644 index 0000000000..64a3d8b95a --- /dev/null +++ b/frontend/benefit/handler/src/components/applicationList/InstalmentButton.tsx @@ -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 = ({ + isLoading, + isLoadingStatusChange, + onClick, + children +}) => ( + + ); + +export default InstalmentButton; \ No newline at end of file