mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Axo Block: Improve code comments and fix minor misc bugs
This commit is contained in:
parent
1f3034136e
commit
2436ceb487
29 changed files with 449 additions and 39 deletions
|
@ -3,11 +3,21 @@ import { useDispatch, useSelect } from '@wordpress/data';
|
|||
|
||||
const CHECKOUT_STORE_KEY = 'wc/store/checkout';
|
||||
|
||||
/**
|
||||
* Custom hook to manage address editing states in the checkout process.
|
||||
*
|
||||
* When set to true (default), the shipping and billing address forms are displayed.
|
||||
* When set to false, the address forms are hidden and the user can only view the address details (card view).
|
||||
*
|
||||
* @return {Object} An object containing address editing states and setter functions.
|
||||
*/
|
||||
export const useAddressEditing = () => {
|
||||
// Select address editing states from the checkout store
|
||||
const { isEditingShippingAddress, isEditingBillingAddress } = useSelect(
|
||||
( select ) => {
|
||||
const store = select( CHECKOUT_STORE_KEY );
|
||||
return {
|
||||
// Default to true if the getter function doesn't exist
|
||||
isEditingShippingAddress: store.getEditingShippingAddress
|
||||
? store.getEditingShippingAddress()
|
||||
: true,
|
||||
|
@ -19,9 +29,11 @@ export const useAddressEditing = () => {
|
|||
[]
|
||||
);
|
||||
|
||||
// Get dispatch functions to update address editing states
|
||||
const { setEditingShippingAddress, setEditingBillingAddress } =
|
||||
useDispatch( CHECKOUT_STORE_KEY );
|
||||
|
||||
// Memoized function to update shipping address editing state
|
||||
const setShippingAddressEditing = useCallback(
|
||||
( isEditing ) => {
|
||||
if ( typeof setEditingShippingAddress === 'function' ) {
|
||||
|
@ -31,6 +43,7 @@ export const useAddressEditing = () => {
|
|||
[ setEditingShippingAddress ]
|
||||
);
|
||||
|
||||
// Memoized function to update billing address editing state
|
||||
const setBillingAddressEditing = useCallback(
|
||||
( isEditing ) => {
|
||||
if ( typeof setEditingBillingAddress === 'function' ) {
|
||||
|
@ -40,6 +53,7 @@ export const useAddressEditing = () => {
|
|||
[ setEditingBillingAddress ]
|
||||
);
|
||||
|
||||
// Return an object with address editing states and setter functions
|
||||
return {
|
||||
isEditingShippingAddress,
|
||||
isEditingBillingAddress,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue