Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jrlarano committed May 24, 2024
1 parent 4132e82 commit b670fc1
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/kits/core-ui/components/common/shopping-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ const ShoppingList = ({template, version}) => {

const updateQuantityHandler = (
productEl: HTMLElement,
productIndex: number,
action: 'plus' | 'minus'
) => {
const {localeCode} = translations;
const index = Number(productEl.dataset.id);
const priceEl = productEl.querySelector<HTMLElement>(
'.sgn-shopping-list-content-price'
);
Expand All @@ -403,7 +403,7 @@ const ShoppingList = ({template, version}) => {
quantityTxt.value =
action === 'plus' ? `${++quantity}` : `${--quantity}`;

storedPublicationOffers[productIndex].quantity = quantityTxt.value;
storedPublicationOffers[index].quantity = quantityTxt.value;
clientLocalStorage.setWithEvent(
'publication-saved-offers',
storedPublicationOffers,
Expand All @@ -412,17 +412,17 @@ const ShoppingList = ({template, version}) => {

if (
priceEl &&
storedPublicationOffers[productIndex]?.pricing?.price &&
storedPublicationOffers[index]?.pricing?.price &&
quantity
) {
const priceNum =
storedPublicationOffers[productIndex]?.pricing?.price *
Number(storedPublicationOffers[productIndex].quantity || 1);
storedPublicationOffers[index]?.pricing?.price *
Number(storedPublicationOffers[index].quantity || 1);

priceEl.innerHTML = formatPrice(
priceNum,
localeCode,
storedPublicationOffers[productIndex]?.pricing?.currency
storedPublicationOffers[index]?.pricing?.currency
);
}
}
Expand All @@ -434,7 +434,6 @@ const ShoppingList = ({template, version}) => {
);

productEls.forEach((productEl: HTMLElement) => {
const index = Number(productEl.dataset.id);
const minusBtn = productEl.querySelector<HTMLElement>(
'.sgn-offer-product-quantity-minus'
);
Expand All @@ -443,10 +442,10 @@ const ShoppingList = ({template, version}) => {
);

plusBtn?.addEventListener('click', () =>
updateQuantityHandler(productEl, index, 'plus')
updateQuantityHandler(productEl, 'plus')
);
minusBtn?.addEventListener('click', () =>
updateQuantityHandler(productEl, index, 'minus')
updateQuantityHandler(productEl, 'minus')
);
});
};
Expand Down

0 comments on commit b670fc1

Please sign in to comment.