11import get from 'lodash/get' ;
2- import PropTypes from 'prop-types' ;
32import {
43 useCallback ,
54 useEffect ,
@@ -11,15 +10,13 @@ import {
1110 FormattedMessage ,
1211 useIntl ,
1312} from 'react-intl' ;
14- import ReactRouterPropTypes from 'react-router-prop-types' ;
1513
1614import {
1715 IfPermission ,
1816 TitleManager ,
1917 stripesConnect ,
2018} from '@folio/stripes/core' ;
2119import {
22- baseManifest ,
2320 CUSTOM_FIELDS_ORDERS_BACKEND_NAME ,
2421 getErrorCodeFromResponse ,
2522 handleKeyCommand ,
@@ -69,16 +66,13 @@ import {
6966 INVOICES_ROUTE ,
7067 ORDERS_ROUTE ,
7168 PO_CONFIG_NAME_PREFIX ,
69+ PO_UPDATE_ACTION_TYPES ,
7270 REEXPORT_SOURCES ,
7371 SCOPE_CUSTOM_FIELDS_MANAGE ,
7472 WORKFLOW_STATUS ,
7573} from '../../common/constants' ;
7674import { useHandleOrderUpdateError } from '../../common/hooks' ;
7775import { isOngoing } from '../../common/POFields' ;
78- import {
79- reasonsForClosureResource ,
80- updateEncumbrancesResource ,
81- } from '../../common/resources' ;
8276import {
8377 getCommonErrorMessage ,
8478 getExportAccountNumbers ,
@@ -93,15 +87,12 @@ import {
9387 reopenOrder as reopenOrderResource ,
9488 updateOrderResource ,
9589} from '../Utils/orderResource' ;
96- import {
97- APPROVALS_SETTING ,
98- FUND ,
99- LINES_LIMIT ,
100- ORDER_NUMBER ,
101- ORDER ,
102- } from '../Utils/resources' ;
10390import CloseOrderModal from './CloseOrder' ;
104- import { LINE_LISTING_COLUMN_MAPPING } from './constants' ;
91+ import {
92+ LINE_LISTING_COLUMN_MAPPING ,
93+ PO_MANIFEST ,
94+ PO_PROP_TYPES ,
95+ } from './constants' ;
10596import { getPOActionMenu } from './getPOActionMenu' ;
10697import {
10798 useOrderMutation ,
@@ -260,7 +251,7 @@ const PO = ({
260251 refreshList ( ) ;
261252 } )
262253 . catch ( e => {
263- return handleErrorResponse ( e , orderErrorModalShow , 'clone.error' ) ;
254+ return handleErrorResponse ( e , { openModal : orderErrorModalShow , genericCode : 'clone.error' } ) ;
264255 } )
265256 . finally ( ( ) => setIsLoading ( false ) ) ;
266257 } , [
@@ -324,6 +315,8 @@ const PO = ({
324315 } ,
325316 } ;
326317
318+ const actionType = isCancelReason ? PO_UPDATE_ACTION_TYPES . CANCEL : PO_UPDATE_ACTION_TYPES . CLOSE ;
319+
327320 setIsCancelReason ( false ) ;
328321 toggleCloseOrderModal ( ) ;
329322 setIsLoading ( true ) ;
@@ -336,19 +329,24 @@ const PO = ({
336329
337330 return refetch ( ) ;
338331 } ,
339- e => handleErrorResponse ( e , orderErrorModalShow , 'closeOrder' ) ,
332+ ( e ) => handleErrorResponse ( e , {
333+ actionType,
334+ genericCode : 'closeOrder' ,
335+ openModal : orderErrorModalShow ,
336+ } ) ,
340337 )
341338 . finally ( ( ) => setIsLoading ( false ) ) ;
342339 } , [
343- toggleCloseOrderModal ,
344- order ,
340+ handleErrorResponse ,
341+ isCancelReason ,
345342 mutator . orderDetails ,
346- sendCallout ,
347- refreshList ,
343+ order ,
344+ orderErrorModalShow ,
348345 refetch ,
349346 refetchFiscalYears ,
350- handleErrorResponse ,
351- orderErrorModalShow ,
347+ refreshList ,
348+ sendCallout ,
349+ toggleCloseOrderModal ,
352350 ] ) ;
353351
354352 const cancelClosingOrder = useCallback ( ( ) => {
@@ -368,8 +366,11 @@ const PO = ({
368366
369367 return refetch ( ) ;
370368 } ,
371- e => {
372- return handleErrorResponse ( e , orderErrorModalShow ) ;
369+ ( e ) => {
370+ return handleErrorResponse ( e , {
371+ actionType : PO_UPDATE_ACTION_TYPES . APPROVE ,
372+ openModal : orderErrorModalShow ,
373+ } ) ;
373374 } ,
374375 )
375376 . finally ( ( ) => setIsLoading ( false ) ) ;
@@ -414,8 +415,13 @@ const PO = ({
414415
415416 return refetch ( ) ;
416417 } ,
417- e => {
418- return handleErrorResponse ( e , orderErrorModalShow , ERROR_CODES . orderGenericError1 , toggleDeletePieces ) ;
418+ ( e ) => {
419+ return handleErrorResponse ( e , {
420+ actionType : PO_UPDATE_ACTION_TYPES . OPEN ,
421+ genericCode : ERROR_CODES . orderGenericError1 ,
422+ openModal : orderErrorModalShow ,
423+ toggleDeletePieces,
424+ } ) ;
419425 } ,
420426 )
421427 . finally ( ( ) => setIsLoading ( false ) ) ;
@@ -451,8 +457,11 @@ const PO = ({
451457
452458 return refetch ( ) ;
453459 } ,
454- e => {
455- return handleErrorResponse ( e , orderErrorModalShow ) ;
460+ ( e ) => {
461+ return handleErrorResponse ( e , {
462+ actionType : PO_UPDATE_ACTION_TYPES . REOPEN ,
463+ openModal : orderErrorModalShow ,
464+ } ) ;
456465 } ,
457466 )
458467 . finally ( ( ) => setIsLoading ( false ) ) ;
@@ -491,7 +500,10 @@ const PO = ({
491500 return refetch ( ) ;
492501 } ,
493502 ( e ) => {
494- return handleErrorResponse ( e ?. response , orderErrorModalShow ) ;
503+ return handleErrorResponse ( e ?. response , {
504+ actionType : PO_UPDATE_ACTION_TYPES . UNOPEN ,
505+ openModal : orderErrorModalShow ,
506+ } ) ;
495507 } ,
496508 )
497509 . finally ( ( ) => setIsLoading ( false ) ) ;
@@ -519,8 +531,11 @@ const PO = ({
519531 search : location . search ,
520532 } ) ;
521533 } )
522- . catch ( e => {
523- return handleErrorResponse ( e , orderErrorModalShow , 'noCreatedOrder' ) ;
534+ . catch ( ( e ) => {
535+ return handleErrorResponse ( e , {
536+ genericCode : 'noCreatedOrder' ,
537+ openModal : orderErrorModalShow ,
538+ } ) ;
524539 } )
525540 . finally ( ( ) => setIsLoading ( false ) ) ;
526541 } , [
@@ -623,8 +638,12 @@ const PO = ({
623638
624639 return refetch ( ) ;
625640 } ,
626- e => {
627- return handleErrorResponse ( e , orderErrorModalShow , 'ui-orders.order.updateEncumbrances.error' ) ;
641+ ( e ) => {
642+ return handleErrorResponse ( e , {
643+ actionType : PO_UPDATE_ACTION_TYPES . RE_ENCUMBER ,
644+ genericCode : 'ui-orders.order.updateEncumbrances.error' ,
645+ openModal : orderErrorModalShow ,
646+ } ) ;
628647 } ,
629648 )
630649 . finally ( ( ) => setIsLoading ( false ) ) ;
@@ -973,33 +992,7 @@ const PO = ({
973992 ) ;
974993} ;
975994
976- PO . manifest = Object . freeze ( {
977- orderDetails : {
978- ...ORDER ,
979- accumulate : true ,
980- fetch : false ,
981- } ,
982- linesLimit : LINES_LIMIT ,
983- closingReasons : reasonsForClosureResource ,
984- fund : FUND ,
985- approvalsSetting : APPROVALS_SETTING ,
986- expenseClass : {
987- ...baseManifest ,
988- accumulate : true ,
989- fetch : false ,
990- } ,
991- generatedOrderNumber : ORDER_NUMBER ,
992- updateEncumbrances : updateEncumbrancesResource ,
993- } ) ;
994-
995- PO . propTypes = {
996- history : ReactRouterPropTypes . history . isRequired ,
997- location : ReactRouterPropTypes . location . isRequired ,
998- match : ReactRouterPropTypes . match . isRequired ,
999- mutator : PropTypes . object . isRequired ,
1000- resources : PropTypes . object . isRequired ,
1001- refreshList : PropTypes . func . isRequired ,
1002- stripes : PropTypes . object . isRequired ,
1003- } ;
995+ PO . manifest = PO_MANIFEST ;
996+ PO . propTypes = PO_PROP_TYPES ;
1004997
1005998export default stripesConnect ( PO ) ;
0 commit comments