From c2c4347ce2491ab9faec1b2bcf55d3a155806e3a Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Mon, 13 Jan 2025 15:21:36 +0100 Subject: [PATCH] use merchant directly --- .../ReusableComponents/ConnectionInfo.js | 23 ++----------------- .../TabSettingsElements/ConnectionStatus.js | 16 +++++-------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/ConnectionInfo.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/ConnectionInfo.js index 4d06f16e4..0c90bf58f 100644 --- a/modules/ppcp-settings/resources/js/Components/ReusableComponents/ConnectionInfo.js +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/ConnectionInfo.js @@ -1,17 +1,8 @@ import { __ } from '@wordpress/i18n'; -import { useState, useEffect } from '@wordpress/element'; -import {CommonHooks} from "../../data"; - +import { CommonHooks } from '../../data'; const ConnectionInfo = () => { - const { merchant } = CommonHooks.useMerchantInfo(); - const [connectionData, setConnectionData] = useState(getDefaultConnectionStatusData(merchant)); - - useEffect(() => { - if (merchant) { - setConnectionData(getDefaultConnectionStatusData(merchant)); - } - }, [merchant]); + const { merchant } = CommonHooks.useMerchantInfo(); return (
@@ -31,16 +22,6 @@ const ConnectionInfo = () => { ); }; export default ConnectionInfo; -export const getDefaultConnectionStatusData = (merchant = null) => { - if (!merchant) { - const contextMerchant = CommonHooks.useMerchantInfo()?.merchant || {}; - return { - connectionStatus: contextMerchant.isConnected || false, - email: contextMerchant.email || '', - merchantId: contextMerchant.id || '', - clientId: contextMerchant.clientId || '', - }; - } return { connectionStatus: merchant.isConnected || false, diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabSettingsElements/ConnectionStatus.js b/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabSettingsElements/ConnectionStatus.js index fa264a6ee..c765d8738 100644 --- a/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabSettingsElements/ConnectionStatus.js +++ b/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabSettingsElements/ConnectionStatus.js @@ -1,13 +1,13 @@ import { __ } from '@wordpress/i18n'; import SettingsCard from '../../../ReusableComponents/SettingsCard'; -import ConnectionInfo, { - getDefaultConnectionStatusData, -} from '../../../ReusableComponents/ConnectionInfo'; +import { CommonHooks } from '../../../../data'; import TitleBadge, { TITLE_BADGE_NEGATIVE, TITLE_BADGE_POSITIVE, } from '../../../ReusableComponents/TitleBadge'; +import ConnectionInfo from '../../../ReusableComponents/ConnectionInfo'; const ConnectionStatus = () => { + const { merchant } = CommonHooks.useMerchantInfo(); return ( {
- { getDefaultConnectionStatusData().connectionStatus ? ( + { merchant.isConnected ? ( { ) }
- { getDefaultConnectionStatusData().connectionStatus && ( - + { merchant.isConnected && ( + ) }