Skip to content

Commit

Permalink
use merchant directly
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Jan 13, 2025
1 parent b65ed2b commit c2c4347
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -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 (
<div className="ppcp-r-connection-status__data">
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<SettingsCard
className="ppcp-r-tab-overview-support"
Expand All @@ -20,7 +20,7 @@ const ConnectionStatus = () => {
<div className="ppcp-r-connection-status">
<div className="ppcp-r-connection-status__status">
<div className="ppcp-r-connection-status__status-status">
{ getDefaultConnectionStatusData().connectionStatus ? (
{ merchant.isConnected ? (
<TitleBadge
type={ TITLE_BADGE_POSITIVE }
text={ __(
Expand All @@ -39,12 +39,8 @@ const ConnectionStatus = () => {
) }
</div>
</div>
{ getDefaultConnectionStatusData().connectionStatus && (
<ConnectionInfo
connectionStatusDataDefault={
getDefaultConnectionStatusData()
}
/>
{ merchant.isConnected && (
<ConnectionInfo connectionStatusDataDefault={ merchant } />
) }
</div>
</SettingsCard>
Expand Down

0 comments on commit c2c4347

Please sign in to comment.