Add store action to update merchant details

This commit is contained in:
Philipp Stracker 2025-02-12 13:24:52 +01:00
parent e09ad9d74d
commit 67522b9557
No known key found for this signature in database
3 changed files with 16 additions and 0 deletions

View file

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

View file

@ -110,6 +110,17 @@ export const setManualConnectionMode = ( useManualConnection ) =>
export const setWebhooks = ( webhooks ) =>
setPersistent( 'webhooks', webhooks );
/**
* Replace merchant details in the store.
*
* @param {Object} merchant - The new merchant details.
* @return {Action} The action.
*/
export const setMerchant = ( merchant ) => ( {
type: ACTION_TYPES.SET_MERCHANT,
payload: { merchant },
} );
/**
* Reset merchant details in the store.
*

View file

@ -113,6 +113,10 @@ const commonReducer = createReducer( defaultTransient, defaultPersistent, {
features: Object.freeze( { ...defaultTransient.features } ),
} ),
[ ACTION_TYPES.SET_MERCHANT ]: ( state, payload ) => {
return changePersistent( state, { merchant: payload.merchant } );
},
[ ACTION_TYPES.HYDRATE ]: ( state, payload ) => {
const newState = changePersistent( state, payload.data );