2021-07-22 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { createContext, useContext } from '@wordpress/element';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context consumed by inner blocks.
|
|
|
|
*/
|
|
|
|
export type CheckoutBlockContextProps = {
|
|
|
|
allowCreateAccount: boolean;
|
|
|
|
showCompanyField: boolean;
|
|
|
|
showApartmentField: boolean;
|
|
|
|
showPhoneField: boolean;
|
|
|
|
requireCompanyField: boolean;
|
|
|
|
requirePhoneField: boolean;
|
2021-10-15 09:48:57 +00:00
|
|
|
showOrderNotes: boolean;
|
|
|
|
showPolicyLinks: boolean;
|
|
|
|
showReturnToCart: boolean;
|
|
|
|
cartPageId: number;
|
|
|
|
showRateAfterTaxName: boolean;
|
2021-07-22 11:03:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type CheckoutBlockControlsContextProps = {
|
|
|
|
addressFieldControls: () => JSX.Element | null;
|
|
|
|
accountControls: () => JSX.Element | null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const CheckoutBlockContext = createContext< CheckoutBlockContextProps >(
|
|
|
|
{
|
|
|
|
allowCreateAccount: false,
|
|
|
|
showCompanyField: false,
|
|
|
|
showApartmentField: false,
|
|
|
|
showPhoneField: false,
|
|
|
|
requireCompanyField: false,
|
|
|
|
requirePhoneField: false,
|
2021-10-15 09:48:57 +00:00
|
|
|
showOrderNotes: true,
|
|
|
|
showPolicyLinks: true,
|
|
|
|
showReturnToCart: true,
|
|
|
|
cartPageId: 0,
|
|
|
|
showRateAfterTaxName: false,
|
2021-07-22 11:03:00 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export const CheckoutBlockControlsContext = createContext<
|
|
|
|
CheckoutBlockControlsContextProps
|
|
|
|
>( {
|
|
|
|
addressFieldControls: () => null,
|
|
|
|
accountControls: () => null,
|
|
|
|
} );
|
|
|
|
|
|
|
|
export const useCheckoutBlockContext = (): CheckoutBlockContextProps => {
|
|
|
|
return useContext( CheckoutBlockContext );
|
|
|
|
};
|
|
|
|
|
|
|
|
export const useCheckoutBlockControlsContext = (): CheckoutBlockControlsContextProps => {
|
|
|
|
return useContext( CheckoutBlockControlsContext );
|
|
|
|
};
|