mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
✨ New state props for client ID and secret
This commit is contained in:
parent
e20a6fdbce
commit
52d04c7347
4 changed files with 57 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
|||
export default {
|
||||
// Transient data.
|
||||
SET_IS_SAVING_ONBOARDING_DETAILS: 'SET_IS_SAVING_ONBOARDING_DETAILS',
|
||||
SET_CLIENT_ID: 'SET_CLIENT_ID',
|
||||
SET_CLIENT_SECRET: 'SET_CLIENT_SECRET',
|
||||
|
||||
// Persistent data.
|
||||
SET_ONBOARDING_DETAILS: 'SET_ONBOARDING_DETAILS',
|
||||
|
|
|
@ -68,6 +68,32 @@ export const setIsSaving = ( isSaving ) => {
|
|||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Non-persistent. Changes the "client ID" value.
|
||||
*
|
||||
* @param {string} clientId
|
||||
* @return {{type: string, clientId}} The action.
|
||||
*/
|
||||
export const setClientId = ( clientId ) => {
|
||||
return {
|
||||
type: ACTION_TYPES.SET_CLIENT_ID,
|
||||
clientId,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Non-persistent. Changes the "client secret" value.
|
||||
*
|
||||
* @param {string} clientSecret
|
||||
* @return {{type: string, clientSecret}} The action.
|
||||
*/
|
||||
export const setClientSecret = ( clientSecret ) => {
|
||||
return {
|
||||
type: ACTION_TYPES.SET_CLIENT_SECRET,
|
||||
clientSecret,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Saves the persistent details to the WP database.
|
||||
*
|
||||
|
|
|
@ -7,6 +7,8 @@ export const useOnboardingDetails = () => {
|
|||
setSandboxMode,
|
||||
setManualConnectionMode,
|
||||
persist,
|
||||
setClientId,
|
||||
setClientSecret,
|
||||
} = useDispatch( STORE_NAME );
|
||||
|
||||
// Transient accessors.
|
||||
|
@ -14,6 +16,15 @@ export const useOnboardingDetails = () => {
|
|||
return select( STORE_NAME ).getTransientData().isSaving;
|
||||
}, [] );
|
||||
|
||||
const clientId = useSelect( ( select ) => {
|
||||
return select( STORE_NAME ).getTransientData().clientId;
|
||||
}, [] );
|
||||
|
||||
const clientSecret = useSelect( ( select ) => {
|
||||
return select( STORE_NAME ).getTransientData().clientSecret;
|
||||
}, [] );
|
||||
|
||||
// Persistent accessors.
|
||||
const onboardingStep = useSelect( ( select ) => {
|
||||
return select( STORE_NAME ).getPersistentData().step || 0;
|
||||
}, [] );
|
||||
|
@ -36,6 +47,10 @@ export const useOnboardingDetails = () => {
|
|||
isSaving,
|
||||
isSandboxMode,
|
||||
isManualConnectionMode,
|
||||
clientId,
|
||||
setClientId,
|
||||
clientSecret,
|
||||
setClientSecret,
|
||||
setOnboardingStep: ( step ) =>
|
||||
setDetailAndPersist( setOnboardingStep, step ),
|
||||
setSandboxMode: ( state ) =>
|
||||
|
|
|
@ -2,6 +2,8 @@ import ACTION_TYPES from './action-types';
|
|||
|
||||
const defaultState = {
|
||||
isSaving: false,
|
||||
clientId: '',
|
||||
clientSecret: '',
|
||||
data: {
|
||||
step: 0,
|
||||
useSandbox: false,
|
||||
|
@ -21,6 +23,18 @@ export const onboardingReducer = (
|
|||
isSaving: action.isSaving,
|
||||
};
|
||||
|
||||
case ACTION_TYPES.SET_CLIENT_ID:
|
||||
return {
|
||||
...state,
|
||||
clientId: action.clientId,
|
||||
};
|
||||
|
||||
case ACTION_TYPES.SET_CLIENT_SECRET:
|
||||
return {
|
||||
...state,
|
||||
clientSecret: action.clientSecret,
|
||||
};
|
||||
|
||||
// Persistent data.
|
||||
case ACTION_TYPES.SET_ONBOARDING_DETAILS:
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue