From c9f1681daad17d1ab1c6900d8e4352f1387da359 Mon Sep 17 00:00:00 2001 From: b3aton Date: Mon, 6 Mar 2023 16:41:50 +0800 Subject: [PATCH] fix: sl to cart quantity issues & cantPurchase products tips --- .../shoppingListDetails/components/ReAddToCart.tsx | 5 ++++- .../components/ShoppingDetailFooter.tsx | 11 +++++++++++ apps/storefront/src/shared/service/request/fetch.ts | 11 ++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/apps/storefront/src/pages/shoppingListDetails/components/ReAddToCart.tsx b/apps/storefront/src/pages/shoppingListDetails/components/ReAddToCart.tsx index 89861e29..fa8e6179 100644 --- a/apps/storefront/src/pages/shoppingListDetails/components/ReAddToCart.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/components/ReAddToCart.tsx @@ -283,11 +283,14 @@ export const ReAddToCart = (props: ShoppingProductsProps) => { const quantityNumber = parseInt(`${quantity}`, 10) || 0 if (minQuantity !== 0 && quantityNumber < minQuantity) { product.node.quantity = minQuantity + product.isValid = true } else if (maxQuantity !== 0 && quantityNumber > maxQuantity) { product.node.quantity = maxQuantity + product.isValid = true } if (isStock !== '0' && stock && quantity > stock) { product.node.quantity = stock + product.isValid = true } }) @@ -326,7 +329,7 @@ export const ReAddToCart = (props: ShoppingProductsProps) => { variant="filled" severity="error" > - {allowJuniorPlaceOrder ? `${successProducts} product(s) can\n't checkout, please change the quantity` : `${products.length} product(s) were not added to cart, please change the quantity`} + {allowJuniorPlaceOrder ? `${products.length} product(s) can\n't checkout, please change the quantity` : `${products.length} product(s) were not added to cart, please change the quantity`} { try { const skus: string[] = [] + let cantPurchase: string = '' + checkedArr.forEach((item: ProductsProps) => { const { node, } = item + if (node.productsSearch.availability === 'disabled') { + cantPurchase += `${node.variantSku},` + } + skus.push(node.variantSku) }) + if (cantPurchase) { + snackbar.error(`Sku(s): ${cantPurchase.slice(0, -1)} unavailable for purchasing, please uncheck.`) + return + } + if (skus.length === 0) { snackbar.error(allowJuniorPlaceOrder ? 'Please select at least one item to checkout' : 'Please select at least one item to add to cart') return diff --git a/apps/storefront/src/shared/service/request/fetch.ts b/apps/storefront/src/shared/service/request/fetch.ts index 00fe24fe..040c4bce 100644 --- a/apps/storefront/src/shared/service/request/fetch.ts +++ b/apps/storefront/src/shared/service/request/fetch.ts @@ -9,9 +9,18 @@ import { const originFetch = window.fetch +const responseResult = (path: string, res: any, resolve: any, init: any) => { + if (path.includes('current.jwt')) return res.text() + console.log(init) + if (init.method === 'DELETE') { + resolve() + } + return res.json() +} + function b3Fetch(path: string, init: any, type?: string, customMessage = false) { return new Promise((resolve, reject) => { - originFetch(path, init).then((res: Response) => (path.includes('current.jwt') ? res.text() : res.json())).then(async (res) => { + originFetch(path, init).then((res: Response) => responseResult(path, res, resolve, init)).then(async (res) => { if (res?.code === 500) { const data = res?.data || {} const message = data.errMsg || res.message || ''