Skip to content

Commit

Permalink
fix: storeBasicInfo isEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-liu-smile authored and BrianJiang2021 committed Apr 25, 2023
1 parent 2542bf8 commit 999e279
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 30 deletions.
2 changes: 1 addition & 1 deletion apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default function App() {
// await getTaxZoneRates()
await Promise.all([
getStoreTaxZoneRates(),
setStorefrontConfig(dispatch),
setStorefrontConfig(dispatch, currentChannelId),
getTemPlateConfig(currentChannelId, styleDispatch, dispatch),
])
const userInfo = {
Expand Down
13 changes: 8 additions & 5 deletions apps/storefront/src/components/B3StoreContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { B3PageMask, showPageMask } from '@/components'
import { GlobaledContext } from '@/shared/global'
import { getBCStoreChannelId } from '@/shared/service/b2b'
import { B3SStorage } from '@/utils'
import { getCurrenciesInfo, getCurrentStoreInfo } from '@/utils/loginInfo'
import { getCurrentStoreInfo } from '@/utils/loginInfo'

interface B3StoreContainerProps {
children: ReactNode
Expand Down Expand Up @@ -42,7 +42,6 @@ export function B3StoreContainer(props: B3StoreContainerProps) {
try {
const { storeBasicInfo }: CustomFieldItems = await getBCStoreChannelId()

B3SStorage.set('timeFormat', storeBasicInfo.timeFormat)
const {
channelId,
b3ChannelId: b2bChannelId,
Expand All @@ -51,22 +50,26 @@ export function B3StoreContainer(props: B3StoreContainerProps) {
(storeBasicInfo as StoreBasicInfo)?.storeSites || []
)

await getCurrenciesInfo(dispatch, String(channelId))
const isEnabled = storeBasicInfo?.multiStorefrontEnabled
? storeEnabled
: true

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

if (!storeEnabled) {
if (!isEnabled) {
showPageMask(dispatch, false)
}

B3SStorage.set('timeFormat', storeBasicInfo.timeFormat)
B3SStorage.set('B3channelId', channelId)
} catch (error) {
showPageMask(dispatch, false)
Expand Down
1 change: 1 addition & 0 deletions apps/storefront/src/shared/service/b2b/graphql/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const getStoreChannelId = () => `{
storeCountry
storeLogo
storeUrl
multiStorefrontEnabled
storeSites{
channelId
urls
Expand Down
4 changes: 1 addition & 3 deletions apps/storefront/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
serialize,
} from './b3AddToShoppingList'
import currencyFormat from './b3CurrencyFormat'
import { displayExtendedFormat,displayFormat } from './b3DateFormat'
import { displayExtendedFormat, displayFormat } from './b3DateFormat'
import { getLogo, getQuoteEnabled } from './b3Init'
import { showPageMask } from './b3PageMask'
import distanceDay from './b3Picker'
Expand All @@ -25,7 +25,6 @@ import {
} from './graphqlDataConvert'
import {
clearCurrentCustomerInfo,
getCurrenciesInfo,
getCurrentCustomerInfo,
getCurrentJwt,
getSearchVal,
Expand Down Expand Up @@ -60,7 +59,6 @@ export {
displayFormat,
distanceDay,
getCookie,
getCurrenciesInfo,
getCurrentCustomerInfo,
getCurrentJwt,
getDefaultCurrencyInfo,
Expand Down
20 changes: 0 additions & 20 deletions apps/storefront/src/utils/loginInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
getB2BCompanyUserInfo,
getB2BToken,
getBCToken,
getCurrencies,
getUserCompany,
} from '@/shared/service/b2b'
import { getBcCurrentJWT, getCustomerInfo } from '@/shared/service/bc'
Expand Down Expand Up @@ -88,22 +87,6 @@ export const loginInfo = async () => {
B3SStorage.set('BcToken', token)
}

export const getCurrenciesInfo = async (
dispatch: DispatchProps,
channelId: string
) => {
const { currencies } = await getCurrencies(channelId)

dispatch({
type: 'common',
payload: {
currencies,
},
})

B3SStorage.set('currencies', currencies)
}

export const clearCurrentCustomerInfo = async (dispatch: DispatchProps) => {
B3SStorage.set('B3CustomerInfo', {})
B3SStorage.set('B3CustomerId', '')
Expand Down Expand Up @@ -236,9 +219,6 @@ export const agentInfo = async (

export const getCurrentCustomerInfo = async (dispatch: DispatchProps) => {
try {
const channelId = B3SStorage.get('B3channelId')
await getCurrenciesInfo(dispatch, channelId)

const {
data: { customer },
} = await getCustomerInfo()
Expand Down
11 changes: 10 additions & 1 deletion apps/storefront/src/utils/storefrontConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { CustomStyleButtonState } from '@/shared/customStyleButtton/context/conf
import { DispatchProps } from '@/shared/global/context/config'
import {
getB2BRegisterLogo,
getCurrencies,
getStorefrontConfig,
getStorefrontConfigs,
getTaxZoneRates,
} from '@/shared/service/b2b'
import { setTaxZoneRates, store } from '@/store'
import { B3SStorage } from '@/utils'

// import {
// storeHash,
Expand Down Expand Up @@ -159,15 +161,22 @@ const getQuoteConfig = async (dispatch: DispatchProps) => {
})
}

const setStorefrontConfig = async (dispatch: DispatchProps) => {
const setStorefrontConfig = async (
dispatch: DispatchProps,
currentChannelId: string
) => {
const {
storefrontConfig: { config: storefrontConfig },
} = await getStorefrontConfig()

const { currencies } = await getCurrencies(currentChannelId)
B3SStorage.set('currencies', currencies)

dispatch({
type: 'common',
payload: {
storefrontConfig,
currencies,
},
})
}
Expand Down

0 comments on commit 999e279

Please sign in to comment.