Skip to content

Commit

Permalink
fix: pending account tip display issues
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlLiu2023 authored and BrianJiang2021 committed May 18, 2023
1 parent 32963a1 commit a75d2b4
Showing 1 changed file with 41 additions and 29 deletions.
70 changes: 41 additions & 29 deletions apps/storefront/src/hooks/dom/useCartToQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,56 @@ const useCartToQuote = ({
state: { companyInfo },
} = useContext(GlobaledContext)

const urlArr = ['/cart.php', '/checkout']
const urlArr = ['/cart', '/checkout']

const checkIsInPage = (url: string) => window.location.href.includes(url)

const isBlockPendingAccountOrderCreation =
(checkIsInPage(urlArr[0]) || checkIsInPage(urlArr[1])) &&
blockPendingAccountOrderCreation.enabled &&
companyInfo.companyStatus &&
+companyInfo.companyStatus === 0
const { pathname } = window.location

useEffect(() => {
const showPendingAccountTip = () => {
const isShowBlockPendingAccountOrderCreationTip: IsShowBlockPendingAccountOrderCreationTipProps =
B3SStorage.get('isShowBlockPendingAccountOrderCreationTip') || {
cartTip: 0,
checkoutTip: 0,
}
const isShowTips =
(checkIsInPage(urlArr[0]) &&
isShowBlockPendingAccountOrderCreationTip.cartTip === 0) ||
(checkIsInPage(urlArr[1]) &&
isShowBlockPendingAccountOrderCreationTip.checkoutTip === 0)
if (isBlockPendingAccountOrderCreation && isShowTips) {
globalSnackbar.warning(
'Your account is pending approval. Ordering will be enabled after account approval',
{
isClose: true,
}
)
B3SStorage.set('isShowBlockPendingAccountOrderCreationTip', {
cartTip:
+checkIsInPage(urlArr[0]) +
isShowBlockPendingAccountOrderCreationTip.cartTip,
checkoutTip:
+checkIsInPage(urlArr[1]) +
isShowBlockPendingAccountOrderCreationTip.checkoutTip,
})
}
}, [isBlockPendingAccountOrderCreation])

if (!urlArr.includes(pathname)) return

if (companyInfo.companyStatus === '') return

if (+companyInfo.companyStatus || !blockPendingAccountOrderCreation.enabled)
return

if (
isShowBlockPendingAccountOrderCreationTip.cartTip &&
checkIsInPage(urlArr[0])
)
return

if (
isShowBlockPendingAccountOrderCreationTip.checkoutTip &&
checkIsInPage(urlArr[1])
)
return
globalSnackbar.warning(
'Your account is pending approval. Ordering will be enabled after account approval',
{
isClose: true,
}
)
B3SStorage.set('isShowBlockPendingAccountOrderCreationTip', {
cartTip:
+checkIsInPage(urlArr[0]) +
isShowBlockPendingAccountOrderCreationTip.cartTip,
checkoutTip:
+checkIsInPage(urlArr[1]) +
isShowBlockPendingAccountOrderCreationTip.checkoutTip,
})
}

useEffect(() => {
showPendingAccountTip()
}, [pathname])

const quoteCallBbck = useCallback(() => {
const b3CartToQuote = document.querySelector('.b2b-cart-to-quote')
Expand Down

0 comments on commit a75d2b4

Please sign in to comment.