From 3ec504f35e64cca305726ebde41f67756d96b60b Mon Sep 17 00:00:00 2001 From: bc-marco <109162781+bc-marco@users.noreply.github.com> Date: Tue, 31 Oct 2023 18:37:24 -0600 Subject: [PATCH] feat(BUN-1630): use new format for storeBasicInfo query (#807) feat(BUN-1630): use new format for storeBasicInfo query (#806) --- apps/storefront/.env-example | 1 + apps/storefront/index.html | 2 ++ apps/storefront/src/components/B3StoreContainer.tsx | 9 ++------- .../src/shared/service/b2b/graphql/register.ts | 10 ++++++---- apps/storefront/src/utils/basicConfig.ts | 10 ++++++---- apps/storefront/src/utils/index.ts | 3 +-- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/apps/storefront/.env-example b/apps/storefront/.env-example index 6cf03ed9..50770bca 100644 --- a/apps/storefront/.env-example +++ b/apps/storefront/.env-example @@ -1,6 +1,7 @@ VITE_B2B_URL=http://localhost:9000 VITE_B2B_SOCKET_URL=http://localhost:9000 VITE_TRANSLATION_SERVICE_URL=http://localhost:5000 +VITE_CHANNEL_ID=1 VITE_STORE_HASH=store_hash VITE_CATPCHA_SETKEY=captcha_setkey VITE_B2B_CLIENT_ID=client_id diff --git a/apps/storefront/index.html b/apps/storefront/index.html index 7266afaa..17ba942d 100644 --- a/apps/storefront/index.html +++ b/apps/storefront/index.html @@ -12,6 +12,7 @@ VITE_STORE_HASH, VITE_CATPCHA_SETKEY, VITE_LOCAL_DEBUG, + VITE_CHANNEL_ID, } = import.meta.env window.B3Local = { @@ -21,6 +22,7 @@ b2b_socket_url: VITE_B2B_SOCKET_URL, captcha_setkey: VITE_CATPCHA_SETKEY, is_local_debugging: VITE_LOCAL_DEBUG === 'TRUE', + channel_id: VITE_CHANNEL_ID, }, 'dom.checkoutRegisterParentElement': '#b2bParent', 'dom.openB3Checkout': 'childB2b', diff --git a/apps/storefront/src/components/B3StoreContainer.tsx b/apps/storefront/src/components/B3StoreContainer.tsx index 2f293dd5..029c0336 100644 --- a/apps/storefront/src/components/B3StoreContainer.tsx +++ b/apps/storefront/src/components/B3StoreContainer.tsx @@ -4,7 +4,6 @@ import { GlobaledContext } from '@/shared/global' import { getBCStoreChannelId } from '@/shared/service/b2b' import { setHeadLessBcUrl, store } from '@/store' import { B3SStorage, setGlobalTranslation, storeHash } from '@/utils' -import { getCurrentStoreInfo } from '@/utils/loginInfo' import B3PageMask from './loadding/B3PageMask' import showPageMask from './loadding/B3showPageMask' @@ -47,11 +46,7 @@ export default function B3StoreContainer(props: B3StoreContainerProps) { try { const { storeBasicInfo }: CustomFieldItems = await getBCStoreChannelId() - - const storeInfo = getCurrentStoreInfo( - (storeBasicInfo as StoreBasicInfo)?.storeSites || [], - storeBasicInfo.multiStorefrontEnabled - ) + const [storeInfo] = storeBasicInfo.storeSites if (!storeInfo) return @@ -64,7 +59,7 @@ export default function B3StoreContainer(props: B3StoreContainerProps) { } = storeInfo const bcUrl = - platform === 'next' + platform !== 'bigcommerce' ? `https://store-${storeHash}-${channelId}.mybigcommerce.com` : '' const isEnabled = storeBasicInfo?.multiStorefrontEnabled diff --git a/apps/storefront/src/shared/service/b2b/graphql/register.ts b/apps/storefront/src/shared/service/b2b/graphql/register.ts index 8e8a81cd..ccefe569 100644 --- a/apps/storefront/src/shared/service/b2b/graphql/register.ts +++ b/apps/storefront/src/shared/service/b2b/graphql/register.ts @@ -1,4 +1,4 @@ -import { convertArrayToGraphql, storeHash } from '../../../../utils' +import { channelId,convertArrayToGraphql, storeHash } from '../../../../utils' import B3Request from '../../request/b3Fetch' const getAccountFormFields = (type: number) => `{ @@ -145,8 +145,9 @@ const getForcePasswordReset = (email: string) => `{ } }` -const getStoreChannelId = () => `{ - storeBasicInfo(storeHash: "${storeHash}"){ +const getStoreChannelId = ` +query getStoreBasicInfo($storeHash: String!, $bcChannelId: Int) { + storeBasicInfo(storeHash: $storeHash, bcChannelId: $bcChannelId){ storeName storeAddress storeCountry @@ -232,5 +233,6 @@ export const getBCForcePasswordReset = (email: string): CustomFieldItems => export const getBCStoreChannelId = (): CustomFieldItems => B3Request.graphqlB2B({ - query: getStoreChannelId(), + query: getStoreChannelId, + variables: { storeHash, bcChannelId: channelId }, }) diff --git a/apps/storefront/src/utils/basicConfig.ts b/apps/storefront/src/utils/basicConfig.ts index 6df54768..2b12afa7 100644 --- a/apps/storefront/src/utils/basicConfig.ts +++ b/apps/storefront/src/utils/basicConfig.ts @@ -2,9 +2,13 @@ import globalB3 from '@b3/global-b3' import { store } from '@/store' -const storeHash = globalB3?.setting?.store_hash +export const storeHash = globalB3?.setting?.store_hash -const bcBaseUrl = () => { +export const channelId = Number.isInteger(globalB3?.setting?.channel_id) + ? globalB3?.setting?.channel_id + : Number.parseInt(globalB3?.setting?.channel_id, 10) + +export const bcBaseUrl = () => { const { global: { bcUrl }, } = store.getState() @@ -13,5 +17,3 @@ const bcBaseUrl = () => { return isLocalDebugging ? '/bigcommerce' : bcUrl } - -export { bcBaseUrl, storeHash } diff --git a/apps/storefront/src/utils/index.ts b/apps/storefront/src/utils/index.ts index 251c196b..83c39634 100644 --- a/apps/storefront/src/utils/index.ts +++ b/apps/storefront/src/utils/index.ts @@ -36,7 +36,6 @@ import { B3LStorage, B3SStorage } from './b3Storage' import { globalSnackbar, snackbar } from './b3Tip' import b3TriggerCartNumber from './b3TriggerCartNumber' import getCookie from './b3utils' -import { storeHash } from './basicConfig' import { getActiveCurrencyInfo, getDefaultCurrencyInfo } from './currencyUtils' import { convertArrayToGraphql, @@ -53,6 +52,7 @@ import { import { validatorRules } from './validatorRules' export * from './b3Product/b3Product' +export * from './basicConfig' export * from './masquerade' export * from './setTranslation' export { @@ -109,6 +109,5 @@ export { serialize, showPageMask, snackbar, - storeHash, validatorRules, }