Skip to content

Commit

Permalink
fix: fix: quote shopping nav authority and closing the login page got…
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 authored and CarlLiu2023 committed Jul 28, 2023
1 parent 21286e5 commit b976e51
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 48 deletions.
8 changes: 2 additions & 6 deletions apps/storefront/src/components/RegisteredCloseButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Dispatch, SetStateAction, useContext } from 'react'
import { useNavigate } from 'react-router-dom'
import globalB3 from '@b3/global-b3'
import type { OpenPageState } from '@b3/hooks'
import { Box } from '@mui/material'

Expand All @@ -16,15 +15,12 @@ export default function RegisteredCloseButton(props: CloseButtonProps) {
const { setOpenPage } = props

const {
state: { isCheckout, isCloseGotoBCHome },
state: { isCloseGotoBCHome },
} = useContext(GlobaledContext)
const navigate = useNavigate()

const handleCloseForm = () => {
if (
isCloseGotoBCHome ||
(isCheckout && document.getElementById(globalB3['dom.openB3Checkout']))
) {
if (isCloseGotoBCHome) {
window.location.href = '/'
} else {
navigate('/')
Expand Down
8 changes: 7 additions & 1 deletion apps/storefront/src/shared/global/context/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export interface ChannelCurrenciesProps {
enabled_currencies: Array<string>
}

export interface QuoteConfigProps {
key: string
value: string
extraFields: CustomFieldItems
}

export interface CurrencyProps {
auto_update: boolean
country_iso2: string
Expand Down Expand Up @@ -105,7 +111,7 @@ export interface GlobalState {
cartQuoteEnabled: boolean
shoppingListEnabled: boolean
registerEnabled: boolean
quoteConfig: CustomFieldItems[]
quoteConfig: QuoteConfigProps[]
currencies: {
channelCurrencies: ChannelCurrenciesProps
currencies: CurrencyProps
Expand Down
21 changes: 13 additions & 8 deletions apps/storefront/src/shared/routes/routes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { lazy } from 'react'
import { matchPath } from 'react-router-dom'

import { GlobalState } from '@/shared/global/context/config'
import { GlobalState, QuoteConfigProps } from '@/shared/global/context/config'

const OrderList = lazy(() => import('../../pages/order/MyOrder'))

Expand Down Expand Up @@ -294,21 +294,24 @@ const getAllowedRoutes = (globalState: GlobalState): RouteItem[] => {
if (item.configKey === 'quotes') {
if (role === 100) {
const quoteGuest =
quoteConfig.find((config: any) => config.key === 'quote_for_guest')
?.value || '0'
quoteConfig.find(
(config: QuoteConfigProps) => config.key === 'quote_for_guest'
)?.value || '0'
return quoteGuest === '1' && navListKey
}
if (role === 99) {
const quoteIndividualCustomer =
quoteConfig.find(
(config: any) => config.key === 'quote_for_individual_customer'
(config: QuoteConfigProps) =>
config.key === 'quote_for_individual_customer'
)?.value || '0'
return quoteIndividualCustomer === '1' && navListKey
}
}
if (item.configKey === 'shoppingLists') {
const shoppingListOnProductPage = quoteConfig.find(
(config: any) => config.key === 'shopping_list_on_product_page'
(config: QuoteConfigProps) =>
config.key === 'shopping_list_on_product_page'
)?.extraFields
if (role === 100) {
return shoppingListOnProductPage?.guest && navListKey
Expand All @@ -327,14 +330,16 @@ const getAllowedRoutes = (globalState: GlobalState): RouteItem[] => {

if (item.configKey === 'quotes') {
const quoteB2B =
quoteConfig.find((config: any) => config.key === 'quote_for_b2b')
?.value || '0'
quoteConfig.find(
(config: QuoteConfigProps) => config.key === 'quote_for_b2b'
)?.value || '0'
return storefrontConfig.quotes && quoteB2B === '1'
}

if (item.configKey === 'shoppingLists') {
const shoppingListOnProductPage = quoteConfig.find(
(config: any) => config.key === 'shopping_list_on_product_page'
(config: QuoteConfigProps) =>
config.key === 'shopping_list_on_product_page'
)?.extraFields
return storefrontConfig.quotes && shoppingListOnProductPage?.b2b
}
Expand Down
71 changes: 38 additions & 33 deletions apps/storefront/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,48 @@
import legacy from '@vitejs/plugin-legacy'
import react from '@vitejs/plugin-react'
import path from 'path'
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'

export default defineConfig({
plugins: [
legacy({
targets: ['defaults'],
}),
react(),
],
server: {
port: 3001,
proxy: {
'/bigcommerce': {
target: 'https://msfremote-frontend-demo.mybigcommerce.com/',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/bigcommerce/, ''),
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd())
return {
plugins: [
legacy({
targets: ['defaults'],
}),
react(),
],
server: {
port: 3001,
proxy: {
'/bigcommerce': {
target:
env?.VITE_PROXY_SHOPPING_URL ||
'https://msfremote-frontend-demo.mybigcommerce.com/',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/bigcommerce/, ''),
},
},
},
},
test: {
environment: 'jsdom',
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
test: {
environment: 'jsdom',
},
},
build: {
rollupOptions: {
manualChunks: {
mui: ['@mui/material'],
dropzone: ['react-mui-dropzone'],
muiIcon: ['@mui/icons-material'],
muiPickers: ['@mui/x-date-pickers'],
dateFns: ['date-fns'],
lang: ['@b3/lang'],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
},
build: {
rollupOptions: {
manualChunks: {
mui: ['@mui/material'],
dropzone: ['react-mui-dropzone'],
muiIcon: ['@mui/icons-material'],
muiPickers: ['@mui/x-date-pickers'],
dateFns: ['date-fns'],
lang: ['@b3/lang'],
},
},
},
}
})

0 comments on commit b976e51

Please sign in to comment.