Skip to content

Commit

Permalink
Add loading state to the Setup button
Browse files Browse the repository at this point in the history
  • Loading branch information
mordeth committed Aug 27, 2024
1 parent af1b5fe commit fc38eca
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { __ } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';
import { Button, Modal } from '@wordpress/components';
import { Icon, currencyDollar } from '@wordpress/icons';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -26,12 +27,16 @@ const SetupLivePaymentsModal: React.FC< Props > = ( {
source,
onClose,
}: Props ) => {
const [ isLoading, setIsLoading ] = useState( false );

const handleSetup = () => {
recordEvent( 'wcpay_onboarding_flow_setup_live_payments', {
from,
source,
} );

setIsLoading( true );

window.location.href = addQueryArgs( wcpaySettings.connectUrl, {
'wcpay-disable-onboarding-test-mode': 'true',
from,
Expand All @@ -45,6 +50,7 @@ const SetupLivePaymentsModal: React.FC< Props > = ( {
source,
} );

setIsLoading( false );
onClose();
};

Expand Down Expand Up @@ -85,7 +91,12 @@ const SetupLivePaymentsModal: React.FC< Props > = ( {
<Button variant="tertiary" onClick={ trackAndClose }>
{ __( 'Cancel', 'woocommerce-payments' ) }
</Button>
<Button variant="primary" onClick={ handleSetup }>
<Button
variant="primary"
onClick={ handleSetup }
isBusy={ isLoading }
disabled={ isLoading }
>
{ __( 'Continue setup', 'woocommerce-payments' ) }
</Button>
</div>
Expand Down

0 comments on commit fc38eca

Please sign in to comment.