From 023b2ce638d4cc7ee2c9854b930fb21dfff23b21 Mon Sep 17 00:00:00 2001 From: BrianJiang2021 Date: Wed, 8 Nov 2023 16:40:17 +0800 Subject: [PATCH] feat: solve bc user logout login, b2b problems --- apps/storefront/src/App.tsx | 47 +++++++++++++-------- apps/storefront/src/shared/routes/routes.ts | 8 +++- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/apps/storefront/src/App.tsx b/apps/storefront/src/App.tsx index 8fa0ab84..74c20b08 100644 --- a/apps/storefront/src/App.tsx +++ b/apps/storefront/src/App.tsx @@ -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, @@ -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), @@ -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) { @@ -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(() => { diff --git a/apps/storefront/src/shared/routes/routes.ts b/apps/storefront/src/shared/routes/routes.ts index 7ff088ae..19b94cc9 100644 --- a/apps/storefront/src/shared/routes/routes.ts +++ b/apps/storefront/src/shared/routes/routes.ts @@ -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')) @@ -378,7 +379,7 @@ const getAllowedRoutes = (globalState: GlobalState): RouteItem[] => { }) } -const gotoAllowedAppPage = ( +const gotoAllowedAppPage = async ( role: number, gotoPage: (url: string) => void, isAccountEnter?: boolean @@ -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 (