diff --git a/apps/storefront/src/App.tsx b/apps/storefront/src/App.tsx index 3c3f9a0e..a753dcce 100644 --- a/apps/storefront/src/App.tsx +++ b/apps/storefront/src/App.tsx @@ -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 { @@ -275,9 +268,6 @@ export default function App() { productQuoteEnabled={productQuoteEnabled} setOpenPage={setOpenPage} /> - {/* */} ) diff --git a/apps/storefront/src/hooks/useRegisteredbctob2b.ts b/apps/storefront/src/hooks/useRegisteredbctob2b.ts index 8bc3e5c4..a780745e 100644 --- a/apps/storefront/src/hooks/useRegisteredbctob2b.ts +++ b/apps/storefront/src/hooks/useRegisteredbctob2b.ts @@ -18,6 +18,10 @@ import { useMutationObservable, } from '@b3/hooks' +import { + B3SStorage, +} from '@/utils' + const useRegisteredbctob2b = (setOpenPage: Dispatch>, isB2BUser: boolean, customerId:number | string) => { const b3Lang = useB3Lang() @@ -33,7 +37,8 @@ const useRegisteredbctob2b = (setOpenPage: Dispatch { - 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 diff --git a/apps/storefront/src/shared/service/b2b/graphql/register.ts b/apps/storefront/src/shared/service/b2b/graphql/register.ts index 182f4847..4f0e13d8 100644 --- a/apps/storefront/src/shared/service/b2b/graphql/register.ts +++ b/apps/storefront/src/shared/service/b2b/graphql/register.ts @@ -57,8 +57,8 @@ const getRegisterLogo = () => `{ } }` -const getCompanyUserInfo = (email: T) => `{ - companyUserInfo(storeHash:"${storeHash}", email:"${email}") { +const getCompanyUserInfo = (email: T, customerId?: number) => `{ + companyUserInfo(storeHash:"${storeHash}", email:"${email}", ${customerId ? `customerId: ${customerId}` : ''}) { userType, userInfo { id @@ -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({ diff --git a/apps/storefront/src/utils/loginInfo.ts b/apps/storefront/src/utils/loginInfo.ts index 51a90627..d4dc8e7b 100644 --- a/apps/storefront/src/utils/loginInfo.ts +++ b/apps/storefront/src/utils/loginInfo.ts @@ -5,7 +5,6 @@ import { getAgentInfo, getUserCompany, getCurrencies, - // superAdminEndMasquerade, } from '@/shared/service/b2b' import { @@ -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 { @@ -209,6 +216,8 @@ const getCompanyInfo = async (id: number, userType: number, role:number) => { } } + B3SStorage.set('companyStatus', companyInfo.companyStatus) + return companyInfo } @@ -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) => { @@ -292,7 +282,7 @@ export const getCurrentCustomerInfo = async (dispatch: DispatchProps) => { id, }, }, - } = await getB2BCompanyUserInfo(emailAddress) + } = await getB2BCompanyUserInfo(emailAddress, customerId) await getCurrentJwtAndB2BToken(userType) @@ -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,