Skip to content

Commit

Permalink
fix: account loadding
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-liu-smile committed Apr 27, 2023
1 parent 64b0634 commit c48bb18
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 38 deletions.
16 changes: 7 additions & 9 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useContext, useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useDispatch } from 'react-redux'
import { HashRouter } from 'react-router-dom'
import { useB3AppOpen } from '@b3/hooks'

Expand Down Expand Up @@ -31,7 +31,7 @@ import {
setStorefrontConfig,
} from '@/utils'

import { globalStateSelector, setGlabolCommonState } from './store'
import { setGlabolCommonState } from './store'

const FONT_URL =
'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap'
Expand All @@ -56,12 +56,8 @@ export default function App() {

const storeDispatch = useDispatch()

// isLoadComplete
const isLoadComplete = useSelector(globalStateSelector)

const [{ isOpen, openUrl, params }, setOpenPage] = useB3AppOpen({
isOpen: false,
isLoaddingComplete: isLoadComplete,
})

const {
Expand Down Expand Up @@ -157,9 +153,11 @@ export default function App() {
isAgenting,
}

const info = await getCurrentCustomerInfo(dispatch)
if (info) {
userInfo.role = info?.role
if (!customerId || isRelogin) {
const info = await getCurrentCustomerInfo(dispatch)
if (info) {
userInfo.role = info?.role
}
}

// background login enter judgment and refresh
Expand Down
9 changes: 1 addition & 8 deletions apps/storefront/src/components/B3StoreContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@ export function B3StoreContainer(props: B3StoreContainerProps) {

useLayoutEffect(() => {
const getStoreBasicInfo = async () => {
// if (
// window.location.pathname.includes('account.php') ||
// window.location.hash
// ) {
// showPageMask(dispatch, true)
// }

showPageMask(dispatch, true)
if (!B3SStorage.get('bcJwtToken')) showPageMask(dispatch, true)

try {
const { storeBasicInfo }: CustomFieldItems = await getBCStoreChannelId()
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/shared/service/request/b3Fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const B3Request = {
},
graphqlProxyBC: function post<T>(data: T): Promise<any> {
const config = {
Authorization: `Bearer ${B3SStorage.get('bc_jwt_token') || ''}`,
Authorization: `Bearer ${B3SStorage.get('bcJwtToken') || ''}`,
}
return graphqlRequest(RequestType.B2BGraphql, data, config)
},
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/shared/service/request/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function b3Fetch(
try {
await getCurrentJwt()
const config = {
Authorization: `Bearer ${B3SStorage.get('bc_jwt_token') || ''}`,
Authorization: `Bearer ${B3SStorage.get('bcJwtToken') || ''}`,
}
const headers = {
'content-type': 'application/json',
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/utils/loginInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const clearCurrentCustomerInfo = async (dispatch: DispatchProps) => {
B3SStorage.set('B3EmailAddress', '')
B3SStorage.set('B3Role', '')
B3SStorage.set('isB2BUser', false)
B3SStorage.set('bc_jwt_token', '')
B3SStorage.set('bcJwtToken', '')
B3SStorage.set('B3B2BToken', false)
B3SStorage.set('B3UserId', '')

Expand Down Expand Up @@ -131,7 +131,7 @@ export const getCurrentJwt = async () => {
app_client_id: 'r2x8j3tn54wduq47b4efct5tqxio5z2',
})

B3SStorage.set('bc_jwt_token', res)
B3SStorage.set('bcJwtToken', res)
return res
} catch (error) {
console.log(error)
Expand Down
26 changes: 9 additions & 17 deletions packages/hooks/useB3AppOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import useMutationObservable from './useMutationObservable'
export interface OpenPageState {
isOpen: boolean
openUrl?: string
isLoaddingComplete?: boolean
params?: { [key: string]: string }
}

Expand Down Expand Up @@ -57,21 +56,14 @@ export const useB3AppOpen = (initOpenState: OpenPageState) => {
e.preventDefault()
e.stopPropagation()

if (
!(
initOpenState?.isLoaddingComplete &&
allOtherArr.includes(e.target)
)
) {
const href = (e.target as HTMLAnchorElement).href || ''
const gotoUrl = registerArr.includes(e.target)
? getCurrentLoginUrl(href)
: '/orders'
setOpenPage({
isOpen: true,
openUrl: gotoUrl,
})
}
const href = (e.target as HTMLAnchorElement).href || ''
const gotoUrl = registerArr.includes(e.target)
? getCurrentLoginUrl(href)
: '/orders'
setOpenPage({
isOpen: true,
openUrl: gotoUrl,
})
}
return false
}
Expand All @@ -85,7 +77,7 @@ export const useB3AppOpen = (initOpenState: OpenPageState) => {
}
}
return () => {}
}, [checkoutRegisterNumber, initOpenState?.isLoaddingComplete])
}, [checkoutRegisterNumber])

useMutationObservable(globalB3['dom.checkoutRegisterParentElement'], callback)

Expand Down

0 comments on commit c48bb18

Please sign in to comment.