Skip to content

Commit

Permalink
feat: add store type set
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton committed Feb 3, 2023
1 parent fed8834 commit 7aac756
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import {
getB2BRegisterLogo,
getStorefrontConfig,
setChannelStoreType,
} from '@/shared/service/b2b'

import {
Expand Down Expand Up @@ -58,6 +59,7 @@ export default function App() {
BcToken,
role,
logo,
bcChannelId,
},
dispatch,
} = useContext(GlobaledContext)
Expand Down Expand Up @@ -163,6 +165,7 @@ export default function App() {
setLogo()
}
setStorefrontConfig()
setChannelStoreType(bcChannelId)
if (!customerId) {
const data = await getCurrentCustomerInfo(dispatch)
if (data) gotoPage(data.role)
Expand Down
2 changes: 2 additions & 0 deletions apps/storefront/src/components/B3StoreContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const B3StoreContainer = (props: B3StoreContainerProps) => {
const {
channelId,
channelLogo: logo,
b3ChannelId: bcChannelId,
b2bEnabled: storeEnabled,
} = getCurrentStoreInfo((storeBasicInfo as StoreBasicInfo)?.storeSites || [])

Expand All @@ -62,6 +63,7 @@ export const B3StoreContainer = (props: B3StoreContainerProps) => {
logo,
storeEnabled,
currentChannelId: channelId,
bcChannelId,
storeName: storeBasicInfo.storeName,
},
})
Expand Down
2 changes: 2 additions & 0 deletions apps/storefront/src/shared/global/context/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface GlobalState {
storeEnabled: boolean,
storeName: string,
currentChannelId: number,
bcChannelId: number,
}

export const initState = {
Expand Down Expand Up @@ -100,6 +101,7 @@ export const initState = {
storeEnabled: false,
storeName: '',
currentChannelId: 1,
bcChannelId: 1,
}

export interface GlobalAction {
Expand Down
13 changes: 13 additions & 0 deletions apps/storefront/src/shared/service/b2b/api/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import {
B3Request,
} from '../../request/b3Fetch'

import {
RequestType,
} from '../../request/base'
import {
storeHash,
} from '../../../../utils/basicConfig'

interface UploadFileData {
file: File,
type: string
Expand All @@ -19,3 +26,9 @@ export const uploadB2BFile = (data: UploadFileData) => {

return B3Request.fileUpload('/api/v2/media/upload', formData)
}

export const setChannelStoreType = (bcChannelId: number): CustomFieldItems => B3Request.put('/api/v2/store-configs/channel-storefront-type', RequestType.B2BRest, {
bcChannelId,
storefrontType: 1,
storeHash,
})
2 changes: 2 additions & 0 deletions apps/storefront/src/shared/service/b2b/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {

import {
uploadB2BFile,
setChannelStoreType,
} from './api/global'

import {
Expand Down Expand Up @@ -149,4 +150,5 @@ export {
deleteB2BShoppingListItem,
checkUserEmail,
checkUserBCEmail,
setChannelStoreType,
}
9 changes: 9 additions & 0 deletions apps/storefront/src/shared/service/request/b3Fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ export const B3Request = {
},
}, type)
},
put: function put<T>(url: string, type: string, data: T): Promise<any> {
return request(url, {
body: JSON.stringify(data),
method: 'PUT',
headers: {
'content-type': 'application/json',
},
}, type)
},
fileUpload: function fileUpload<T, Y>(url: string, formData: T, config?: Y): Promise<any> {
return request(`${B2B_BASIC_URL}${url}`, {
method: 'POST',
Expand Down
2 changes: 2 additions & 0 deletions apps/storefront/src/utils/loginInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface ChannelIdProps {
urls: Array<string>,
b2bEnabled: boolean,
channelLogo: string,
b3ChannelId?: number,
}

type B2BToken = {
Expand Down Expand Up @@ -58,6 +59,7 @@ export const getCurrentStoreInfo = (storeSites: Array<ChannelIdProps>) => {
urls: [],
b2bEnabled: true,
channelLogo: '',
b3ChannelId: 16,
}

const {
Expand Down

0 comments on commit 7aac756

Please sign in to comment.