Skip to content

Commit

Permalink
fix: tpa
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-liu-smile authored and BrianJiang2021 committed Apr 12, 2023
1 parent a3fbcd2 commit cde113a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export default function App() {
}
}, [isB2BUser, isAgenting, role, quoteConfig, storefrontConfig])

useRegisteredbctob2b(setOpenPage, isB2BUser, customerId)
useRegisteredbctob2b(setOpenPage)

useEffect(() => {
if (isOpen) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
SetStateAction,
Dispatch,
useCallback,
useEffect,
useContext,
} from 'react'

import {
Expand All @@ -15,16 +16,36 @@ import type {
import globalB3 from '@b3/global-b3'

import {
useMutationObservable,
} from '@b3/hooks'
GlobaledContext,
} from '@/shared/global'

import {
CustomStyleContext,
} from '@/shared/customStyleButtton'

import {
B3SStorage,
} from '@/utils'
useDomVariation,
} from './useDomVariation'

const useRegisteredbctob2b = (setOpenPage: Dispatch<SetStateAction<OpenPageState>>, isB2BUser: boolean, customerId:number | string) => {
const useRegisteredbctob2b = (setOpenPage: Dispatch<SetStateAction<OpenPageState>>) => {
const b3Lang = useB3Lang()

const {
state: {
isB2BUser,
customerId,
companyInfo,
},
} = useContext(GlobaledContext)

const {
state: {
accountLoginRegistration: {
b2b,
},
},
} = useContext(CustomStyleContext)

const createConvertB2BNavNode = () => {
const convertB2BNavNode = document.createElement('li')
convertB2BNavNode.className = 'navUser-item navUser-convert-b2b'
Expand All @@ -36,16 +57,19 @@ const useRegisteredbctob2b = (setOpenPage: Dispatch<SetStateAction<OpenPageState
return convertB2BNavNode
}

const cd = useCallback(() => {
const companyStatus = B3SStorage.get('companyStatus')
if (!isB2BUser && companyStatus === 99 && customerId && document.querySelector(globalB3['dom.navUserLoginElement'])) {
const [openQuickView] = useDomVariation(globalB3['dom.navUserLoginElement'])

useEffect(() => {
if (b2b && !isB2BUser && +companyInfo.companyStatus === 99 && customerId && document.querySelector(globalB3['dom.navUserLoginElement'])) {
// already exist
console.log(document.querySelector('.navUser-item.navUser-convert-b2b'))
if (document.querySelector('.navUser-item.navUser-convert-b2b')) {
return
}

const convertB2BNavNode = createConvertB2BNavNode()
const accountNode = document.querySelector(globalB3['dom.navUserLoginElement'])
console.log(accountNode, 'accountNode')
accountNode?.parentNode?.insertBefore(convertB2BNavNode, accountNode)

const linkNode = convertB2BNavNode.querySelector('a')
Expand All @@ -60,9 +84,7 @@ const useRegisteredbctob2b = (setOpenPage: Dispatch<SetStateAction<OpenPageState
} else {
document.querySelector('.navUser-item.navUser-convert-b2b')?.remove()
}
}, [isB2BUser, customerId])

useMutationObservable(document.documentElement, cd)
}, [isB2BUser, customerId, openQuickView, b2b])
}

export {
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {

import {
useRegisteredbctob2b,
} from './useRegisteredbctob2b'
} from './dom/useRegisteredbctob2b'

import {
useCardListColumn,
Expand Down
8 changes: 5 additions & 3 deletions packages/global-b3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ const localConfig = () => {
}

const globalB3 = {
'dom.registerElement': '[href^="/login.php"]',
'dom.registerElement': '[href^="/login.php"], #checkout-customer-login',
'dom.registerUrl': '/registered',
'dom.allOtherElement': '[href^="/account.php"]',
'dom.checkoutRegisterParentElement': '.checkout-step--customer .checkout-view-content',
'dom.checkoutRegisterParentElement': '#checkout-app',
'dom.navUserLoginElement': '.navUser-item.navUser-item--account',
'dom.setToQuote': '#form-action-addToCart',
'dom.setToShoppingListParentEl': '#add-to-cart-wrapper',
'dom.cartActions.container': '.cart-actions',
before_login_goto_page: '/',
'dom.openB3Checkout': 'checkout-customer-continue',
before_login_goto_page: '/account.php?action=order_status',
checkout_super_clear_session: 'true',
setting: {
b2b_url: 'https://staging-v2.bundleb2b.net',
b2b_socket_url: 'https://staging-v2.bundleb2b.net',
Expand Down

0 comments on commit cde113a

Please sign in to comment.