Axo Blocks: Migrate console logs to the Axo log function

This commit is contained in:
Daniel Dudzic 2024-09-26 12:47:04 +02:00
parent b44dd0a8d9
commit 70676468b8
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
15 changed files with 82 additions and 94 deletions

View file

@ -1,24 +1,26 @@
import { dispatch } from '@wordpress/data';
import { log } from '../../../../ppcp-axo/resources/js/Helper/Debug';
export const snapshotFields = ( shippingAddress, billingAddress ) => {
console.log( 'Attempting to snapshot fields' );
if ( ! shippingAddress || ! billingAddress ) {
console.warn( 'Shipping or billing address is missing:', {
shippingAddress,
billingAddress,
} );
log(
`Shipping or billing address is missing: ${ JSON.stringify( {
shippingAddress,
billingAddress,
} ) }`,
'warn'
);
}
const originalData = { shippingAddress, billingAddress };
console.log( 'Snapshot data:', originalData );
log( `Snapshot data: ${ JSON.stringify( originalData ) }` );
try {
localStorage.setItem(
'axoOriginalCheckoutFields',
JSON.stringify( originalData )
);
console.log( 'Original fields saved to localStorage', originalData );
} catch ( error ) {
console.error( 'Error saving to localStorage:', error );
log( `Error saving to localStorage: ${ error }`, 'error' );
}
};
@ -26,47 +28,41 @@ export const restoreOriginalFields = (
updateShippingAddress,
updateBillingAddress
) => {
console.log( 'Attempting to restore original fields' );
log( 'Attempting to restore original fields' );
let savedData;
try {
savedData = localStorage.getItem( 'axoOriginalCheckoutFields' );
console.log( 'Data retrieved from localStorage:', savedData );
log(
`Data retrieved from localStorage: ${ JSON.stringify( savedData ) }`
);
} catch ( error ) {
console.error( 'Error retrieving from localStorage:', error );
log( `Error retrieving from localStorage: ${ error }`, 'error' );
}
if ( savedData ) {
try {
const parsedData = JSON.parse( savedData );
console.log( 'Parsed data:', parsedData );
if ( parsedData.shippingAddress ) {
console.log(
'Restoring shipping address:',
parsedData.shippingAddress
);
updateShippingAddress( parsedData.shippingAddress );
} else {
console.warn( 'No shipping address found in saved data' );
log( `No shipping address found in saved data`, 'warn' );
}
if ( parsedData.billingAddress ) {
console.log(
'Restoring billing address:',
parsedData.billingAddress
log(
`Restoring billing address:
${ JSON.stringify( parsedData.billingAddress ) }`
);
updateBillingAddress( parsedData.billingAddress );
} else {
console.warn( 'No billing address found in saved data' );
log( 'No billing address found in saved data', 'warn' );
}
console.log(
'Original fields restored from localStorage',
parsedData
);
} catch ( error ) {
console.error( 'Error parsing saved data:', error );
log( `Error parsing saved data: ${ error }` );
}
} else {
console.warn(
'No data found in localStorage under axoOriginalCheckoutFields'
log(
'No data found in localStorage under axoOriginalCheckoutFields',
'warn'
);
}
};
@ -78,9 +74,10 @@ export const populateWooFields = (
) => {
const CHECKOUT_STORE_KEY = 'wc/store/checkout';
console.log(
'Populating WooCommerce fields with profile data:',
profileData
log(
`Populating WooCommerce fields with profile data: ${ JSON.stringify(
profileData
) }`
);
const checkoutDispatch = dispatch( CHECKOUT_STORE_KEY );
@ -107,7 +104,11 @@ export const populateWooFields = (
phone: phoneNumber.nationalNumber,
};
console.log( 'Setting WooCommerce shipping address:', shippingAddress );
log(
`Setting WooCommerce shipping address: ${ JSON.stringify(
shippingAddress
) }`
);
setWooShippingAddress( shippingAddress );
// Save billing address.
@ -124,7 +125,11 @@ export const populateWooFields = (
country: billingData.countryCode,
};
console.log( 'Setting WooCommerce billing address:', billingAddress );
log(
`Setting WooCommerce billing address: ${ JSON.stringify(
billingAddress
) }`
);
setWooBillingAddress( billingAddress );
// Collapse shipping address input fields into the card view.