Add merchant details to “common” hydration path

This commit is contained in:
Philipp Stracker 2024-12-06 19:07:44 +01:00
parent 0462905123
commit c97464d7e2
No known key found for this signature in database
4 changed files with 60 additions and 9 deletions

View file

@ -8,7 +8,7 @@
export const STORE_NAME = 'wc/paypal/common';
/**
* REST path to hydrate data of this module by loading data from the WP DB..
* REST path to hydrate data of this module by loading data from the WP DB.
*
* Used by resolvers.
*

View file

@ -17,6 +17,13 @@ const defaultTransient = {
activities: new Map(),
// Read only values, provided by the server via hydrate.
merchant: {
isConnected: false,
isSandbox: false,
id: '',
email: '',
},
wooSettings: {
storeCountry: '',
storeCurrency: '',
@ -75,12 +82,17 @@ const commonReducer = createReducer( defaultTransient, defaultPersistent, {
[ ACTION_TYPES.HYDRATE ]: ( state, payload ) => {
const newState = setPersistent( state, payload.data );
if ( payload.wooSettings ) {
newState.wooSettings = {
...newState.wooSettings,
...payload.wooSettings,
};
}
// Populate read-only properties.
[ 'wooSettings', 'merchant' ].forEach( ( key ) => {
if ( ! payload[ key ] ) {
return;
}
newState[ key ] = Object.freeze( {
...newState[ key ],
...payload[ key ],
} );
} );
return newState;
},

View file

@ -16,7 +16,8 @@ export const persistentData = ( state ) => {
};
export const transientData = ( state ) => {
const { data, wooSettings, ...transientState } = getState( state );
const { data, merchant, wooSettings, ...transientState } =
getState( state );
return transientState || EMPTY_OBJ;
};