Skip to content

Commit

Permalink
fix: incorporated feedback comments and update the code
Browse files Browse the repository at this point in the history
  • Loading branch information
zubair-ce07 committed Apr 16, 2024
1 parent d5a059c commit 68b7c59
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
20 changes: 16 additions & 4 deletions src/payment/PaymentPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,25 @@ class PaymentPage extends React.Component {
}

componentDidMount() {
const sku = localStorage.getItem('sku');
const rawSkus = localStorage.getItem('skus');
const skus = JSON.parse(rawSkus);

// Check if SKU is not null
if (sku !== null) {
const paymentPage = `${getConfig().ECOMMERCE_BASE_URL}/basket/add/?sku=${sku}`;
if (skus !== null) {
const baseURL = getConfig().ECOMMERCE_BASE_URL;

// Constructing the URL with the sku parameters
let paymentPage = `${baseURL}/basket/add/?`;
// Appending each sku value to the URL
Object.values(skus).forEach(sku => { paymentPage += `sku=${sku}&`; });
// for (const sku of skus) {
// paymentPage += `sku=${sku}&`;
// }
// Removing the extra '&' character at the end
paymentPage = paymentPage.slice(0, -1);
// const paymentPage = `${getConfig().ECOMMERCE_BASE_URL}/basket/add/?sku=${sku}`;
window.location.href = paymentPage;
localStorage.removeItem('sku');
localStorage.removeItem('skus');
} else {
this.props.fetchBasket();
sendPageEvent();
Expand Down
8 changes: 8 additions & 0 deletions src/payment/checkout/Checkout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class Checkout extends React.Component {
);

this.props.submitPayment({ method: 'paypal' });

const { products } = this.props;

Check failure on line 51 in src/payment/checkout/Checkout.jsx

View workflow job for this annotation

GitHub Actions / tests

'products' is missing in props validation
const skus = [];

for (const product of products){

Check failure on line 54 in src/payment/checkout/Checkout.jsx

View workflow job for this annotation

GitHub Actions / tests

iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations

Check failure on line 54 in src/payment/checkout/Checkout.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing space before opening brace
skus.push(product.sku)

Check failure on line 55 in src/payment/checkout/Checkout.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon
}
localStorage.setItem('skus', JSON.stringify(skus));
};

// eslint-disable-next-line react/no-unused-class-component-methods
Expand Down
3 changes: 0 additions & 3 deletions src/payment/data/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ const basket = (state = basketInitialState, action = null) => {
};

case BASKET_DATA_RECEIVED:
if (action.payload.products && action.payload.products.length > 0) {
localStorage.setItem('sku', action.payload.products[0].sku);
}
return { ...state, ...action.payload };

case BASKET_PROCESSING: return {
Expand Down

0 comments on commit 68b7c59

Please sign in to comment.