This repository was archived by the owner on Mar 13, 2025. It is now read-only.
File tree 2 files changed +17
-7
lines changed
2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -384,7 +384,7 @@ export const toggleWorkingPeriodsVisible = (on = null) => ({
384
384
* @param {?boolean } on whether to turn processing-payments state on or off
385
385
* @returns {Object }
386
386
*/
387
- export const toggleWorkPeriodsProcessingPeyments = ( on = null ) => ( {
387
+ export const toggleWorkPeriodsProcessingPayments = ( on = null ) => ( {
388
388
type : ACTION_TYPE . WP_TOGGLE_PROCESSING_PAYMENTS ,
389
389
payload : on ,
390
390
} ) ;
Original file line number Diff line number Diff line change @@ -293,16 +293,26 @@ export const updateWorkPeriodWorkingDays =
293
293
* @param {function } getState function returning redux store root state
294
294
*/
295
295
export const processPayments = async ( dispatch , getState ) => {
296
- dispatch ( actions . toggleWorkPeriodsProcessingPeyments ( true ) ) ;
297
296
const state = getState ( ) ;
297
+ const isProcessing = selectors . getWorkPeriodsIsProcessingPayments ( state ) ;
298
+ if ( isProcessing ) {
299
+ return ;
300
+ }
301
+ dispatch ( actions . toggleWorkPeriodsProcessingPayments ( true ) ) ;
298
302
const isSelectedAll = selectors . getWorkPeriodsIsSelectedAll ( state ) ;
299
303
const { pageSize, totalCount } = selectors . getWorkPeriodsPagination ( state ) ;
300
- if ( isSelectedAll && totalCount > pageSize ) {
301
- processPaymentsAll ( dispatch , getState ) ;
302
- } else {
303
- processPaymentsSpecific ( dispatch , getState ) ;
304
+ const promise =
305
+ isSelectedAll && totalCount > pageSize
306
+ ? processPaymentsAll ( dispatch , getState )
307
+ : processPaymentsSpecific ( dispatch , getState ) ;
308
+ // The promise returned by processPaymentsAll or processPaymentsSpecific
309
+ // should never be rejected but adding try-catch block just in case.
310
+ try {
311
+ await promise ;
312
+ } catch ( error ) {
313
+ console . error ( error ) ;
304
314
}
305
- dispatch ( actions . toggleWorkPeriodsProcessingPeyments ( false ) ) ;
315
+ dispatch ( actions . toggleWorkPeriodsProcessingPayments ( false ) ) ;
306
316
} ;
307
317
308
318
const processPaymentsAll = async ( dispatch , getState ) => {
You can’t perform that action at this time.
0 commit comments