Skip to content

Commit

Permalink
feat: refresh page after login
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton committed Sep 6, 2022
1 parent 8113739 commit 49670e6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/storefront/src/components/RegisteredCloseButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export function RegisteredCloseButton(props: CloseButtonProps) {
state: {
isCheckout,
isCloseGotoBCHome,
isLoginStatusChange,
},
dispatch,
} = useContext(GlobaledContext)

const handleCloseForm = () => {
Expand All @@ -45,6 +47,16 @@ export function RegisteredCloseButton(props: CloseButtonProps) {
isOpen: false,
openUrl: '',
})

if (isLoginStatusChange) {
window.location.reload()
dispatch({
type: 'common',
payload: {
isLoginStatusChange: false,
},
})
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions apps/storefront/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {

import {
getCurrentCustomerInfo,
clearCurrentCustomerInfo,
} from '@/utils'

import {
Expand Down Expand Up @@ -155,6 +156,8 @@ export default function Login() {
isCloseGotoBCHome: true,
},
})

clearCurrentCustomerInfo(dispatch)
}

// setChannelId(getChannelId)
Expand Down Expand Up @@ -239,6 +242,13 @@ export default function Login() {
} else {
const info = await getCurrentCustomerInfo(dispatch)

dispatch({
type: 'common',
payload: {
isLoginStatusChange: true,
},
})

if (info?.userType === 3 && info?.role === 3) {
navigate('/dashboard')
} else {
Expand Down
2 changes: 2 additions & 0 deletions apps/storefront/src/shared/global/context/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface GlobalState {
BcToken: string,
isB2BUser: boolean,
isLogin: boolean,
isLoginStatusChange: boolean,
customerId: number | string,
customer?: CustomerInfo,
emailAddress: string,
Expand All @@ -32,6 +33,7 @@ export const initState = {
BcToken: B3SStorage.get('BcToken') || '',
isB2BUser: B3SStorage.get('isB2BUser') || false,
isLogin: false,
isLoginStatusChange: false,
customerId: B3SStorage.get('B3CustomerId') || '',
emailAddress: B3SStorage.get('B3EmailAddress') || '',
role: B3SStorage.get('B3Role') || '',
Expand Down
2 changes: 2 additions & 0 deletions apps/storefront/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getChannelId,
loginInfo,
getCurrentCustomerInfo,
clearCurrentCustomerInfo,
} from './loginInfo'

export {
Expand All @@ -34,4 +35,5 @@ export {
loginInfo,
getChannelId,
getCurrentCustomerInfo,
clearCurrentCustomerInfo,
}
25 changes: 25 additions & 0 deletions apps/storefront/src/utils/loginInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,30 @@ export const loginInfo = async () => {
B3SStorage.set('BcToken', token)
}

export const clearCurrentCustomerInfo = async (dispatch: DispatchProps) => {
B3SStorage.set('B3CustomerInfo', {})
B3SStorage.set('B3CustomerId', '')
B3SStorage.set('B3EmailAddress', '')
B3SStorage.set('B3Role', 0)
B3SStorage.set('isB2BUser', false)

dispatch({
type: 'common',
payload: {
isB2BUser: false,
role: 0,
customerId: '',
customer: {
phoneNumber: '',
firstName: '',
lastName: '',
emailAddress: '',
},
emailAddress: '',
},
})
}

export const getCurrentCustomerInfo = async (dispatch: DispatchProps) => {
try {
const {
Expand Down Expand Up @@ -154,5 +178,6 @@ export const getCurrentCustomerInfo = async (dispatch: DispatchProps) => {
} catch (error) {
// eslint-disable-next-line no-console
console.log(error)
clearCurrentCustomerInfo(dispatch)
}
}

0 comments on commit 49670e6

Please sign in to comment.