Skip to content

Commit

Permalink
feat: add msf support
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton committed Jan 29, 2023
1 parent 8df0a62 commit dac7446
Show file tree
Hide file tree
Showing 18 changed files with 378 additions and 170 deletions.
11 changes: 7 additions & 4 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
} from '@/hooks'

import {
getChannelId,
loginInfo,
getCurrentCustomerInfo,
getLogo,
Expand Down Expand Up @@ -58,6 +57,7 @@ export default function App() {
customerId,
BcToken,
role,
logo,
},
dispatch,
} = useContext(GlobaledContext)
Expand Down Expand Up @@ -156,11 +156,13 @@ export default function App() {
const init = async () => {
// bc token
if (!BcToken) {
await getChannelId()
await loginInfo()
}
await setLogo()
await setStorefrontConfig()

if (!logo) {
setLogo()
}
setStorefrontConfig()
if (!customerId) {
const data = await getCurrentCustomerInfo(dispatch)
if (data) gotoPage(data.role)
Expand All @@ -187,6 +189,7 @@ export default function App() {
) : null}
</ThemeFrame>
</div>

</HashRouter>
)
}
85 changes: 85 additions & 0 deletions apps/storefront/src/components/B3StoreContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {
ReactNode,
useEffect,
useContext,
} from 'react'

import {
getBCStoreChannelId,
} from '@/shared/service/b2b'

import {
GlobaledContext,
} from '@/shared/global'
import {
getCurrentStoreInfo,
} from '@/utils/loginInfo'

import {
B3SStorage,
} from '@/utils'

interface B3StoreContainerProps {
children: ReactNode
}

interface StoreItem {
channelId: number,
urls: Array<string>,
b2bEnabled: boolean,
channelLogo: string,
isEnabled: boolean,
b3ChannelId: number,
}

export interface StoreBasicInfo {
storeSites?: Array<StoreItem> | [],
storeName: string,
}

export const B3StoreContainer = (props: B3StoreContainerProps) => {
const {
state: {
storeEnabled,
},
dispatch,
} = useContext(GlobaledContext)

const getStoreBasicInfo = async () => {
const {
storeBasicInfo,
}: CustomFieldItems = await getBCStoreChannelId()

const {
channelId,
channelLogo: logo,
b2bEnabled: storeEnabled,
} = getCurrentStoreInfo((storeBasicInfo as StoreBasicInfo)?.storeSites || [])

dispatch({
type: 'common',
payload: {
logo,
storeEnabled,
currentChannelId: channelId,
storeName: storeBasicInfo.storeName,
},
})

B3SStorage.set('B3channelId', channelId)
}

useEffect(() => {
getStoreBasicInfo()
}, [])

const {
children,
} = props

return (
<>
{storeEnabled ? children : null}
</>
)
}
5 changes: 5 additions & 0 deletions apps/storefront/src/locales/en-US/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ export default {
'intl.user.forgot.forgotText.requestEmail': 'Fill in your email below to request a new password. An email will be sent to the address below containing a link to verify your email address.',
'intl.user.forgot.forgotText.resetPasswordBtn': 'Reset Password',

'intl.user.addUser.emailValidate.alreadyExitsBC': 'The email address {email} is already in use. Please enter a different one.',
'intl.user.addUser.emailValidate.multipleCustomer': 'This email is used by multiple customers in your store. Please use another email.',
'intl.user.addUser.emailValidate.companyUsed': 'This email is used by a customer within another company ({companyName}).',
'intl.user.addUser.emailValidate.alreadyExits': 'This user already exists in this company.',
'intl.user.addUser.emailValidate.usedSuperAdmin': 'This email is used by a super admin.',
}
6 changes: 6 additions & 0 deletions apps/storefront/src/locales/zh-CN/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ export default {
'intl.user.forgot.forgotText.resetPassword': '重置密码',
'intl.user.forgot.forgotText.requestEmail': '填写下面的电子邮件以请求新密码。将向以下地址发送一封电子邮件,其中包含验证您电子邮件地址的链接。',
'intl.user.forgot.forgotText.resetPasswordBtn': '重置密码',

'intl.user.addUser.emailValidate.alreadyExitsBC': '电子邮件地址{email}已在使用中。请输入另一个。',
'intl.user.addUser.emailValidate.multipleCustomer': '此电子邮件由您商店中的多个客户使用。 请使用其他电子邮件。',
'intl.user.addUser.emailValidate.companyUsed': '此电子邮件由另一家公司({companyName})内的客户使用。',
'intl.user.addUser.emailValidate.alreadyExits': '该用户已存在于此公司。',
'intl.user.addUser.emailValidate.usedSuperAdmin': '此电子邮件由超级管理员使用。',
}
26 changes: 16 additions & 10 deletions apps/storefront/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
} from '@/shared/global'

