diff --git a/apps/storefront/src/App.tsx b/apps/storefront/src/App.tsx index 977ab83c..5ec41fee 100644 --- a/apps/storefront/src/App.tsx +++ b/apps/storefront/src/App.tsx @@ -79,6 +79,7 @@ export default function App() { storefrontConfig, productQuoteEnabled, cartQuoteEnabled, + shoppingListEnabled, }, dispatch, } = useContext(GlobaledContext) @@ -88,7 +89,7 @@ export default function App() { useOpenPDP({ setOpenPage, isB2BUser, - role, + shoppingListEnabled, }) useMyQuote({ @@ -177,10 +178,11 @@ export default function App() { }, []) useEffect(() => { + const isRelogin = sessionStorage.getItem('isreLogin') loginAndRegister() const init = async () => { // bc token - if (!BcToken) { + if (!BcToken || isRelogin) { await loginInfo() } @@ -192,7 +194,7 @@ export default function App() { isAgenting, } - if (!customerId) { + if (!customerId || isRelogin) { const info = await getCurrentCustomerInfo(dispatch) if (info) { userInfo.role = info?.role @@ -203,6 +205,8 @@ export default function App() { if (!href.includes('checkout') && !(customerId && !window.location.hash)) { gotoAllowedAppPage(+userInfo.role, userInfo.isAgenting, gotoPage) } + + sessionStorage.removeItem('isreLogin') showPageMask(false) } @@ -221,6 +225,7 @@ export default function App() { const { productQuoteEnabled, cartQuoteEnabled, + shoppingListEnabled, } = getQuoteEnabled(quoteConfig, storefrontConfig, role, isB2BUser, isAgenting) dispatch({ @@ -228,6 +233,7 @@ export default function App() { payload: { productQuoteEnabled, cartQuoteEnabled, + shoppingListEnabled, }, }) } diff --git a/apps/storefront/src/components/B3HoverButton.tsx b/apps/storefront/src/components/B3HoverButton.tsx index 3fecdcb4..836e1a5c 100644 --- a/apps/storefront/src/components/B3HoverButton.tsx +++ b/apps/storefront/src/components/B3HoverButton.tsx @@ -47,6 +47,12 @@ export const B3HoverButton = (props: B3HoverButtonProps) => { const [isMobile] = useMobile() + const { + href, + } = window.location + + if (href.includes('/checkout')) return <> + return ( { const { hash, + href, } = window.location + if (href.includes('/checkout')) return <> + const isAddBottom = bottomHeightPage.some((item: string) => hash.includes(item)) const [isExpansion, setExpansion] = useState(true) diff --git a/apps/storefront/src/components/upload/B3Upload.tsx b/apps/storefront/src/components/upload/B3Upload.tsx index 794c8ad9..31b361e0 100644 --- a/apps/storefront/src/components/upload/B3Upload.tsx +++ b/apps/storefront/src/components/upload/B3Upload.tsx @@ -79,7 +79,7 @@ export const B3Upload = () => { } const openFile = () => { - if (uploadRef.current) uploadRef.current.children[1].click() + if (uploadRef.current) (uploadRef.current.children[1] as any).click() } const content = ( diff --git a/apps/storefront/src/hooks/useOpenPDP.ts b/apps/storefront/src/hooks/useOpenPDP.ts index 13cec6f3..9aaa6149 100644 --- a/apps/storefront/src/hooks/useOpenPDP.ts +++ b/apps/storefront/src/hooks/useOpenPDP.ts @@ -18,11 +18,11 @@ import type { interface MutationObserverProps { setOpenPage: Dispatch>, isB2BUser: boolean, - role: string | number, + shoppingListEnabled: boolean, } const useOpenPDP = ({ - setOpenPage, isB2BUser, role, + setOpenPage, isB2BUser, shoppingListEnabled, }: MutationObserverProps) => { const [openQuickViewNum, setOpenQuickViewNum] = useState(0) @@ -41,7 +41,7 @@ const useOpenPDP = ({ useMutationObservable(document.documentElement, cd) - useB3PDPOpen(globalB3['dom.setToShoppingListParentEl'], pdpCallBbck, isB2BUser, role, openQuickViewNum) + useB3PDPOpen(globalB3['dom.setToShoppingListParentEl'], pdpCallBbck, isB2BUser, shoppingListEnabled, openQuickViewNum) } export { diff --git a/apps/storefront/src/pages/dashboard/Dashboard.tsx b/apps/storefront/src/pages/dashboard/Dashboard.tsx index 4c71e0e1..769c9d4d 100644 --- a/apps/storefront/src/pages/dashboard/Dashboard.tsx +++ b/apps/storefront/src/pages/dashboard/Dashboard.tsx @@ -113,7 +113,7 @@ const Dashboard = () => { edges = [], totalCount, }, - }: any = await superAdminCompanies(+B3UserId, params.q) + }: any = await superAdminCompanies(+B3UserId, params) return { edges, diff --git a/apps/storefront/src/shared/global/context/config.ts b/apps/storefront/src/shared/global/context/config.ts index 2eaadba2..798be415 100644 --- a/apps/storefront/src/shared/global/context/config.ts +++ b/apps/storefront/src/shared/global/context/config.ts @@ -102,6 +102,7 @@ export interface GlobalState { value: boolean, enabledStatus: boolean, }, + shoppingLists: boolean, }, storeEnabled: boolean, storeName: string, @@ -110,6 +111,7 @@ export interface GlobalState { countriesList?: Country[], productQuoteEnabled: boolean, cartQuoteEnabled: boolean, + shoppingListEnabled: boolean, quoteConfig: { switchStatus: { [key: string]: string @@ -171,6 +173,7 @@ export const initState = { countriesList: [], productQuoteEnabled: false, cartQuoteEnabled: false, + shoppingListEnabled: false, quoteConfig: { switchStatus: [], otherConfigs: [], diff --git a/apps/storefront/src/shared/routes/routes.ts b/apps/storefront/src/shared/routes/routes.ts index 89d8deae..6e8a62e2 100644 --- a/apps/storefront/src/shared/routes/routes.ts +++ b/apps/storefront/src/shared/routes/routes.ts @@ -100,7 +100,7 @@ const routes: RouteItem[] = [ wsKey: 'router-orders', isMenuItem: false, component: OrderDetail, - permissions: [0, 1, 2, 3, 99, 100], + permissions: [0, 1, 2, 3, 4, 99, 100], isTokenLogin: true, }, { @@ -200,15 +200,15 @@ const routes: RouteItem[] = [ permissions: [0, 1, 2, 3, 99, 100], isTokenLogin: false, }, - { - path: '/xxxxx', - name: 'Recently viewed', - wsKey: 'router-orders', - isMenuItem: true, - component: Dashboard, - permissions: [0, 1, 2, 3, 99, 100], - isTokenLogin: true, - }, + // { + // path: '/xxxxx', + // name: 'Recently viewed', + // wsKey: 'router-orders', + // isMenuItem: true, + // component: Dashboard, + // permissions: [0, 1, 2, 3, 99, 100], + // isTokenLogin: true, + // }, ] const firstLevelRouting: RouteFirstLevelItem[] = [ diff --git a/apps/storefront/src/shared/service/b2b/graphql/global.ts b/apps/storefront/src/shared/service/b2b/graphql/global.ts index bcb4524f..a0c33061 100644 --- a/apps/storefront/src/shared/service/b2b/graphql/global.ts +++ b/apps/storefront/src/shared/service/b2b/graphql/global.ts @@ -26,12 +26,12 @@ const getAgentInfoQl = (customerId: string | number) => `{ } }` -const superAdminCompaniesQl = (id: number, q: string) => `{ +const superAdminCompaniesQl = (id: number, params: CustomFieldItems) => `{ superAdminCompanies( superAdminId: ${id} - offset: 0 - first: 10 - search: "${q || ''}" + first: ${params.first} + offset: ${params.offset} + search: "${params.q || ''}" ) { edges{ node{ @@ -140,8 +140,8 @@ export const getAgentInfo = (customerId: string | number): CustomFieldItems => B query: getAgentInfoQl(customerId), }) -export const superAdminCompanies = (id: number, q: string): CustomFieldItems => B3Request.graphqlB2B({ - query: superAdminCompaniesQl(id, q), +export const superAdminCompanies = (id: number, params: CustomFieldItems): CustomFieldItems => B3Request.graphqlB2B({ + query: superAdminCompaniesQl(id, params), }) export const superAdminBeginMasquerade = (companyId: number, userId: number): CustomFieldItems => B3Request.graphqlB2B({ diff --git a/apps/storefront/src/utils/b3Init.ts b/apps/storefront/src/utils/b3Init.ts index 9795ed29..c70526d1 100644 --- a/apps/storefront/src/utils/b3Init.ts +++ b/apps/storefront/src/utils/b3Init.ts @@ -20,6 +20,7 @@ export const getQuoteEnabled = ( value: boolean, enabledStatus: boolean, }, + shoppingLists: boolean, }, role: number | string, isB2BUser: boolean, @@ -33,6 +34,8 @@ export const getQuoteEnabled = ( const quoteEnabled = storefrontConfig.quotes || false + let shoppingListEnabled = storefrontConfig.shoppingLists || false + quoteConfig.switchStatus.forEach((config) => { if (config.key === 'quote_customer') { customerEnabled = config.isEnabled @@ -57,7 +60,12 @@ export const getQuoteEnabled = ( if (`${role}` === '100') { // guest productQuoteEnabled = productQuoteEnabled && guestEnabled === '1' cartQuoteEnabled = cartQuoteEnabled && guestEnabled === '1' - } else if (!isB2BUser || (`${role}` === '3' && !isAgenting)) { // BCUser + shoppingListEnabled = false + } else if (`${role}` === '3' && !isAgenting) { + productQuoteEnabled = false + cartQuoteEnabled = false + shoppingListEnabled = false + } else if (!isB2BUser) { // BCUser productQuoteEnabled = productQuoteEnabled && bcUserEnabled === '1' cartQuoteEnabled = cartQuoteEnabled && bcUserEnabled === '1' } @@ -65,5 +73,6 @@ export const getQuoteEnabled = ( return { productQuoteEnabled, cartQuoteEnabled, + shoppingListEnabled, } } diff --git a/packages/hooks/useB3PDPOpen.ts b/packages/hooks/useB3PDPOpen.ts index 66da2293..dc948228 100644 --- a/packages/hooks/useB3PDPOpen.ts +++ b/packages/hooks/useB3PDPOpen.ts @@ -9,14 +9,14 @@ const removeElement = (_element: CustomFieldItems) => { } } -export const useB3PDPOpen = (el: string, cd: () => void, isB2BUser: boolean, role: string | number, openQuickViewNum: number) => { +export const useB3PDPOpen = (el: string, cd: () => void, isB2BUser: boolean, shoppingListEnabled: boolean, openQuickViewNum: number) => { useEffect(() => { const addToCartAll = document.querySelectorAll(el) const wishlistSdd = document.querySelector('form[data-wishlist-add]') let shoppingBtnDom: CustomFieldItems | null = null if (!addToCartAll.length) return if (document.querySelectorAll('#shoppingListBtn').length) return - if (isB2BUser && (+role === 0 || +role === 1 || +role === 2)) { + if (shoppingListEnabled) { addToCartAll.forEach((node: CustomFieldItems) => { shoppingBtnDom = document.createElement('div') shoppingBtnDom.setAttribute('id', 'shoppingListBtn') @@ -40,5 +40,5 @@ export const useB3PDPOpen = (el: string, cd: () => void, isB2BUser: boolean, rol shoppingBtnDom.removeEventListener('click', cd) } } - }, [isB2BUser, role, openQuickViewNum]) + }, [isB2BUser, shoppingListEnabled, openQuickViewNum]) }