Skip to content

Commit

Permalink
fix: account loaddding complete click
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-liu-smile committed Apr 26, 2023
1 parent cbd39d2 commit df8a9d1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 18 deletions.
24 changes: 20 additions & 4 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useContext, useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { HashRouter } from 'react-router-dom'
import { useB3AppOpen } from '@b3/hooks'

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

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

const FONT_URL =
'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap'

export default function App() {
const [{ isOpen, openUrl, params }, setOpenPage] = useB3AppOpen({
isOpen: false,
})

const {
state: {
isB2BUser,
Expand All @@ -55,6 +54,18 @@ export default function App() {
dispatch,
} = useContext(GlobaledContext)

const storeDispatch = useDispatch()

// isLoadComplete
const isLoadComplete = useSelector(globalStateSelector)

console.log(isLoadComplete, 'isLoadComplete')

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

const {
state: {
portalStyle: { backgroundColor },
Expand Down Expand Up @@ -165,6 +176,11 @@ export default function App() {

sessionStorage.removeItem('isReLogin')
showPageMask(dispatch, false)
storeDispatch(
setGlabolCommonState({
isLoadComplete: false,
})
)
}

init()
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare interface CustomFieldItems {
}

declare interface CustomFieldStringItems {
[key: string]: strting
[key: string]: string | number
}

declare interface Window {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function DashboardCard({
mb: '10px',
}}
variant="text"
onClick={() => startActing(row.companyId)}
onClick={() => startActing((row as CustomFieldItems).companyId)}
>
MASQUERADE
</Button>
Expand Down
7 changes: 7 additions & 0 deletions apps/storefront/src/store/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ import { createSelector } from '@reduxjs/toolkit'
import { RootState } from './reducer'

const themeSelector = (state: RootState) => state.theme
const globalSelector = (state: RootState) => state.global

// More selectors will be added
// eslint-disable-next-line
export const themeFrameSelector = createSelector(
themeSelector,
(theme) => theme.themeFrame
)

export const globalStateSelector = createSelector(
globalSelector,
(state) => state.isLoadComplete
)
11 changes: 9 additions & 2 deletions apps/storefront/src/store/slices/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ export interface TaxZoneRatesProps {

export interface GlabolState {
taxZoneRates?: TaxZoneRatesProps[]
isLoadComplete?: boolean
}

const initialState: GlabolState = {
taxZoneRates: [],
isLoadComplete: true,
}

export const glabolSlice = createSlice({
name: 'glabol',
name: 'global',
initialState,
reducers: {
clearglabol: () => initialState,
Expand All @@ -40,9 +42,14 @@ export const glabolSlice = createSlice({
) => {
state.taxZoneRates = payload as Draft<TaxZoneRatesProps[]>
},
setGlabolCommonState: (state, { payload }: PayloadAction<GlabolState>) => ({
...state,
...payload,
}),
},
})

export const { clearglabol, setTaxZoneRates } = glabolSlice.actions
export const { clearglabol, setTaxZoneRates, setGlabolCommonState } =
glabolSlice.actions

export default glabolSlice.reducer
29 changes: 19 additions & 10 deletions packages/hooks/useB3AppOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import useMutationObservable from './useMutationObservable'
export interface OpenPageState {
isOpen: boolean
openUrl?: string
params?: CustomFieldItems
isLoaddingComplete?: boolean
params?: { [key: string]: string }
}

export const useB3AppOpen = (initOpenState: OpenPageState) => {
Expand Down Expand Up @@ -43,6 +44,7 @@ export const useB3AppOpen = (initOpenState: OpenPageState) => {
// })
// }
// login register orther

if (document.querySelectorAll(globalB3['dom.registerElement']).length) {
const registerArr = Array.from(
document.querySelectorAll(globalB3['dom.registerElement'])
Expand All @@ -55,14 +57,21 @@ export const useB3AppOpen = (initOpenState: OpenPageState) => {
e.preventDefault()
e.stopPropagation()

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

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

Expand Down

0 comments on commit df8a9d1

Please sign in to comment.