From 0c58a7a89759307bb1b8c7f49a007cc73228eb02 Mon Sep 17 00:00:00 2001 From: "Brian.Jiang2021" Date: Wed, 26 Apr 2023 11:45:28 +0800 Subject: [PATCH] fix: submit quote error https://bigc-b2b.atlassian.net/browse/BUN-1022 --- .../storefront/src/pages/quote/QuoteDraft.tsx | 101 ++++-------------- 1 file changed, 20 insertions(+), 81 deletions(-) diff --git a/apps/storefront/src/pages/quote/QuoteDraft.tsx b/apps/storefront/src/pages/quote/QuoteDraft.tsx index 3f75978e6..4826e3cf8 100644 --- a/apps/storefront/src/pages/quote/QuoteDraft.tsx +++ b/apps/storefront/src/pages/quote/QuoteDraft.tsx @@ -18,8 +18,6 @@ import { createQuote, getB2BCustomerAddresses, getBCCustomerAddresses, - searchB2BProducts, - searchBcProducts, } from '@/shared/service/b2b' import { AddressItemType, BCAddressItemType } from '@/types/address' import { @@ -31,11 +29,7 @@ import { storeHash, } from '@/utils' -import { - conversionProductsList, - getProductOptionsFields, - ListItemProps, -} from '../../utils/b3Product/shared/config' +import { getProductOptionsFields } from '../../utils/b3Product/shared/config' import { convertBCToB2BAddress } from '../address/shared/config' import AddToQuote from './components/AddToQuote' @@ -116,14 +110,10 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) { const navigate = useNavigate() - // const nextPath = B3SStorage.get('nextPath') - const [isMobile] = useMobile() const [loading, setLoading] = useState(false) - const [isRequestLoading, setIsRequestLoading] = useState(false) - const [isEdit, setEdit] = useState(false) const [addressList, setAddressList] = useState([]) @@ -295,53 +285,7 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) { setEdit(true) } - const { currency_code: currencyCode } = getDefaultCurrencyInfo() - - const handleGetProductsById = async (listProducts: ListItemProps[]) => { - if (listProducts.length > 0) { - const productIds: number[] = [] - listProducts.forEach((item) => { - const { node } = item - if (!productIds.includes(node.productId)) { - productIds.push(node.productId) - } - }) - - const getProducts = isB2BUser ? searchB2BProducts : searchBcProducts - - try { - const { productsSearch } = await getProducts({ - productIds, - currencyCode, - companyId: companyB2BId, - }) - - const newProductsSearch = conversionProductsList(productsSearch) - - listProducts.forEach((item) => { - const { node } = item - - const productInfo = newProductsSearch.find( - (search: CustomFieldItems) => { - const { id: productId } = search - - return +node.productId === +productId - } - ) - - node.productsSearch = productInfo || {} - }) - - return listProducts - } catch (err: any) { - snackbar.error(err) - } - } - return undefined - } - const getQuoteTableDetails = async (params: CustomFieldItems) => { - setIsRequestLoading(true) const quoteDraftAllList = B3LStorage.get('b2bQuoteDraftList') || [] const startIndex = +params.offset @@ -356,8 +300,6 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) { } const list = quoteDraftAllList.slice(startIndex, endIndex) - await handleGetProductsById(list) - list.forEach((item: any) => { let additionalCalculatedPriceTax = 0 let additionalCalculatedPrice = 0 @@ -373,8 +315,6 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) { item.node.tax = +item.node.tax + additionalCalculatedPriceTax }) - setIsRequestLoading(false) - return { edges: list, totalCount: quoteDraftAllList.length, @@ -459,6 +399,7 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) { const emailAddress = B3SStorage.get('B3EmailAddress') const note = info?.note || '' + const newNote = note.trim().replace(/[\r\n]/g, '\\n') const perfectAddress = (address: CustomFieldStringItems) => { const newAddress = { @@ -546,7 +487,7 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) { const data = { // notes: note, - message: note, + message: newNote, legalTerms: '', totalAmount: allPrice.toFixed(2), grandTotal: allPrice.toFixed(2), @@ -783,25 +724,23 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) { alignItems: 'flex-start', }} > - - - - - + + +