Skip to content

Commit

Permalink
feat(BUN-1630): use new format for storeBasicInfo query (#807)
Browse files Browse the repository at this point in the history
feat(BUN-1630): use new format for storeBasicInfo query (#806)
  • Loading branch information
bc-marco authored and bc-micah committed Nov 10, 2023
1 parent e10ecff commit 3ec504f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions apps/storefront/.env-example
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions apps/storefront/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
VITE_STORE_HASH,
VITE_CATPCHA_SETKEY,
VITE_LOCAL_DEBUG,
VITE_CHANNEL_ID,
} = import.meta.env

window.B3Local = {
Expand All @@ -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',
Expand Down
9 changes: 2 additions & 7 deletions apps/storefront/src/components/B3StoreContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions apps/storefront/src/shared/service/b2b/graphql/register.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convertArrayToGraphql, storeHash } from '../../../../utils'
import { channelId,convertArrayToGraphql, storeHash } from '../../../../utils'
import B3Request from '../../request/b3Fetch'

const getAccountFormFields = (type: number) => `{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -232,5 +233,6 @@ export const getBCForcePasswordReset = (email: string): CustomFieldItems =>

export const getBCStoreChannelId = (): CustomFieldItems =>
B3Request.graphqlB2B({
query: getStoreChannelId(),
query: getStoreChannelId,
variables: { storeHash, bcChannelId: channelId },
})
10 changes: 6 additions & 4 deletions apps/storefront/src/utils/basicConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -13,5 +17,3 @@ const bcBaseUrl = () => {

return isLocalDebugging ? '/bigcommerce' : bcUrl
}

export { bcBaseUrl, storeHash }
3 changes: 1 addition & 2 deletions apps/storefront/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -53,6 +52,7 @@ import {
import { validatorRules } from './validatorRules'

export * from './b3Product/b3Product'
export * from './basicConfig'
export * from './masquerade'
export * from './setTranslation'
export {
Expand Down Expand Up @@ -109,6 +109,5 @@ export {
serialize,
showPageMask,
snackbar,
storeHash,
validatorRules,
}

0 comments on commit 3ec504f

Please sign in to comment.