Skip to content

Commit

Permalink
fix: fixed dashboard page
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-liu-smile authored and BrianJiang2021 committed Mar 21, 2023
1 parent b42db1c commit 35b8be6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 44 deletions.
10 changes: 0 additions & 10 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,6 @@ export default function App() {
init()
}, [])

// useEffect(() => {
// if (openApp) {
// gotoAllowedAppPage(+role, gotoPage)
// showPageMask(false)
// }
// }, [openApp])

useEffect(() => {
if (quoteConfig.switchStatus.length > 0 && storefrontConfig) {
const {
Expand Down Expand Up @@ -275,9 +268,6 @@ export default function App() {
productQuoteEnabled={productQuoteEnabled}
setOpenPage={setOpenPage}
/>
{/* <CheckoutTip
setOpenPage={setOpenPage}
/> */}
</>

)
Expand Down
7 changes: 6 additions & 1 deletion apps/storefront/src/hooks/useRegisteredbctob2b.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import {
useMutationObservable,
} from '@b3/hooks'

import {
B3SStorage,
} from '@/utils'

const useRegisteredbctob2b = (setOpenPage: Dispatch<SetStateAction<OpenPageState>>, isB2BUser: boolean, customerId:number | string) => {
const b3Lang = useB3Lang()

Expand All @@ -33,7 +37,8 @@ const useRegisteredbctob2b = (setOpenPage: Dispatch<SetStateAction<OpenPageState
}

const cd = useCallback(() => {
if (!isB2BUser && customerId && document.querySelector(globalB3['dom.navUserLoginElement'])) {
const companyStatus = B3SStorage.get('companyStatus')
if (!isB2BUser && companyStatus === 99 && customerId && document.querySelector(globalB3['dom.navUserLoginElement'])) {
// already exist
if (document.querySelector('.navUser-item.navUser-convert-b2b')) {
return
Expand Down
8 changes: 4 additions & 4 deletions apps/storefront/src/shared/service/b2b/graphql/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const getRegisterLogo = () => `{
}
}`

const getCompanyUserInfo = <T>(email: T) => `{
companyUserInfo(storeHash:"${storeHash}", email:"${email}") {
const getCompanyUserInfo = <T>(email: T, customerId?: number) => `{
companyUserInfo(storeHash:"${storeHash}", email:"${email}", ${customerId ? `customerId: ${customerId}` : ''}) {
userType,
userInfo {
id
Expand Down Expand Up @@ -168,8 +168,8 @@ export const getB2BAccountFormFields = (type: number): CustomFieldItems => B3Req
query: getAccountFormFields(type),
})

export const getB2BCompanyUserInfo = (email: string): CustomFieldItems => B3Request.graphqlB2B({
query: getCompanyUserInfo(email),
export const getB2BCompanyUserInfo = (email: string, customerId?: number): CustomFieldItems => B3Request.graphqlB2B({
query: getCompanyUserInfo(email, customerId),
})

export const getB2BRegisterLogo = (): CustomFieldItems => B3Request.graphqlB2B({
Expand Down
48 changes: 19 additions & 29 deletions apps/storefront/src/utils/loginInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
getAgentInfo,
getUserCompany,
getCurrencies,
// superAdminEndMasquerade,
} from '@/shared/service/b2b'

import {
Expand Down Expand Up @@ -191,11 +190,19 @@ const getCurrentJwtAndB2BToken = async (userType: number) => {
}
}

// companyStatus
// 99: default, Distinguish between bc and b2b
// 0: pending
// 1: approved
// 2: rejected
// 3: inactive
// 4: deleted

const getCompanyInfo = async (id: number, userType: number, role:number) => {
let companyInfo = {
id: '',
companyName: '',
companyStatus: 0,
companyStatus: 99,
}
if (userType === 3 && role !== 3) {
const {
Expand All @@ -209,6 +216,8 @@ const getCompanyInfo = async (id: number, userType: number, role:number) => {
}
}

B3SStorage.set('companyStatus', companyInfo.companyStatus)

return companyInfo
}

Expand Down Expand Up @@ -236,31 +245,12 @@ export const agentInfo = async (customerId: number, role: number, b3UserId: numb
salesRepCompanyName: companyName,
},
})
} else if (id || companyName) {
// end
// await superAdminEndMasquerade(+id, +b3UserId)
// B3SStorage.delete('isAgenting')
// B3SStorage.delete('salesRepCompanyId')
// B3SStorage.delete('salesRepCompanyName')
// dispatch({
// type: 'common',
// payload: {
// isAgenting: false,
// salesRepCompanyId: '',
// salesRepCompanyName: '',
// },
// })
}
}
} catch (error) {
console.log(error)
}
}
// return {
// isAgenting,
// salesRepCompanyId,
// salesRepCompanyName,
// }
}

export const getCurrentCustomerInfo = async (dispatch: DispatchProps) => {
Expand Down Expand Up @@ -292,7 +282,7 @@ export const getCurrentCustomerInfo = async (dispatch: DispatchProps) => {
id,
},
},
} = await getB2BCompanyUserInfo(emailAddress)
} = await getB2BCompanyUserInfo(emailAddress, customerId)

await getCurrentJwtAndB2BToken(userType)

Expand All @@ -309,24 +299,24 @@ export const getCurrentCustomerInfo = async (dispatch: DispatchProps) => {
emailAddress,
customerGroupId,
}

const isB2BUser = (userType === 3 && companyInfo?.companyStatus === 1) || +role === 3

B3SStorage.set('B3CustomerInfo', customerInfo)
B3SStorage.set('B3CompanyInfo', companyInfo)
B3SStorage.set('B3CustomerId', customerId)
B3SStorage.set('B3EmailAddress', emailAddress)
B3SStorage.set('B3UserId', id)
B3SStorage.set('B3Role', userType === 3 ? role : 99)
B3SStorage.set('isB2BUser', (userType === 3 && companyInfo?.companyStatus === 1))
B3SStorage.set('B3Role', isB2BUser ? role : 99)
B3SStorage.set('isB2BUser', isB2BUser)

dispatch({
type: 'common',
payload: {
isB2BUser: (userType === 3 && companyInfo?.companyStatus === 1),
role: (userType === 3 && companyInfo?.companyStatus === 1) ? role : 99,
isB2BUser,
role: isB2BUser ? role : 99,
customerId,
B3UserId: id,
// isAgenting: agentInfo.isAgenting,
// salesRepCompanyId: agentInfo.salesRepCompanyId,
// salesRepCompanyName: agentInfo.salesRepCompanyName,
companyInfo,
customer: {
phoneNumber,
Expand Down

0 comments on commit 35b8be6

Please sign in to comment.