Skip to content

Commit

Permalink
feat: solve bc user logout login, b2b problems
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 authored and libruce committed Nov 16, 2023
1 parent a60b6d0 commit 023b2ce
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
47 changes: 29 additions & 18 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { CustomStyleContext } from '@/shared/customStyleButtton'
import { GlobaledContext } from '@/shared/global'
import { gotoAllowedAppPage } from '@/shared/routes'
import { setChannelStoreType } from '@/shared/service/b2b'
import { getCustomerInfo } from '@/shared/service/bc'
import {
B3SStorage,
clearInvoiceCart,
Expand Down Expand Up @@ -184,7 +185,8 @@ export default function App() {
setChannelStoreType(currentChannelId)
// await getTaxZoneRates()

await Promise.all([
const getInfo = await Promise.all([
getCustomerInfo(),
getStoreTaxZoneRates(),
setStorefrontConfig(dispatch, currentChannelId),
getTemPlateConfig(currentChannelId, styleDispatch, dispatch),
Expand All @@ -195,6 +197,8 @@ export default function App() {
role: +role,
isAgenting,
}

console.log(getInfo, 'info')
if (!customerId || isRelogin) {
const info = await getCurrentCustomerInfo(dispatch)
if (info) {
Expand Down Expand Up @@ -260,26 +264,33 @@ export default function App() {
}, [isOpen])

useEffect(() => {
if (isClickEnterBtn && isPageComplete && currentClickedUrl) {
const gotoUrl = openPageByClick({
href: currentClickedUrl,
role,
isRegisterAndLogin,
isAgenting,
})

setOpenPage({
isOpen: true,
openUrl: gotoUrl,
})
const init = async () => {
if (isClickEnterBtn && isPageComplete && currentClickedUrl) {
// graphql bc
const { customer } = await getCustomerInfo()

const gotoUrl = openPageByClick({
href: currentClickedUrl,
role,
isRegisterAndLogin,
isAgenting,
})

showPageMask(dispatch, false)
storeDispatch(
setGlabolCommonState({
isClickEnterBtn: false,
setOpenPage({
isOpen: true,
openUrl: customer ? gotoUrl : '/login',
})
)

showPageMask(dispatch, false)
storeDispatch(
setGlabolCommonState({
isClickEnterBtn: false,
})
)
}
}

init()
}, [isPageComplete, currentClickedUrl, clickTimeTarget])

useEffect(() => {
Expand Down
8 changes: 7 additions & 1 deletion apps/storefront/src/shared/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { lazy } from 'react'
import { matchPath } from 'react-router-dom'

import { GlobalState, QuoteConfigProps } from '@/shared/global/context/config'
import { getCustomerInfo } from '@/shared/service/bc'
import { B3SStorage } from '@/utils'

const OrderList = lazy(() => import('../../pages/order/MyOrder'))
Expand Down Expand Up @@ -378,7 +379,7 @@ const getAllowedRoutes = (globalState: GlobalState): RouteItem[] => {
})
}

const gotoAllowedAppPage = (
const gotoAllowedAppPage = async (
role: number,
gotoPage: (url: string) => void,
isAccountEnter?: boolean
Expand All @@ -387,6 +388,11 @@ const gotoAllowedAppPage = (
gotoPage('/login?loginFlag=3&&closeIsLogout=1')
return
}

const { customer } = await getCustomerInfo()

if (!customer) gotoPage('/login')

const { hash, pathname } = window.location
let url = hash.split('#')[1] || ''
if (
Expand Down

0 comments on commit 023b2ce

Please sign in to comment.