import App from './App'
import {
B3StoreContainer,
} from './components/B3StoreContainer'
import B3ThemeProvider from './theme'

import * as locales from './locales'
Expand All @@ -29,14 +32,17 @@ if (!container) {
container.className = 'bundle-namespace'

ReactDOM.createRoot(container).render(
<LangProvider
locales={locales}
supportLang={SUPPORT_LANGUAGE}
>
<GlobalProvider>
<B3ThemeProvider>
<App />
</B3ThemeProvider>
</GlobalProvider>
</LangProvider>,
<GlobalProvider>
<B3StoreContainer>
<LangProvider
locales={locales}
supportLang={SUPPORT_LANGUAGE}
>
<B3ThemeProvider>
<App />
</B3ThemeProvider>
</LangProvider>
</B3StoreContainer>
</GlobalProvider>
,
)
12 changes: 2 additions & 10 deletions apps/storefront/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
} from '@/shared/service/bc'

import {
getB2BRegisterLogo,
getBCForcePasswordReset,
getB2BLoginPageConfig,
} from '@/shared/service/b2b'
Expand All @@ -57,7 +56,6 @@ import {
} from './styled'

import {
getLogo,
LoginInfoInit,
LoginConfig,
loginCheckout,
Expand Down Expand Up @@ -95,7 +93,6 @@ export default function Login(props:RegisteredProps) {
setOpenPage,
} = props

const [logo, setLogo] = useState('')
const [showTipInfo, setShowTipInfo] = useState<boolean>(true)
const [flag, setLoginFlag] = useState<string>('')
const [loginAccount, setLoginAccount] = useState<LoginConfig>({
Expand All @@ -112,17 +109,14 @@ export default function Login(props:RegisteredProps) {
const {
state: {
isCheckout,
logo,
},
dispatch,
} = useContext(GlobaledContext)

useEffect(() => {
const init = async () => {
try {
const {
quoteConfig,
} = await getB2BRegisterLogo()

const {
loginPageConfig: {
value: {
Expand Down Expand Up @@ -153,8 +147,6 @@ export default function Login(props:RegisteredProps) {
displayStoreLogo,
}

const registerLogo = getLogo(quoteConfig)

const {
search,
} = location
Expand All @@ -181,7 +173,7 @@ export default function Login(props:RegisteredProps) {

// setChannelId(getChannelId)
setLoginInfo(Info)
setLogo(registerLogo)

setLoading(false)
} catch (e) {
console.log(e)
Expand Down
33 changes: 10 additions & 23 deletions apps/storefront/src/pages/registered/Registered.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import type {
} from '@b3/hooks'

import {
getB2BRegisterLogo,
getB2BCountries,
storeB2BBasicInfo,
getB2BAccountFormFields,
} from '@/shared/service/b2b'

Expand Down Expand Up @@ -55,7 +53,6 @@ import {
} from '@/components'

import {
getRegisterLogo,
companyAttachmentsFields,
getAccountFormFields,
RegisterFieldsItems,
Expand Down Expand Up @@ -85,10 +82,18 @@ export default function Registered(props: RegisteredProps) {

const [activeStep, setActiveStep] = useState(0)

const [logo, setLogo] = useState('')

const b3Lang = useB3Lang()

const {
state: {
isCheckout,
isCloseGotoBCHome,
logo,
storeName,
},
dispatch: globalDispatch,
} = useContext(GlobaledContext)

const {
state: {
isLoading,
Expand Down Expand Up @@ -128,18 +133,9 @@ export default function Registered(props: RegisteredProps) {
const bcAccountFormFields = getAccountFormFields(accountFormFields[0]?.accountFormFields || [])
const b2bAccountFormFields = getAccountFormFields(accountFormFields[1]?.accountFormFields || [])

const {
quoteConfig,
} = await getB2BRegisterLogo()
const {
countries,
} = await getB2BCountries()
const {
storeBasicInfo: {
storeName,
},
} = await storeB2BBasicInfo()
const registerLogo = getRegisterLogo(quoteConfig)

const newAddressInformationFields = b2bAccountFormFields.address?.map((addressFields: Partial<RegisterFieldsItems>):Partial<RegisterFieldsItems> => {
if (addressFields.name === 'country') {
Expand Down Expand Up @@ -181,7 +177,6 @@ export default function Registered(props: RegisteredProps) {
},
})
}
setLogo(registerLogo)
} catch (e) {
console.log(e)
}
Expand Down Expand Up @@ -214,14 +209,6 @@ export default function Registered(props: RegisteredProps) {
setActiveStep((prevActiveStep: number) => prevActiveStep - 1)
}

const {
state: {
isCheckout,
isCloseGotoBCHome,
},
dispatch: globalDispatch,
} = useContext(GlobaledContext)

const clearRegisterInfo = () => {
if (dispatch) {
dispatch({
Expand Down
Loading

0 comments on commit dac7446

Please sign in to comment.