From 8c58eb0a74810f7895fc8ecf4dee31fe40ebc55e Mon Sep 17 00:00:00 2001 From: Sampo Tawast <5328394+sirtawast@users.noreply.github.com> Date: Thu, 4 Jan 2024 13:43:58 +0200 Subject: [PATCH] fix: modify batches to better support TALPA and handler's work (HL-1053) (#2615) * feat: separate inspection and completion phase * feat: reorganize to better support new tab structure * fix: use completed status when rejected applications are sent to archive --- .../api/v1/application_batch_views.py | 11 +- .../tests/test_application_batch_api.py | 2 +- .../handler/public/locales/en/common.json | 9 +- .../handler/public/locales/fi/common.json | 11 +- .../handler/public/locales/sv/common.json | 9 +- .../BatchActionsCompletion.tsx | 202 ------------ .../BatchActionsInspection.tsx | 45 --- .../batchProcessing/BatchApplicationList.tsx | 56 +++- .../batchFooter/BatchFooterCompletion.tsx | 287 ++++++++++++++++++ .../BatchFooterDraft.tsx} | 8 +- .../BatchFooterInspection.tsx} | 42 +-- .../useBatchActionsInspected.ts | 2 +- .../src/components/table/TableExtras.sc.ts | 4 +- .../handler/src/hooks/useBatchInspected.ts | 16 +- .../handler/src/hooks/useBatchStatus.ts | 1 + .../handler/src/pages/batches/index.tsx | 11 +- frontend/benefit/shared/src/constants.ts | 1 + 17 files changed, 403 insertions(+), 314 deletions(-) delete mode 100644 frontend/benefit/handler/src/components/batchProcessing/BatchActionsCompletion.tsx delete mode 100644 frontend/benefit/handler/src/components/batchProcessing/BatchActionsInspection.tsx create mode 100644 frontend/benefit/handler/src/components/batchProcessing/batchFooter/BatchFooterCompletion.tsx rename frontend/benefit/handler/src/components/batchProcessing/{BatchActionsDraft.tsx => batchFooter/BatchFooterDraft.tsx} (96%) rename frontend/benefit/handler/src/components/batchProcessing/{BatchActionsInspectionForm.tsx => batchFooter/BatchFooterInspection.tsx} (91%) diff --git a/backend/benefit/applications/api/v1/application_batch_views.py b/backend/benefit/applications/api/v1/application_batch_views.py index 011ae930fb..813d917aa8 100755 --- a/backend/benefit/applications/api/v1/application_batch_views.py +++ b/backend/benefit/applications/api/v1/application_batch_views.py @@ -310,25 +310,24 @@ def status(self, request, pk=None): ApplicationBatchStatus.DECIDED_ACCEPTED, ApplicationBatchStatus.DECIDED_REJECTED, ApplicationBatchStatus.SENT_TO_TALPA, + ApplicationBatchStatus.COMPLETED, ]: return Response(status=status.HTTP_400_BAD_REQUEST) + # Patch all required fields after batch inspection if new_status in [ ApplicationBatchStatus.DECIDED_ACCEPTED, ApplicationBatchStatus.DECIDED_REJECTED, ]: - # Patch all required fields after batch inspection for key in request.data: setattr(batch, key, request.data.get(key)) + # Archive all applications if this batch will be completed if new_status in [ - ApplicationBatchStatus.SENT_TO_TALPA, - ApplicationBatchStatus.DECIDED_REJECTED, + ApplicationBatchStatus.COMPLETED, ]: - # Archive all applications if this batch will be completed Application.objects.filter(batch=batch).update(archived=True) - previous_status = batch.status batch.status = new_status try: @@ -353,6 +352,8 @@ def status(self, request, pk=None): status=status.HTTP_400_BAD_REQUEST, ) + previous_status = batch.status + return Response( { "id": batch.id, diff --git a/backend/benefit/applications/tests/test_application_batch_api.py b/backend/benefit/applications/tests/test_application_batch_api.py index 6188ecb446..db2b165e6d 100755 --- a/backend/benefit/applications/tests/test_application_batch_api.py +++ b/backend/benefit/applications/tests/test_application_batch_api.py @@ -269,7 +269,7 @@ def test_deassign_applications_from_batch_all(handler_api_client, application_ba @pytest.mark.parametrize( "batch_status,status_code,changed_status", [ - (ApplicationBatchStatus.COMPLETED, 400, None), + (ApplicationBatchStatus.COMPLETED, 200, None), (ApplicationBatchStatus.SENT_TO_TALPA, 200, None), (ApplicationBatchStatus.RETURNED, 400, None), (ApplicationBatchStatus.DECIDED_ACCEPTED, 200, None), diff --git a/frontend/benefit/handler/public/locales/en/common.json b/frontend/benefit/handler/public/locales/en/common.json index 1c7f4d99eb..1013b39956 100644 --- a/frontend/benefit/handler/public/locales/en/common.json +++ b/frontend/benefit/handler/public/locales/en/common.json @@ -1057,7 +1057,8 @@ "multiple": "Koonnit", "tabs": { "pending": "Odottaa Ahjoon vientiä", - "toPaymentAndArchive": "Odottaa maksuun tai arkistoon vientiä" + "inspection": "Odottaa maksuun vientiä", + "completion": "Lähetetty maksuun" }, "list": { "columns": { @@ -1065,7 +1066,9 @@ "status": "Tila", "statuses": { "accepted": "Myönteiset", - "rejected": "Kielteiset" + "rejected": "Kielteiset", + "inPayment": "Maksussa", + "waitingForPayment": "Menossa maksuun" }, "handler": "Käsittelijä" }, @@ -1090,7 +1093,7 @@ "statusChange": { "awaiting_ahjo_decision": "Koonti merkitty Ahjoon viedyksi", "exported_ahjo_report": "Ahjo-valmistelu aloitettu, koonti lukittu", - "sent_to_talpa": "Koonti käsitelty ja arkistoitu", + "completed": "Koonti käsitelty ja arkistoitu", "draft": "Koonti palautettu takaisin odottamaan päätösvalmistelua", "accepted": "Tarkastustiedot tallennettu", "rejected": "Koonti arkistoitu" diff --git a/frontend/benefit/handler/public/locales/fi/common.json b/frontend/benefit/handler/public/locales/fi/common.json index 1c7f4d99eb..17e0034517 100644 --- a/frontend/benefit/handler/public/locales/fi/common.json +++ b/frontend/benefit/handler/public/locales/fi/common.json @@ -1057,15 +1057,18 @@ "multiple": "Koonnit", "tabs": { "pending": "Odottaa Ahjoon vientiä", - "toPaymentAndArchive": "Odottaa maksuun tai arkistoon vientiä" + "inspection": "Odottaa maksuun vientiä", + "completion": "Lähetetty maksuun" }, "list": { "columns": { - "createdAt": "Luotu", + "createdAt": "Luotu ", "status": "Tila", "statuses": { "accepted": "Myönteiset", - "rejected": "Kielteiset" + "rejected": "Kielteiset", + "inPayment": "Maksussa", + "waitingForPayment": "Menossa maksuun" }, "handler": "Käsittelijä" }, @@ -1090,7 +1093,7 @@ "statusChange": { "awaiting_ahjo_decision": "Koonti merkitty Ahjoon viedyksi", "exported_ahjo_report": "Ahjo-valmistelu aloitettu, koonti lukittu", - "sent_to_talpa": "Koonti käsitelty ja arkistoitu", + "completed": "Koonti käsitelty ja arkistoitu", "draft": "Koonti palautettu takaisin odottamaan päätösvalmistelua", "accepted": "Tarkastustiedot tallennettu", "rejected": "Koonti arkistoitu" diff --git a/frontend/benefit/handler/public/locales/sv/common.json b/frontend/benefit/handler/public/locales/sv/common.json index 1c7f4d99eb..1013b39956 100644 --- a/frontend/benefit/handler/public/locales/sv/common.json +++ b/frontend/benefit/handler/public/locales/sv/common.json @@ -1057,7 +1057,8 @@ "multiple": "Koonnit", "tabs": { "pending": "Odottaa Ahjoon vientiä", - "toPaymentAndArchive": "Odottaa maksuun tai arkistoon vientiä" + "inspection": "Odottaa maksuun vientiä", + "completion": "Lähetetty maksuun" }, "list": { "columns": { @@ -1065,7 +1066,9 @@ "status": "Tila", "statuses": { "accepted": "Myönteiset", - "rejected": "Kielteiset" + "rejected": "Kielteiset", + "inPayment": "Maksussa", + "waitingForPayment": "Menossa maksuun" }, "handler": "Käsittelijä" }, @@ -1090,7 +1093,7 @@ "statusChange": { "awaiting_ahjo_decision": "Koonti merkitty Ahjoon viedyksi", "exported_ahjo_report": "Ahjo-valmistelu aloitettu, koonti lukittu", - "sent_to_talpa": "Koonti käsitelty ja arkistoitu", + "completed": "Koonti käsitelty ja arkistoitu", "draft": "Koonti palautettu takaisin odottamaan päätösvalmistelua", "accepted": "Tarkastustiedot tallennettu", "rejected": "Koonti arkistoitu" diff --git a/frontend/benefit/handler/src/components/batchProcessing/BatchActionsCompletion.tsx b/frontend/benefit/handler/src/components/batchProcessing/BatchActionsCompletion.tsx deleted file mode 100644 index 0a50d866c8..0000000000 --- a/frontend/benefit/handler/src/components/batchProcessing/BatchActionsCompletion.tsx +++ /dev/null @@ -1,202 +0,0 @@ -import useBatchStatus from 'benefit/handler/hooks/useBatchStatus'; -import useDownloadP2PFile from 'benefit/handler/hooks/useDownloadP2PFile'; -import { BATCH_STATUSES } from 'benefit-shared/constants'; -import { BatchProposal } from 'benefit-shared/types/application'; -import { Button, IconArrowUndo, IconDownload } from 'hds-react'; -import noop from 'lodash/noop'; -import { useTranslation } from 'next-i18next'; -import React from 'react'; -import Modal from 'shared/components/modal/Modal'; -import { useTheme } from 'styled-components'; - -import ConfirmModalContent from '../applicationReview/actions/ConfirmModalContent/confirm'; - -type BatchProps = { - batch: BatchProposal; - isInspectionFormSent: boolean; - setInspectionFormSent: React.Dispatch>; - setBatchCloseAnimation: React.Dispatch>; -}; - -const BatchActionsCompletion: React.FC = ({ - batch, - isInspectionFormSent, - setInspectionFormSent, - setBatchCloseAnimation, -}: BatchProps) => { - const theme = useTheme(); - - const { id } = batch; - const { t } = useTranslation(); - const [isDownloadingAttachments, setIsDownloadingAttachments] = - React.useState(false); - - const { - isError: isDownloadError, - isLoading: isDownloading, - mutate: downloadP2PFile, - } = useDownloadP2PFile(); - - const { mutate: changeBatchStatus } = useBatchStatus(setBatchCloseAnimation); - const [isModalBatchToCompletion, setModalBatchToCompletion] = - React.useState(false); - const [isModalBatchToInspection, setModalBatchToInspection] = - React.useState(false); - - const [isMountedAfterFormSubmission, setMountedAfterFormSubmission] = - React.useState(isInspectionFormSent); - - const handleModalClose = (): void => { - setModalBatchToCompletion(false); - setModalBatchToInspection(false); - }; - - const handleBatchStatusChange = (status: BATCH_STATUSES): void => { - changeBatchStatus({ id, status }); - handleModalClose(); - }; - - const handleDownloadP2PFile = React.useCallback(() => { - setIsDownloadingAttachments(true); - downloadP2PFile(id); - }, [downloadP2PFile, id]); - - React.useEffect(() => { - if (isMountedAfterFormSubmission) { - setInspectionFormSent(false); - setIsDownloadingAttachments(true); - handleDownloadP2PFile(); - setMountedAfterFormSubmission(false); - } - if (!isDownloading) { - setIsDownloadingAttachments(false); - } - if (isDownloadError) { - setIsDownloadingAttachments(false); - } - }, [ - isDownloading, - isDownloadError, - isMountedAfterFormSubmission, - setInspectionFormSent, - setIsDownloadingAttachments, - handleDownloadP2PFile, - id, - ]); - - return ( - <> - - handleBatchStatusChange(BATCH_STATUSES.SENT_TO_TALPA) - } - /> - ) : null - } - /> - {isModalBatchToCompletion ? ( - - handleBatchStatusChange(BATCH_STATUSES.SENT_TO_TALPA) - } - /> - ) : null - } - /> - ) : null} - - {isModalBatchToInspection ? ( - - handleBatchStatusChange(BATCH_STATUSES.AWAITING_FOR_DECISION) - } - /> - ) : null - } - /> - ) : null} - - - - - - ); -}; - -export default BatchActionsCompletion; diff --git a/frontend/benefit/handler/src/components/batchProcessing/BatchActionsInspection.tsx b/frontend/benefit/handler/src/components/batchProcessing/BatchActionsInspection.tsx deleted file mode 100644 index 2eeac86e2c..0000000000 --- a/frontend/benefit/handler/src/components/batchProcessing/BatchActionsInspection.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { BATCH_STATUSES } from 'benefit-shared/constants'; -import { BatchProposal } from 'benefit-shared/types/application'; -import React from 'react'; - -import BatchActionsCompletion from './BatchActionsCompletion'; -import BatchActionsInspectionForm from './BatchActionsInspectionForm'; - -type BatchProps = { - batch: BatchProposal; - setBatchCloseAnimation?: React.Dispatch>; -}; - -const BatchActionsInspection: React.FC = ({ - batch, - setBatchCloseAnimation, -}: BatchProps) => - // eslint-disable-next-line sonarjs/cognitive-complexity - { - const { status } = batch; - const [isInspectionFormSent, setInspectionFormSent] = - React.useState(false); - - return ( - <> - {[BATCH_STATUSES.AWAITING_FOR_DECISION].includes(status) ? ( - - ) : null} - {[BATCH_STATUSES.DECIDED_ACCEPTED].includes(status) ? ( - - ) : null} - - ); - }; - -export default BatchActionsInspection; diff --git a/frontend/benefit/handler/src/components/batchProcessing/BatchApplicationList.tsx b/frontend/benefit/handler/src/components/batchProcessing/BatchApplicationList.tsx index a2d9cbe67f..5eb83c96ac 100644 --- a/frontend/benefit/handler/src/components/batchProcessing/BatchApplicationList.tsx +++ b/frontend/benefit/handler/src/components/batchProcessing/BatchApplicationList.tsx @@ -12,7 +12,9 @@ import { IconAngleDown, IconAngleUp, IconArrowUndo, + IconCheckCircle, IconCheckCircleFill, + IconClock, IconCrossCircleFill, Table, } from 'hds-react'; @@ -36,8 +38,9 @@ import { $TableGrid, $TableWrapper, } from '../table/TableExtras.sc'; -import BatchActionsDraft from './BatchActionsDraft'; -import BatchActionsInspection from './BatchActionsInspection'; +import BatchFooterCompletion from './batchFooter/BatchFooterCompletion'; +import BatchFooterDraft from './batchFooter/BatchFooterDraft'; +import BatchFooterInspection from './batchFooter/BatchFooterInspection'; type BatchProps = { batch: BatchProposal; @@ -206,6 +209,32 @@ const BatchApplicationList: React.FC = ({ batch }: BatchProps) => {
{t('common:batches.list.columns.createdAt')}
{convertToUIDateAndTimeFormat(created_at)}
+
+
{t('common:batches.list.columns.createdAt')}
+
{convertToUIDateAndTimeFormat(created_at)}
+
+ {[ + BATCH_STATUSES.SENT_TO_TALPA, + BATCH_STATUSES.DECIDED_ACCEPTED, + ].includes(status) && ( +
+
{t('common:batches.list.columns.status')}
+
+ {status === BATCH_STATUSES.SENT_TO_TALPA ? ( + + ) : ( + + )} + <$BatchStatusValue> + {status === BATCH_STATUSES.SENT_TO_TALPA + ? t('common:batches.list.columns.statuses.inPayment') + : t( + 'common:batches.list.columns.statuses.waitingForPayment' + )} + +
+
+ )}
{applications.length > 0 ? (
+ {applications?.length ? ( <$TableBody $isCollapsed={isCollapsed} aria-hidden={isCollapsed}> = ({ batch }: BatchProps) => { BATCH_STATUSES.DECIDED_ACCEPTED, ].includes(status) ? theme.colors.coatOfArmsLight - : null + : theme.colors.infoLight } > {[ BATCH_STATUSES.DRAFT, BATCH_STATUSES.AHJO_REPORT_CREATED, - ].includes(status) ? ( - - ) : null} + )} + {[BATCH_STATUSES.AWAITING_FOR_DECISION].includes(status) && ( + + )} {[ - BATCH_STATUSES.AWAITING_FOR_DECISION, BATCH_STATUSES.DECIDED_ACCEPTED, - ].includes(status) ? ( - - ) : null} + )} ) : ( diff --git a/frontend/benefit/handler/src/components/batchProcessing/batchFooter/BatchFooterCompletion.tsx b/frontend/benefit/handler/src/components/batchProcessing/batchFooter/BatchFooterCompletion.tsx new file mode 100644 index 0000000000..52f2c38e60 --- /dev/null +++ b/frontend/benefit/handler/src/components/batchProcessing/batchFooter/BatchFooterCompletion.tsx @@ -0,0 +1,287 @@ +import useBatchStatus from 'benefit/handler/hooks/useBatchStatus'; +import useDownloadP2PFile from 'benefit/handler/hooks/useDownloadP2PFile'; +import { BATCH_STATUSES } from 'benefit-shared/constants'; +import { BatchProposal } from 'benefit-shared/types/application'; +import { Button, IconArrowUndo, IconDownload } from 'hds-react'; +import noop from 'lodash/noop'; +import { useTranslation } from 'next-i18next'; +import React from 'react'; +import { $GridCell } from 'shared/components/forms/section/FormSection.sc'; +import Modal from 'shared/components/modal/Modal'; +import { convertToUIDateFormat } from 'shared/utils/date.utils'; + +import ConfirmModalContent from '../../applicationReview/actions/ConfirmModalContent/confirm'; +import { + $ViewField, + $ViewFieldBold, +} from '../../newApplication/ApplicationForm.sc'; +import { $FormSection } from '../../table/TableExtras.sc'; + +type BatchProps = { + batch: BatchProposal; + setBatchCloseAnimation: React.Dispatch>; +}; + +const BatchFooterCompletion: React.FC = ({ + batch, + setBatchCloseAnimation, +}: BatchProps) => { + const { + id, + status: batchStatus, + p2p_checker_name, + p2p_inspector_email, + p2p_inspector_name, + decision_maker_name, + decision_maker_title, + decision_date, + expert_inspector_name, + expert_inspector_title, + section_of_the_law, + } = batch; + const { t } = useTranslation(); + const [isDownloadingAttachments, setIsDownloadingAttachments] = + React.useState(false); + + const { + isError: isDownloadError, + isLoading: isDownloading, + mutate: downloadP2PFile, + } = useDownloadP2PFile(); + + const { mutate: changeBatchStatus } = useBatchStatus(setBatchCloseAnimation); + const [isModalBatchToCompletion, setModalBatchToCompletion] = + React.useState(false); + const [isModalBatchToInspection, setModalBatchToInspection] = + React.useState(false); + + const handleModalClose = (): void => { + setModalBatchToCompletion(false); + setModalBatchToInspection(false); + }; + + const handleBatchStatusChange = (status: BATCH_STATUSES): void => { + changeBatchStatus({ id, status }); + handleModalClose(); + }; + + const handleDownloadP2PFile = React.useCallback(() => { + setIsDownloadingAttachments(true); + downloadP2PFile(id); + }, [downloadP2PFile, id]); + + React.useEffect(() => { + if (!isDownloading) { + setIsDownloadingAttachments(false); + } + if (isDownloadError) { + setIsDownloadingAttachments(false); + } + }, [isDownloading, isDownloadError]); + + return ( + <> + {isModalBatchToCompletion && ( + + handleBatchStatusChange(BATCH_STATUSES.COMPLETED) + } + /> + ) : null + } + /> + )} + {isModalBatchToCompletion && ( + + handleBatchStatusChange(BATCH_STATUSES.COMPLETED) + } + /> + ) : null + } + /> + )} + {isModalBatchToInspection && ( + + handleBatchStatusChange(BATCH_STATUSES.AWAITING_FOR_DECISION) + } + /> + ) : null + } + /> + )} + <$FormSection> + <$GridCell $colSpan={12}> +

