Skip to content

Commit

Permalink
✨ Initial version of Disconnect button
Browse files Browse the repository at this point in the history
  • Loading branch information
stracker-phil committed Feb 4, 2025
1 parent 3c5c348 commit 91c8bda
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { __ } from '@wordpress/i18n';
import SettingsCard from '../../../../ReusableComponents/SettingsCard';
import { CommonHooks } from '../../../../../data';
import ConnectionStatusBadge from './Parts/ConnectionStatusBadge';
import DisconnectButton from './Parts/DisconnectButton';
import SettingsBlock from '../../../../ReusableComponents/SettingsBlock';
import { ControlStaticValue } from '../../../../ReusableComponents/Controls';

Expand All @@ -13,10 +14,7 @@ const ConnectionStatus = () => {
<SettingsCard
className="ppcp-connection-details ppcp--value-list"
title={ __( 'Connection status', 'woocommerce-paypal-payments' ) }
description={ __(
'Your PayPal account connection details',
'woocommerce-paypal-payments'
) }
description={ <ConnectionDescription /> }
>
<SettingsBlock>
<ControlStaticValue
Expand Down Expand Up @@ -48,3 +46,15 @@ const ConnectionStatus = () => {
};

export default ConnectionStatus;

const ConnectionDescription = () => {
return (
<>
{ __(
'Your PayPal account connection details.',
'woocommerce-paypal-payments'
) }
<DisconnectButton />
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { __ } from '@wordpress/i18n';
import { Button, Modal } from '@wordpress/components';
import { useCallback, useState } from '@wordpress/element';

import { CommonHooks } from '../../../../../../data';
import { HStack } from '../../../../../ReusableComponents/Stack';

const DisconnectButton = () => {
const [ isOpen, setIsOpen ] = useState( false );
const { disconnectMerchant } = CommonHooks.useDisconnectMerchant();

const handleOpen = useCallback( () => {
setIsOpen( true );
}, [] );

const handleCancel = useCallback( () => {
setIsOpen( false );
}, [] );

const handleConfirm = useCallback( async () => {
await disconnectMerchant();
window.location.reload();
}, [ disconnectMerchant ] );

const confirmationTitle = __(
'Disconnect from PayPal?',
'woocommerce-paypal-payments'
);

return (
<>
<Button
variant="tertiary"
isDestructive={ true }
onClick={ handleOpen }
>
{ __( 'Disconnect', 'woocommerce-paypal-payments' ) }
</Button>

{ isOpen && (
<Modal
size="small"
title={ confirmationTitle }
onRequestClose={ handleCancel }
>
<p>
{ __(
'Disconnecting your account will restart the connection wizard. Are you sure you want to disconnect from your PayPal account?',
'woocommerce-paypal-payments'
) }
</p>
<HStack>
<Button variant="tertiary" onClick={ handleCancel }>
{ __( 'Cancel', 'woocommerce-paypal-payments' ) }
</Button>
<Button
variant="primary"
isDestructive={ true }
onClick={ handleConfirm }
>
{ __(
'Disconnect',
'woocommerce-paypal-payments'
) }
</Button>
</HStack>
</Modal>
) }
</>
);
};

export default DisconnectButton;
7 changes: 7 additions & 0 deletions modules/ppcp-settings/resources/js/data/common/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const useHooks = () => {
authenticateWithOAuth,
startWebhookSimulation,
checkWebhookSimulationState,
disconnectMerchant,
} = useDispatch( STORE_NAME );

// Transient accessors.
Expand Down Expand Up @@ -78,6 +79,7 @@ const useHooks = () => {
productionOnboardingUrl,
authenticateWithCredentials,
authenticateWithOAuth,
disconnectMerchant,
merchant,
wooSettings,
features,
Expand Down Expand Up @@ -115,6 +117,11 @@ export const useAuthentication = () => {
};
};

export const useDisconnectMerchant = () => {
const { disconnectMerchant } = useHooks();
return { disconnectMerchant };
};

export const useWooSettings = () => {
const { wooSettings } = useHooks();

Expand Down

0 comments on commit 91c8bda

Please sign in to comment.