Axo Block: Improve code comments and fix minor misc bugs

This commit is contained in:
Daniel Dudzic 2024-10-03 14:09:12 +02:00
parent 1f3034136e
commit 2436ceb487
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
29 changed files with 449 additions and 39 deletions

View file

@ -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,