mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
♻️ MInor reorganization of code
This commit is contained in:
parent
4944c2427b
commit
164af7f515
2 changed files with 25 additions and 27 deletions
|
@ -16,19 +16,6 @@ export const setIsSaving = ( isSaving ) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Persistent.Set the "onboarding completed" flag which shows or hides the wizard.
|
|
||||||
*
|
|
||||||
* @param {boolean} completed
|
|
||||||
* @return {{type: string, payload}} The action.
|
|
||||||
*/
|
|
||||||
export const setCompleted = ( completed ) => {
|
|
||||||
return {
|
|
||||||
type: ACTION_TYPES.SET_ONBOARDING_COMPLETED,
|
|
||||||
completed,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persistent. Set the full onboarding details, usually during app initialization.
|
* Persistent. Set the full onboarding details, usually during app initialization.
|
||||||
*
|
*
|
||||||
|
@ -42,6 +29,19 @@ export const setOnboardingDetails = ( payload ) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persistent.Set the "onboarding completed" flag which shows or hides the wizard.
|
||||||
|
*
|
||||||
|
* @param {boolean} completed
|
||||||
|
* @return {{type: string, payload}} The action.
|
||||||
|
*/
|
||||||
|
export const setCompleted = ( completed ) => {
|
||||||
|
return {
|
||||||
|
type: ACTION_TYPES.SET_ONBOARDING_COMPLETED,
|
||||||
|
completed,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persistent. Sets the onboarding wizard to a new step.
|
* Persistent. Sets the onboarding wizard to a new step.
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,10 +3,9 @@ import { STORE_NAME } from '../constants';
|
||||||
|
|
||||||
export const useOnboardingDetails = () => {
|
export const useOnboardingDetails = () => {
|
||||||
const {
|
const {
|
||||||
setOnboardingStep,
|
persist,
|
||||||
setSandboxMode,
|
setSandboxMode,
|
||||||
setManualConnectionMode,
|
setManualConnectionMode,
|
||||||
persist,
|
|
||||||
setClientId,
|
setClientId,
|
||||||
setClientSecret,
|
setClientSecret,
|
||||||
} = useDispatch( STORE_NAME );
|
} = useDispatch( STORE_NAME );
|
||||||
|
@ -25,10 +24,6 @@ export const useOnboardingDetails = () => {
|
||||||
return select( STORE_NAME ).getPersistentData().clientSecret;
|
return select( STORE_NAME ).getPersistentData().clientSecret;
|
||||||
}, [] );
|
}, [] );
|
||||||
|
|
||||||
const onboardingStep = useSelect( ( select ) => {
|
|
||||||
return select( STORE_NAME ).getPersistentData().step || 0;
|
|
||||||
}, [] );
|
|
||||||
|
|
||||||
const isSandboxMode = useSelect( ( select ) => {
|
const isSandboxMode = useSelect( ( select ) => {
|
||||||
return select( STORE_NAME ).getPersistentData().useSandbox;
|
return select( STORE_NAME ).getPersistentData().useSandbox;
|
||||||
}, [] );
|
}, [] );
|
||||||
|
@ -43,7 +38,6 @@ export const useOnboardingDetails = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
onboardingStep,
|
|
||||||
isSaving,
|
isSaving,
|
||||||
isSandboxMode,
|
isSandboxMode,
|
||||||
isManualConnectionMode,
|
isManualConnectionMode,
|
||||||
|
@ -52,8 +46,6 @@ export const useOnboardingDetails = () => {
|
||||||
clientSecret,
|
clientSecret,
|
||||||
setClientSecret: ( value ) =>
|
setClientSecret: ( value ) =>
|
||||||
setDetailAndPersist( setClientSecret, value ),
|
setDetailAndPersist( setClientSecret, value ),
|
||||||
setOnboardingStep: ( step ) =>
|
|
||||||
setDetailAndPersist( setOnboardingStep, step ),
|
|
||||||
setSandboxMode: ( state ) =>
|
setSandboxMode: ( state ) =>
|
||||||
setDetailAndPersist( setSandboxMode, state ),
|
setDetailAndPersist( setSandboxMode, state ),
|
||||||
setManualConnectionMode: ( state ) =>
|
setManualConnectionMode: ( state ) =>
|
||||||
|
@ -62,9 +54,10 @@ export const useOnboardingDetails = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useOnboardingStep = () => {
|
export const useOnboardingStep = () => {
|
||||||
const { setOnboardingStep, setCompleted } = useDispatch( STORE_NAME );
|
const { persist, setOnboardingStep, setCompleted } =
|
||||||
|
useDispatch( STORE_NAME );
|
||||||
|
|
||||||
const onboardingStep = useSelect( ( select ) => {
|
const step = useSelect( ( select ) => {
|
||||||
return select( STORE_NAME ).getPersistentData().step || 0;
|
return select( STORE_NAME ).getPersistentData().step || 0;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -72,10 +65,15 @@ export const useOnboardingStep = () => {
|
||||||
return select( STORE_NAME ).getPersistentData().completed;
|
return select( STORE_NAME ).getPersistentData().completed;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
const setDetailAndPersist = async ( setter, value ) => {
|
||||||
|
setter( value );
|
||||||
|
await persist();
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
onboardingStep,
|
step,
|
||||||
setOnboardingStep: ( step ) => setOnboardingStep( step ),
|
setStep: ( value ) => setDetailAndPersist( setOnboardingStep, value ),
|
||||||
completed,
|
completed,
|
||||||
setCompleted: ( state ) => setCompleted( state ),
|
setCompleted: ( state ) => setDetailAndPersist( setCompleted, state ),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue