mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
✨ Initial version of Disconnect button
This commit is contained in:
parent
3c5c348d70
commit
91c8bdafb9
3 changed files with 94 additions and 4 deletions
|
@ -3,6 +3,7 @@ import { __ } from '@wordpress/i18n';
|
||||||
import SettingsCard from '../../../../ReusableComponents/SettingsCard';
|
import SettingsCard from '../../../../ReusableComponents/SettingsCard';
|
||||||
import { CommonHooks } from '../../../../../data';
|
import { CommonHooks } from '../../../../../data';
|
||||||
import ConnectionStatusBadge from './Parts/ConnectionStatusBadge';
|
import ConnectionStatusBadge from './Parts/ConnectionStatusBadge';
|
||||||
|
import DisconnectButton from './Parts/DisconnectButton';
|
||||||
import SettingsBlock from '../../../../ReusableComponents/SettingsBlock';
|
import SettingsBlock from '../../../../ReusableComponents/SettingsBlock';
|
||||||
import { ControlStaticValue } from '../../../../ReusableComponents/Controls';
|
import { ControlStaticValue } from '../../../../ReusableComponents/Controls';
|
||||||
|
|
||||||
|
@ -13,10 +14,7 @@ const ConnectionStatus = () => {
|
||||||
<SettingsCard
|
<SettingsCard
|
||||||
className="ppcp-connection-details ppcp--value-list"
|
className="ppcp-connection-details ppcp--value-list"
|
||||||
title={ __( 'Connection status', 'woocommerce-paypal-payments' ) }
|
title={ __( 'Connection status', 'woocommerce-paypal-payments' ) }
|
||||||
description={ __(
|
description={ <ConnectionDescription /> }
|
||||||
'Your PayPal account connection details',
|
|
||||||
'woocommerce-paypal-payments'
|
|
||||||
) }
|
|
||||||
>
|
>
|
||||||
<SettingsBlock>
|
<SettingsBlock>
|
||||||
<ControlStaticValue
|
<ControlStaticValue
|
||||||
|
@ -48,3 +46,15 @@ const ConnectionStatus = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ConnectionStatus;
|
export default ConnectionStatus;
|
||||||
|
|
||||||
|
const ConnectionDescription = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{ __(
|
||||||
|
'Your PayPal account connection details.',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
) }
|
||||||
|
<DisconnectButton />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -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;
|
|
@ -23,6 +23,7 @@ const useHooks = () => {
|
||||||
authenticateWithOAuth,
|
authenticateWithOAuth,
|
||||||
startWebhookSimulation,
|
startWebhookSimulation,
|
||||||
checkWebhookSimulationState,
|
checkWebhookSimulationState,
|
||||||
|
disconnectMerchant,
|
||||||
} = useDispatch( STORE_NAME );
|
} = useDispatch( STORE_NAME );
|
||||||
|
|
||||||
// Transient accessors.
|
// Transient accessors.
|
||||||
|
@ -78,6 +79,7 @@ const useHooks = () => {
|
||||||
productionOnboardingUrl,
|
productionOnboardingUrl,
|
||||||
authenticateWithCredentials,
|
authenticateWithCredentials,
|
||||||
authenticateWithOAuth,
|
authenticateWithOAuth,
|
||||||
|
disconnectMerchant,
|
||||||
merchant,
|
merchant,
|
||||||
wooSettings,
|
wooSettings,
|
||||||
features,
|
features,
|
||||||
|
@ -115,6 +117,11 @@ export const useAuthentication = () => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useDisconnectMerchant = () => {
|
||||||
|
const { disconnectMerchant } = useHooks();
|
||||||
|
return { disconnectMerchant };
|
||||||
|
};
|
||||||
|
|
||||||
export const useWooSettings = () => {
|
export const useWooSettings = () => {
|
||||||
const { wooSettings } = useHooks();
|
const { wooSettings } = useHooks();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue