From 91c8bdafb91c59503efe8aa890ab9ebba54ed55d Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Tue, 4 Feb 2025 18:54:56 +0100
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Initial=20version=20of=20Disconnect?=
=?UTF-8?q?=20button?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/Settings/ConnectionStatus.js | 18 ++++-
.../Settings/Parts/DisconnectButton.js | 73 +++++++++++++++++++
.../resources/js/data/common/hooks.js | 7 ++
3 files changed, 94 insertions(+), 4 deletions(-)
create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Settings/Parts/DisconnectButton.js
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Settings/ConnectionStatus.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Settings/ConnectionStatus.js
index 886fe5c02..d93b8431b 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Settings/ConnectionStatus.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Settings/ConnectionStatus.js
@@ -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';
@@ -13,10 +14,7 @@ const ConnectionStatus = () => {
}
>
{
};
export default ConnectionStatus;
+
+const ConnectionDescription = () => {
+ return (
+ <>
+ { __(
+ 'Your PayPal account connection details.',
+ 'woocommerce-paypal-payments'
+ ) }
+
+ >
+ );
+};
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Settings/Parts/DisconnectButton.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Settings/Parts/DisconnectButton.js
new file mode 100644
index 000000000..aabdd2192
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Settings/Parts/DisconnectButton.js
@@ -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 (
+ <>
+
+ { __( 'Disconnect', 'woocommerce-paypal-payments' ) }
+
+
+ { isOpen && (
+
+
+ { __(
+ 'Disconnecting your account will restart the connection wizard. Are you sure you want to disconnect from your PayPal account?',
+ 'woocommerce-paypal-payments'
+ ) }
+
+
+
+ { __( 'Cancel', 'woocommerce-paypal-payments' ) }
+
+
+ { __(
+ 'Disconnect',
+ 'woocommerce-paypal-payments'
+ ) }
+
+
+
+ ) }
+ >
+ );
+};
+
+export default DisconnectButton;
diff --git a/modules/ppcp-settings/resources/js/data/common/hooks.js b/modules/ppcp-settings/resources/js/data/common/hooks.js
index 0fc8c5f19..b4dd4e936 100644
--- a/modules/ppcp-settings/resources/js/data/common/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/common/hooks.js
@@ -23,6 +23,7 @@ const useHooks = () => {
authenticateWithOAuth,
startWebhookSimulation,
checkWebhookSimulationState,
+ disconnectMerchant,
} = useDispatch( STORE_NAME );
// Transient accessors.
@@ -78,6 +79,7 @@ const useHooks = () => {
productionOnboardingUrl,
authenticateWithCredentials,
authenticateWithOAuth,
+ disconnectMerchant,
merchant,
wooSettings,
features,
@@ -115,6 +117,11 @@ export const useAuthentication = () => {
};
};
+export const useDisconnectMerchant = () => {
+ const { disconnectMerchant } = useHooks();
+ return { disconnectMerchant };
+};
+
export const useWooSettings = () => {
const { wooSettings } = useHooks();