Skip to content

Commit

Permalink
feat: junior hide cart bun1741 (#862)
Browse files Browse the repository at this point in the history
* feat: junior hide cart BUN1741
https://bigc-b2b.atlassian.net/browse/BUN-1741

* feat: junior hide cart bun1741
  • Loading branch information
BrianJiang2021 authored and libruce committed Dec 27, 2023
1 parent b7aad70 commit e8751d3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions apps/storefront/src/hooks/dom/useDomHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Dispatch, SetStateAction, useContext, useEffect } from 'react'
import { OpenPageState } from '@b3/hooks'

import { GlobaledContext } from '@/shared/global'
import { removeCartPermissions } from '@/utils/b3RolePermissions'
import { setCartPermissions } from '@/utils/b3RolePermissions'

import useCartToQuote from './useCartToQuote'
import useHideGoogleCustomerReviews from './useHideGoogleCustomerReviews'
Expand All @@ -28,8 +28,8 @@ const useDomHooks = ({ setOpenPage, isOpen }: MutationObserverProps) => {
} = useContext(GlobaledContext)

useEffect(() => {
if (+role === 2) {
removeCartPermissions(role)
if (+role !== 2) {
setCartPermissions(role)
}
}, [role])

Expand Down
7 changes: 3 additions & 4 deletions apps/storefront/src/hooks/dom/useMyQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import {
splitCustomCssValue,
} from '@/components/outSideComponents/utils/b3CustomStyles'
import { CustomStyleContext } from '@/shared/customStyleButtton'
import { B3LStorage, removeCartPermissions } from '@/utils'
import { B3LStorage, setCartPermissions } from '@/utils'

// import { removeCartPermissions } from '@/utils/b3RolePermissions'
import useDomVariation from './useDomVariation'
import { addProductFromProductPageToQuote, removeElement } from './utils'

Expand Down Expand Up @@ -73,8 +72,8 @@ const useMyQuote = ({
}, [])

const cd = () => {
if (+role === 2) {
removeCartPermissions(role)
if (+role !== 2) {
setCartPermissions(role)
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/utils/b3RolePermissions/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// eslint-disable-next-line
export { default as removeCartPermissions } from './juniorRolePermissions'
export { default as setCartPermissions } from './juniorRolePermissions'
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import globalB3 from '@b3/global-b3'

const removeCartPermissions = (role: number | string) => {
if (+role !== 2) return
const setCartPermissions = (role: number | string) => {
if (+role === 2) return
const carts = document.querySelectorAll(globalB3['dom.cartElement'])

// remove cart Entrance
if (carts.length > 0) {
carts.forEach((cart: any) => {
cart.style.display = 'none'
cart.style.display = ''
})
}
}

export default removeCartPermissions
export default setCartPermissions
6 changes: 3 additions & 3 deletions apps/storefront/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import distanceDay from './b3Picker'
import getProductPriceIncTax from './b3Price'
import b2bPrintInvoice from './b3PrintInvoice'
import getProxyInfo from './b3Proxy'
import { removeCartPermissions } from './b3RolePermissions'
import { setCartPermissions } from './b3RolePermissions'
import { B3LStorage, B3SStorage } from './b3Storage'
import { globalSnackbar, snackbar } from './b3Tip'
import b3TriggerCartNumber from './b3TriggerCartNumber'
Expand All @@ -50,7 +50,7 @@ import {
} from './loginInfo'
import { validatorRules } from './validatorRules'

export { isB2bTokenPage, isUserGotoLogin,logoutSession } from './b3logout'
export { isB2bTokenPage, isUserGotoLogin, logoutSession } from './b3logout'
export * from './b3Product/b3Product'
export * from './basicConfig'
export * from './masquerade'
Expand Down Expand Up @@ -104,8 +104,8 @@ export {
ordersCurrencyFormat,
redirectBcMenus,
removeBCMenus,
removeCartPermissions,
serialize,
setCartPermissions,
showPageMask,
snackbar,
validatorRules,
Expand Down
2 changes: 2 additions & 0 deletions packages/global-b3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ declare global {
B3: any
B3Local: any
B3CustomConfig: any
cartElementId: string
}
}

Expand Down Expand Up @@ -68,6 +69,7 @@ const globalB3 = {
'dom.cartActions.container': '.cart-actions',
'dom.openB3Checkout': 'checkout-customer-continue',
'dom.cartElement':
window?.B3['dom.cart'] ||
'[href="/cart.php"], #form-action-addToCart, [data-button-type="add-cart"], [data-emthemesmodez-cart-item-add]',
'dom.productView': '.productView',
'dom.register': '[href^="/login.php?action=create_account"]',
Expand Down

0 comments on commit e8751d3

Please sign in to comment.