mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
✨ Add new hook for production ISU login
This commit is contained in:
parent
a8f12c63fa
commit
05c1978f0d
3 changed files with 38 additions and 1 deletions
|
@ -34,8 +34,12 @@ const useHooks = () => {
|
|||
setProducts,
|
||||
} = useDispatch( STORE_NAME );
|
||||
|
||||
// Read-only flags.
|
||||
// Read-only flags and derived state.
|
||||
const flags = useSelect( ( select ) => select( STORE_NAME ).flags(), [] );
|
||||
const determineProducts = useSelect(
|
||||
( select ) => select( STORE_NAME ).determineProducts(),
|
||||
[]
|
||||
);
|
||||
|
||||
// Transient accessors.
|
||||
const isReady = useTransient( 'isReady' );
|
||||
|
@ -80,6 +84,7 @@ const useHooks = () => {
|
|||
);
|
||||
return savePersistent( setProducts, validProducts );
|
||||
},
|
||||
determineProducts,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -123,3 +128,9 @@ export const useNavigationState = () => {
|
|||
business,
|
||||
};
|
||||
};
|
||||
|
||||
export const useDetermineProducts = () => {
|
||||
const { determineProducts } = useHooks();
|
||||
|
||||
return determineProducts;
|
||||
};
|
||||
|
|
|
@ -23,3 +23,18 @@ export const transientData = ( state ) => {
|
|||
export const flags = ( state ) => {
|
||||
return getState( state ).flags || EMPTY_OBJ;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the products that we use for the production login link in the last onboarding step.
|
||||
*
|
||||
* This selector does not return state-values, but uses the state to derive the products-array
|
||||
* that should be returned.
|
||||
*
|
||||
* @param {{}} state
|
||||
* @return {string[]} The ISU products, based on choices made in the onboarding wizard.
|
||||
*/
|
||||
export const determineProducts = ( state ) => {
|
||||
const derivedProducts = [];
|
||||
|
||||
return derivedProducts;
|
||||
};
|
||||
|
|
|
@ -82,6 +82,17 @@ export const useSandboxConnection = () => {
|
|||
};
|
||||
};
|
||||
|
||||
export const useProductionConnection = () => {
|
||||
const { connectToProduction } = CommonHooks.useProduction();
|
||||
const products = OnboardingHooks.useDetermineProducts();
|
||||
const handleProductionConnect = useConnectionAttempt(
|
||||
() => connectToProduction( products ),
|
||||
MESSAGES.PRODUCTION_ERROR
|
||||
);
|
||||
|
||||
return { handleProductionConnect };
|
||||
};
|
||||
|
||||
export const useManualConnection = () => {
|
||||
const { handleError, handleSuccess, createErrorNotice } =
|
||||
useConnectionBase();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue