From 999e279ce176cad7e90534b64f0a4d8a386166a0 Mon Sep 17 00:00:00 2001 From: kris-liu-smile Date: Tue, 25 Apr 2023 15:24:26 +0800 Subject: [PATCH] fix: storeBasicInfo isEnabled --- apps/storefront/src/App.tsx | 2 +- .../src/components/B3StoreContainer.tsx | 13 +++++++----- .../shared/service/b2b/graphql/register.ts | 1 + apps/storefront/src/utils/index.ts | 4 +--- apps/storefront/src/utils/loginInfo.ts | 20 ------------------- apps/storefront/src/utils/storefrontConfig.ts | 11 +++++++++- 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/apps/storefront/src/App.tsx b/apps/storefront/src/App.tsx index 450975eb..63e040c7 100644 --- a/apps/storefront/src/App.tsx +++ b/apps/storefront/src/App.tsx @@ -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 = { diff --git a/apps/storefront/src/components/B3StoreContainer.tsx b/apps/storefront/src/components/B3StoreContainer.tsx index 6fa109a6..2a72cc1d 100644 --- a/apps/storefront/src/components/B3StoreContainer.tsx +++ b/apps/storefront/src/components/B3StoreContainer.tsx @@ -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 @@ -42,7 +42,6 @@ export function B3StoreContainer(props: B3StoreContainerProps) { try { const { storeBasicInfo }: CustomFieldItems = await getBCStoreChannelId() - B3SStorage.set('timeFormat', storeBasicInfo.timeFormat) const { channelId, b3ChannelId: b2bChannelId, @@ -51,11 +50,14 @@ 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, @@ -63,10 +65,11 @@ export function B3StoreContainer(props: B3StoreContainerProps) { }, }) - if (!storeEnabled) { + if (!isEnabled) { showPageMask(dispatch, false) } + B3SStorage.set('timeFormat', storeBasicInfo.timeFormat) B3SStorage.set('B3channelId', channelId) } catch (error) { showPageMask(dispatch, false) diff --git a/apps/storefront/src/shared/service/b2b/graphql/register.ts b/apps/storefront/src/shared/service/b2b/graphql/register.ts index 2a535e38..a0c47491 100644 --- a/apps/storefront/src/shared/service/b2b/graphql/register.ts +++ b/apps/storefront/src/shared/service/b2b/graphql/register.ts @@ -146,6 +146,7 @@ const getStoreChannelId = () => `{ storeCountry storeLogo storeUrl + multiStorefrontEnabled storeSites{ channelId urls diff --git a/apps/storefront/src/utils/index.ts b/apps/storefront/src/utils/index.ts index 0f0bb63a..25a0789c 100644 --- a/apps/storefront/src/utils/index.ts +++ b/apps/storefront/src/utils/index.ts @@ -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' @@ -25,7 +25,6 @@ import { } from './graphqlDataConvert' import { clearCurrentCustomerInfo, - getCurrenciesInfo, getCurrentCustomerInfo, getCurrentJwt, getSearchVal, @@ -60,7 +59,6 @@ export { displayFormat, distanceDay, getCookie, - getCurrenciesInfo, getCurrentCustomerInfo, getCurrentJwt, getDefaultCurrencyInfo, diff --git a/apps/storefront/src/utils/loginInfo.ts b/apps/storefront/src/utils/loginInfo.ts index cb2d3a03..375dfcf8 100644 --- a/apps/storefront/src/utils/loginInfo.ts +++ b/apps/storefront/src/utils/loginInfo.ts @@ -4,7 +4,6 @@ import { getB2BCompanyUserInfo, getB2BToken, getBCToken, - getCurrencies, getUserCompany, } from '@/shared/service/b2b' import { getBcCurrentJWT, getCustomerInfo } from '@/shared/service/bc' @@ -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', '') @@ -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() diff --git a/apps/storefront/src/utils/storefrontConfig.ts b/apps/storefront/src/utils/storefrontConfig.ts index ebf5c7b6..0b64ce8e 100644 --- a/apps/storefront/src/utils/storefrontConfig.ts +++ b/apps/storefront/src/utils/storefrontConfig.ts @@ -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, @@ -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, }, }) }