🔀 Merge branch 'trunk'

# Conflicts:
#	modules/ppcp-settings/resources/js/data/common/hooks.js
This commit is contained in:
Philipp Stracker 2025-02-12 15:45:52 +01:00
commit ff81617b22
No known key found for this signature in database
57 changed files with 817 additions and 725 deletions

View file

@ -8,7 +8,7 @@
*/
import { useDispatch, useSelect } from '@wordpress/data';
import { useCallback, useEffect, useState } from '@wordpress/element';
import { useCallback, useEffect, useMemo, useState } from '@wordpress/element';
import { createHooksForStore } from '../utils';
import { STORE_NAME } from './constants';
@ -36,10 +36,6 @@ const useHooks = () => {
const [ isManualConnectionMode, setManualConnectionMode ] = usePersistent(
'useManualConnection'
);
const merchant = useSelect(
( select ) => select( STORE_NAME ).merchant(),
[]
);
// Read-only properties.
const wooSettings = useSelect(
@ -78,7 +74,6 @@ const useHooks = () => {
productionOnboardingUrl,
authenticateWithCredentials,
authenticateWithOAuth,
merchant,
wooSettings,
features,
webhooks,
@ -144,7 +139,8 @@ export const useWebhooks = () => {
};
export const useMerchantInfo = () => {
const { isReady, merchant, features } = useHooks();
const { isReady, features } = useHooks();
const merchant = useMerchant();
const { refreshMerchantData, setMerchant } = useDispatch( STORE_NAME );
const verifyLoginStatus = useCallback( async () => {
@ -175,6 +171,29 @@ export const useMerchantInfo = () => {
};
};
// Read-only access to the sanitized merchant details.
export const useMerchant = () => {
const merchant = useSelect(
( select ) => select( STORE_NAME ).merchant(),
[]
);
return useMemo(
() => ( {
isConnected: merchant.isConnected ?? false,
isSandbox: merchant.isSandbox ?? true,
id: merchant.id ?? '',
email: merchant.email ?? '',
clientId: merchant.clientId ?? '',
clientSecret: merchant.clientSecret ?? '',
isBusinessSeller: 'business' === merchant.sellerType,
isCasualSeller: 'personal' === merchant.sellerType,
} ),
// the merchant object is stable, so a new memo is only generated when a merchant prop changes.
[ merchant ]
);
};
export const useActiveModal = () => {
const { activeModal, setActiveModal } = useHooks();
return { activeModal, setActiveModal };