@@ -21,6 +21,7 @@ import {
2121 onApproveSavePayment ,
2222} from '../paypal-config' ;
2323import { useRef } from 'react' ;
24+ import Spinner from '../../../../ppcp-button/resources/js/modules/Helper/Spinner' ;
2425
2526const PAYPAL_GATEWAY_ID = 'ppcp-gateway' ;
2627
@@ -52,8 +53,11 @@ export const PayPalComponent = ( {
5253 useState ( false ) ;
5354
5455 const [ paypalScriptLoaded , setPaypalScriptLoaded ] = useState ( false ) ;
56+ const [ isFullPageSpinnerActive , setIsFullPageSpinnerActive ] =
57+ useState ( false ) ;
5558
5659 const paypalButtonRef = useRef ( null ) ;
60+ const spinnerRef = useRef ( null ) ;
5761
5862 if ( ! paypalScriptLoaded ) {
5963 if ( ! paypalScriptPromise ) {
@@ -70,6 +74,18 @@ export const PayPalComponent = ( {
7074 ? `${ config . id } -${ fundingSource } `
7175 : config . id ;
7276
77+ // Full-page spinner used to block UI interactions during flows like AppSwitch.
78+ useEffect ( ( ) => {
79+ if ( isFullPageSpinnerActive ) {
80+ if ( ! spinnerRef . current ) {
81+ spinnerRef . current = Spinner . fullPage ( ) ;
82+ }
83+ spinnerRef . current . block ( ) ;
84+ } else if ( spinnerRef . current ) {
85+ spinnerRef . current . unblock ( ) ;
86+ }
87+ } , [ isFullPageSpinnerActive ] ) ;
88+
7389 useEffect ( ( ) => {
7490 // fill the form if in continuation (for product or mini-cart buttons)
7591 if ( continuationFilled || ! config . scriptData . continuation ?. order ) {
@@ -286,12 +302,21 @@ export const PayPalComponent = ( {
286302 } ;
287303 } , [ onPaymentSetup , paypalOrder , activePaymentMethod ] ) ;
288304
305+ useEffect ( ( ) => {
306+ const unsubscribe = onCheckoutFail ( ( ) => {
307+ setIsFullPageSpinnerActive ( false ) ;
308+ } ) ;
309+
310+ return unsubscribe ;
311+ } , [ onCheckoutFail ] ) ;
312+
289313 useEffect ( ( ) => {
290314 if ( activePaymentMethod !== methodId ) {
291315 return ;
292316 }
293317 const unsubscribe = onCheckoutFail ( ( { processingResponse } ) => {
294318 console . error ( processingResponse ) ;
319+ setIsFullPageSpinnerActive ( false ) ;
295320 if ( onClose ) {
296321 onClose ( ) ;
297322 }
@@ -336,7 +361,8 @@ export const PayPalComponent = ( {
336361 setGotoContinuationOnError ,
337362 onSubmit ,
338363 onError ,
339- onClose
364+ onClose ,
365+ setIsFullPageSpinnerActive
340366 ) ;
341367 } ,
342368 }
@@ -491,7 +517,8 @@ export const PayPalComponent = ( {
491517 setGotoContinuationOnError ,
492518 onSubmit ,
493519 onError ,
494- onClose
520+ onClose ,
521+ setIsFullPageSpinnerActive
495522 )
496523 }
497524 onShippingOptionsChange = { getOnShippingOptionsChange (
0 commit comments