{t('common:batches.form.headings.decisionDetails')}

+ + + <$GridCell $colSpan={3} $colStart={1}> + <$ViewFieldBold> + {t('common:batches.form.fields.decisionMakerName')} + + <$ViewField>{decision_maker_title} + + + <$GridCell $colSpan={3}> + <$ViewFieldBold> + {t('common:batches.form.fields.decisionMakerTitle')} + + <$ViewField>{decision_maker_name} + + + <$GridCell $colSpan={2}> + <$ViewFieldBold> + {t('common:batches.form.fields.sectionOfTheLaw')} + + <$ViewField>{section_of_the_law} + + + <$GridCell $colSpan={4}> + <$ViewFieldBold> + {t('common:batches.form.fields.decisionDate')} + + <$ViewField>{convertToUIDateFormat(decision_date)} + + + + {expert_inspector_name?.length && expert_inspector_title?.length ? ( + <$FormSection css="width: 100%"> + <$GridCell $colSpan={3} $colStart={1}> + <$ViewFieldBold> + {t('common:batches.form.fields.expertInspectorName')} + + <$ViewField>{expert_inspector_name} + + + <$GridCell $colSpan={3}> + <$ViewFieldBold> + {t('common:batches.form.fields.expertInspectorTitle')} + + <$ViewField>{expert_inspector_title} + + + <$GridCell $colSpan={6}> + <$ViewFieldBold> + {t('common:batches.form.fields.p2pCheckerName')} + + <$ViewField>{p2p_checker_name} + + + ) : ( + <$FormSection> + <$GridCell $colSpan={3} $colStart={1}> + <$ViewFieldBold> + {t('common:batches.form.fields.p2pInspectorName')} + + <$ViewField>{p2p_inspector_name} + + + <$GridCell $colSpan={3}> + <$ViewFieldBold> + {t('common:batches.form.fields.p2pInspectorEmail')} + + <$ViewField>{p2p_inspector_email} + + + <$GridCell $colSpan={3}> + <$ViewFieldBold> + {t('common:batches.form.fields.p2pCheckerName')} + + <$ViewField>{p2p_checker_name} + + + )} + +
+ {batchStatus === BATCH_STATUSES.DECIDED_ACCEPTED && ( + + )} + + {batchStatus === BATCH_STATUSES.SENT_TO_TALPA && ( + + )} + +
+ + ); +}; + +export default BatchFooterCompletion; diff --git a/frontend/benefit/handler/src/components/batchProcessing/BatchActionsDraft.tsx b/frontend/benefit/handler/src/components/batchProcessing/batchFooter/BatchFooterDraft.tsx similarity index 96% rename from frontend/benefit/handler/src/components/batchProcessing/BatchActionsDraft.tsx rename to frontend/benefit/handler/src/components/batchProcessing/batchFooter/BatchFooterDraft.tsx index 206713a1cd..180a6a60a7 100644 --- a/frontend/benefit/handler/src/components/batchProcessing/BatchActionsDraft.tsx +++ b/frontend/benefit/handler/src/components/batchProcessing/batchFooter/BatchFooterDraft.tsx @@ -18,8 +18,8 @@ import React from 'react'; import Modal from 'shared/components/modal/Modal'; import { useTheme } from 'styled-components'; -import ConfirmModalContent from '../applicationReview/actions/ConfirmModalContent/confirm'; -import { $TooltipWrapper } from './batchAction/BatchActions.sc'; +import ConfirmModalContent from '../../applicationReview/actions/ConfirmModalContent/confirm'; +import { $TooltipWrapper } from '../batchAction/BatchActions.sc'; type BatchProps = { batch: BatchProposal; @@ -28,7 +28,7 @@ type BatchProps = { type ButtonAhjoStates = 'primary' | 'secondary'; -const BatchActionsDraft: React.FC = ({ +const BatchFooterDraft: React.FC = ({ batch, setBatchCloseAnimation, }: BatchProps) => { @@ -235,4 +235,4 @@ const BatchActionsDraft: React.FC = ({ ); }; -export default BatchActionsDraft; +export default BatchFooterDraft; diff --git a/frontend/benefit/handler/src/components/batchProcessing/BatchActionsInspectionForm.tsx b/frontend/benefit/handler/src/components/batchProcessing/batchFooter/BatchFooterInspection.tsx similarity index 91% rename from frontend/benefit/handler/src/components/batchProcessing/BatchActionsInspectionForm.tsx rename to frontend/benefit/handler/src/components/batchProcessing/batchFooter/BatchFooterInspection.tsx index 60397be249..99a4da7202 100644 --- a/frontend/benefit/handler/src/components/batchProcessing/BatchActionsInspectionForm.tsx +++ b/frontend/benefit/handler/src/components/batchProcessing/batchFooter/BatchFooterInspection.tsx @@ -19,15 +19,13 @@ import { $GridCell } from 'shared/components/forms/section/FormSection.sc'; import Modal from 'shared/components/modal/Modal'; import theme from 'shared/styles/theme'; -import ConfirmModalContent from '../applicationReview/actions/ConfirmModalContent/confirm'; -import { $InspectionTypeContainer } from '../table/BatchCompletion.sc'; -import { $FormSection } from '../table/TableExtras.sc'; -import { useBatchActionsInspected } from './useBatchActionsInspected'; +import ConfirmModalContent from '../../applicationReview/actions/ConfirmModalContent/confirm'; +import { $InspectionTypeContainer } from '../../table/BatchCompletion.sc'; +import { $FormSection } from '../../table/TableExtras.sc'; +import { useBatchActionsInspected } from '../useBatchActionsInspected'; type BatchProps = { batch: BatchProposal; - isInspectionFormSent: boolean; - setInspectionFormSent: React.Dispatch>; setBatchCloseAnimation: React.Dispatch>; }; @@ -36,16 +34,14 @@ interface ModalTranslations { text: string; } -const BatchActionsInspectionForm: React.FC = ({ +const BatchFooterInspection: React.FC = ({ batch, - isInspectionFormSent, - setInspectionFormSent, setBatchCloseAnimation, }: // eslint-disable-next-line sonarjs/cognitive-complexity BatchProps) => { const { id, proposal_for_decision: proposalForDecision } = batch; const { t } = useTranslation(); - const { formik, yearFromNow, isSuccess, isError } = useBatchActionsInspected( + const { formik, yearFromNow } = useBatchActionsInspected( batch, setBatchCloseAnimation ); @@ -57,24 +53,15 @@ BatchProps) => { const [inspectorMode, setInspectorMode] = React.useState('ahjo'); - React.useEffect(() => { - if (isError) { - setInspectionFormSent(false); - } - if (isSuccess) { - setInspectionFormSent(true); - } - }, [isSuccess, isError, setInspectionFormSent]); const getErrorMessage = (fieldName: string): string | undefined => getErrorText(formik.errors, formik.touched, fieldName, t, true); const handleModalClose = (): void => { setModalBatchToDraft(false); setModalBatchToCompletion(false); - setInspectionFormSent(false); }; - const handleBatchStatusChange = (): void => { + const handleSubmitToDraft = (): void => { changeBatchStatus({ id, status: BATCH_STATUSES.DRAFT, @@ -87,12 +74,10 @@ BatchProps) => { .submitForm() .then(() => { setModalBatchToCompletion(false); - setInspectionFormSent(true); return true; }) .catch(() => { setModalBatchToCompletion(false); - setInspectionFormSent(false); return false; }); @@ -109,13 +94,11 @@ BatchProps) => { if (Object.keys(errors).length > 0) { return null; } - setInspectionFormSent(true); setModalBatchToCompletion(true); return true; }) .catch(() => { setModalBatchToCompletion(false); - setInspectionFormSent(false); }); }; @@ -155,7 +138,7 @@ BatchProps) => { )} text={t('common:batches.dialog.fromInspectionToDraft.text')} onClose={handleModalClose} - onSubmit={handleBatchStatusChange} + onSubmit={handleSubmitToDraft} /> ) : null} {isModalBatchToCompletion ? ( @@ -365,9 +348,12 @@ BatchProps) => { ) : null} <$FormSection> - <$GridCell $colSpan={3}> + <$GridCell + $colSpan={ + proposalForDecision === PROPOSALS_FOR_DECISION.ACCEPTED ? 3 : 2 + } + >