From afad01ba520c3f506fa14a3291454769faadf125 Mon Sep 17 00:00:00 2001 From: "Brian.Jiang2021" Date: Thu, 27 Apr 2023 10:37:23 +0800 Subject: [PATCH] fix: fix bugs --- apps/storefront/src/App.tsx | 8 +++--- .../src/components/loadding/B3PageMask.tsx | 5 ++++ .../pages/accountSetting/AccountSetting.tsx | 4 ++- .../quote/components/QuoteDetailFooter.tsx | 5 ++-- .../src/pages/quote/components/QuoteTable.tsx | 25 ++++++++++++++++++- .../src/utils/b3Product/b3TaxRate.ts | 4 ++- 6 files changed, 40 insertions(+), 11 deletions(-) diff --git a/apps/storefront/src/App.tsx b/apps/storefront/src/App.tsx index d7ac7e05..d4b998e1 100644 --- a/apps/storefront/src/App.tsx +++ b/apps/storefront/src/App.tsx @@ -157,11 +157,9 @@ export default function App() { isAgenting, } - if (!customerId || isRelogin) { - const info = await getCurrentCustomerInfo(dispatch) - if (info) { - userInfo.role = info?.role - } + const info = await getCurrentCustomerInfo(dispatch) + if (info) { + userInfo.role = info?.role } // background login enter judgment and refresh diff --git a/apps/storefront/src/components/loadding/B3PageMask.tsx b/apps/storefront/src/components/loadding/B3PageMask.tsx index ffc1766a..73c2d82e 100644 --- a/apps/storefront/src/components/loadding/B3PageMask.tsx +++ b/apps/storefront/src/components/loadding/B3PageMask.tsx @@ -14,6 +14,11 @@ export function B3PageMask() { } export const showPageMask = (dispatch: DispatchProps, isShow: boolean) => { + const b2bStyleElement = document.getElementById('b2b-account-page-hide-body') + if (b2bStyleElement) { + b2bStyleElement.innerHTML = '' + } + dispatch({ type: 'common', payload: { diff --git a/apps/storefront/src/pages/accountSetting/AccountSetting.tsx b/apps/storefront/src/pages/accountSetting/AccountSetting.tsx index 6fe32d63..d45005b3 100644 --- a/apps/storefront/src/pages/accountSetting/AccountSetting.tsx +++ b/apps/storefront/src/pages/accountSetting/AccountSetting.tsx @@ -146,7 +146,9 @@ function AccountSetting() { const { accountB2BFormFields, passwordModified } = getAccountSettingFiles(12) - const contactInformation = accountFormFields.contactInformation.filter( + const contactInformation = ( + accountFormFields?.contactInformation || [] + ).filter( (item: Partial) => item.fieldId !== 'field_email_marketing_newsletter' ) diff --git a/apps/storefront/src/pages/quote/components/QuoteDetailFooter.tsx b/apps/storefront/src/pages/quote/components/QuoteDetailFooter.tsx index 417baed1..a18f1caa 100644 --- a/apps/storefront/src/pages/quote/components/QuoteDetailFooter.tsx +++ b/apps/storefront/src/pages/quote/components/QuoteDetailFooter.tsx @@ -3,7 +3,6 @@ import { Box } from '@mui/material' import { CustomButton } from '@/components' import { useMobile } from '@/hooks' import { b2bQuoteCheckout, bcQuoteCheckout } from '@/shared/service/b2b' -import { snackbar } from '@/utils' interface QuoteDetailFooterProps { quoteId: string @@ -40,8 +39,8 @@ function QuoteDetailFooter(props: QuoteDetailFooterProps) { } = res window.location.href = checkoutUrl - } catch (err: any) { - snackbar.error(err) + } catch (err) { + console.error(err) } } diff --git a/apps/storefront/src/pages/quote/components/QuoteTable.tsx b/apps/storefront/src/pages/quote/components/QuoteTable.tsx index 06a0ef96..194aa952 100644 --- a/apps/storefront/src/pages/quote/components/QuoteTable.tsx +++ b/apps/storefront/src/pages/quote/components/QuoteTable.tsx @@ -1,6 +1,7 @@ import { forwardRef, Ref, useImperativeHandle, useRef, useState } from 'react' import { Delete, Edit } from '@mui/icons-material' import { Box, styled, TextField, Typography } from '@mui/material' +import { ceil } from 'lodash' import { B3PaginationTable } from '@/components/table/B3PaginationTable' import { TableColumnItem } from '@/components/table/B3Table' @@ -111,6 +112,7 @@ function QuoteTable(props: ShoppingDetailTableProps, ref: Ref) { isB2BUser, updateSummary, } = props + const quoteProductQtyMaxLimit = 1000000 const paginationTableRef = useRef(null) @@ -151,6 +153,24 @@ function QuoteTable(props: ShoppingDetailTableProps, ref: Ref) { updateSummary() } + const handleCheckProductQty = ( + id: number | string, + value: number | string + ) => { + let newQty = ceil(+value) + if (newQty === +value && newQty >= 1 && newQty <= quoteProductQtyMaxLimit) + return + + if (value < 1) { + newQty = 1 + } + + if (value > quoteProductQtyMaxLimit) { + newQty = quoteProductQtyMaxLimit + } + handleUpdateProductQty(id, newQty) + } + const handleDeleteClick = (id: number | string) => { const quoteDraftAllList = B3LStorage.get('b2bQuoteDraftList') || [] @@ -398,7 +418,10 @@ function QuoteTable(props: ShoppingDetailTableProps, ref: Ref) { pattern: '[0-9]*', }} onChange={(e) => { - handleUpdateProductQty(row.id, e.target.value) + handleUpdateProductQty(row.id, +e.target.value) + }} + onBlur={(e) => { + handleCheckProductQty(row.id, +e.target.value) }} /> ), diff --git a/apps/storefront/src/utils/b3Product/b3TaxRate.ts b/apps/storefront/src/utils/b3Product/b3TaxRate.ts index 27717345..508132aa 100644 --- a/apps/storefront/src/utils/b3Product/b3TaxRate.ts +++ b/apps/storefront/src/utils/b3Product/b3TaxRate.ts @@ -10,8 +10,10 @@ const getTaxRate = (taxClassId: number) => { if (taxZoneRates.length) { taxZoneRates.forEach((taxZoneRate: TaxZoneRatesProps) => { - if (taxZoneRate.rates[0].priority === 1) { + if (taxZoneRate.rates.length > 0 && taxZoneRate.rates[0].priority === 1) { taxRates = taxZoneRate?.rates[0]?.classRates || [] + } else { + taxRates = [] } }) }