Skip to content

Commit

Permalink
Update checkout script
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarMerino committed Dec 2, 2024
1 parent 509b954 commit 10e8ed8
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions scripts/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ export function getCartAddress(checkoutData, type) {
company: address?.company,
countryCode: address.country?.value,
customAttributes: address.customAttributes,
fax: address.fax,
firstName: address.firstName,
lastName: address.lastName,
middleName: address.middleName,
postcode: address.postCode,
prefix: address.prefix,
region: {
regionCode: address.region?.code,
regionId: address.region?.id,
},
street: address.street,
suffix: address.suffix,
telephone: address.telephone,
vatId: address.vatId,
};
Expand Down Expand Up @@ -59,29 +63,34 @@ const transformAddressFormValues = (data) => {
company: data?.company,
countryCode: data.countryCode,
customAttributes,
// TODO fax
fax: data.fax,
firstName: data.firstName,
lastName: data.lastName,
// TODO middleName
middleName: data.middleName,
postcode: data.postcode,
// TODO prefix
prefix: data.prefix,
region: data?.region?.regionCode,
regionId: data?.region?.regionId,
street: data.street,
// TODO suffix
suffix: data.suffix,
telephone: data.telephone,
vatId: data.vatId,
saveInAddressBook: data.saveAddressBook,
},
};
};

let ongoingSetAddressCalls = 0;
export function setAddressOnCart({ api, debounceMs = 0, placeOrderBtn = null }) {
const debouncedApi = debounce((address) => {
ongoingSetAddressCalls += 1;
api(address)
.catch(console.error)
.finally(() => {
placeOrderBtn?.setProps((prev) => ({ ...prev, disabled: false }));
ongoingSetAddressCalls -= 1;
if (ongoingSetAddressCalls === 0) {
placeOrderBtn?.setProps((prev) => ({ ...prev, disabled: false }));
}
});
}, debounceMs);

Expand Down

0 comments on commit 10e8ed8

Please sign in to comment.