mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
New Settings UI: Apply feedback
This commit is contained in:
parent
a06a74004c
commit
4f0f71f5e0
5 changed files with 37 additions and 27 deletions
|
@ -43,7 +43,11 @@ const useHooks = () => {
|
|||
const clientSecret = usePersistent( 'clientSecret' );
|
||||
const isSandboxMode = usePersistent( 'useSandbox' );
|
||||
const isManualConnectionMode = usePersistent( 'useManualConnection' );
|
||||
const flags = usePersistent( 'flags' );
|
||||
|
||||
const wooSettings = useSelect(
|
||||
( select ) => select( STORE_NAME ).wooSettings(),
|
||||
[]
|
||||
);
|
||||
|
||||
const savePersistent = async ( setter, value ) => {
|
||||
setter( value );
|
||||
|
@ -70,7 +74,7 @@ const useHooks = () => {
|
|||
},
|
||||
connectViaSandbox,
|
||||
connectViaIdAndSecret,
|
||||
flags,
|
||||
wooSettings,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -113,7 +117,6 @@ export const useManualConnection = () => {
|
|||
};
|
||||
|
||||
export const useWooSettings = () => {
|
||||
const { flags = {} } = useHooks();
|
||||
const { country, currency } = flags;
|
||||
return { storeCountry: country, storeCurrency: currency };
|
||||
const { wooSettings } = useHooks();
|
||||
return wooSettings;
|
||||
};
|
||||
|
|
|
@ -22,10 +22,6 @@ const defaultPersistent = {
|
|||
useManualConnection: false,
|
||||
clientId: '',
|
||||
clientSecret: '',
|
||||
flags: {
|
||||
country: '',
|
||||
currency: '',
|
||||
},
|
||||
};
|
||||
|
||||
// Reducer logic.
|
||||
|
@ -42,11 +38,18 @@ const commonReducer = createReducer( defaultTransient, defaultPersistent, {
|
|||
[ ACTION_TYPES.SET_PERSISTENT ]: ( state, action ) =>
|
||||
setPersistent( state, action ),
|
||||
|
||||
[ ACTION_TYPES.HYDRATE ]: ( state, payload ) =>
|
||||
setPersistent( state, {
|
||||
...payload.data,
|
||||
flags: payload.flags,
|
||||
} ),
|
||||
[ ACTION_TYPES.HYDRATE ]: ( state, payload ) => {
|
||||
const newState = setPersistent( state, payload.data );
|
||||
|
||||
if ( payload.wooSettings ) {
|
||||
newState.wooSettings = {
|
||||
...newState.wooSettings,
|
||||
...payload.wooSettings,
|
||||
};
|
||||
}
|
||||
|
||||
return newState;
|
||||
},
|
||||
} );
|
||||
|
||||
export default commonReducer;
|
||||
|
|
|
@ -16,6 +16,10 @@ export const persistentData = ( state ) => {
|
|||
};
|
||||
|
||||
export const transientData = ( state ) => {
|
||||
const { data, ...transientState } = getState( state );
|
||||
const { data, wooSettings, ...transientState } = getState( state ); // ← extract the wooSettings, to ensure they are not part of the "transientState" collection.
|
||||
return transientState || EMPTY_OBJ;
|
||||
};
|
||||
|
||||
export const wooSettings = ( state ) => {
|
||||
return getState( state ).wooSettings || EMPTY_OBJ;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue