♻️ Common store: Detach a reducer from controls

This commit is contained in:
Philipp Stracker 2025-02-06 14:21:59 +01:00
parent d90a893a38
commit 4f5b254452
No known key found for this signature in database
4 changed files with 11 additions and 1 deletions

View file

@ -12,6 +12,7 @@ export default {
SET_PERSISTENT: 'ppcp/common/SET_PERSISTENT',
RESET: 'ppcp/common/RESET',
HYDRATE: 'ppcp/common/HYDRATE',
RESET_MERCHANT: 'ppcp/common/RESET_MERCHANT',
// Activity management (advanced solution that replaces the isBusy state).
START_ACTIVITY: 'ppcp/common/START_ACTIVITY',

View file

@ -173,6 +173,7 @@ export function disconnectMerchant() {
export function refreshMerchantData() {
return async ( { dispatch } ) => {
try {
await dispatch.resetMerchant();
const result = await apiFetch( {
path: REST_HYDRATE_MERCHANT_PATH,
} );

View file

@ -110,6 +110,13 @@ export const setManualConnectionMode = ( useManualConnection ) =>
export const setWebhooks = ( webhooks ) =>
setPersistent( 'webhooks', webhooks );
/**
* Reset merchant details in the store.
*
* @return {Action} The action.
*/
export const resetMerchant = () => ( { type: ACTION_TYPES.RESET_MERCHANT } );
// Activity control - see useBusyState() hook.
/**

View file

@ -106,7 +106,8 @@ const commonReducer = createReducer( defaultTransient, defaultPersistent, {
return changeTransient( state, { activities: newActivities } );
},
[ ACTION_TYPES.DO_REFRESH_MERCHANT ]: ( state ) => ( {
// Instantly reset the merchant data and features before refreshing the details.
[ ACTION_TYPES.RESET_MERCHANT ]: ( state ) => ( {
...state,
merchant: Object.freeze( { ...defaultTransient.merchant } ),
features: Object.freeze( { ...defaultTransient.features } ),