diff --git a/apps/storefront/src/components/RegisteredCloseButton.tsx b/apps/storefront/src/components/RegisteredCloseButton.tsx index 9ecdd974..f0d02dd7 100644 --- a/apps/storefront/src/components/RegisteredCloseButton.tsx +++ b/apps/storefront/src/components/RegisteredCloseButton.tsx @@ -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' @@ -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('/') diff --git a/apps/storefront/src/shared/global/context/config.ts b/apps/storefront/src/shared/global/context/config.ts index 83800012..13b9915d 100644 --- a/apps/storefront/src/shared/global/context/config.ts +++ b/apps/storefront/src/shared/global/context/config.ts @@ -30,6 +30,12 @@ export interface ChannelCurrenciesProps { enabled_currencies: Array } +export interface QuoteConfigProps { + key: string + value: string + extraFields: CustomFieldItems +} + export interface CurrencyProps { auto_update: boolean country_iso2: string @@ -105,7 +111,7 @@ export interface GlobalState { cartQuoteEnabled: boolean shoppingListEnabled: boolean registerEnabled: boolean - quoteConfig: CustomFieldItems[] + quoteConfig: QuoteConfigProps[] currencies: { channelCurrencies: ChannelCurrenciesProps currencies: CurrencyProps diff --git a/apps/storefront/src/shared/routes/routes.ts b/apps/storefront/src/shared/routes/routes.ts index c3e07fde..9270d32a 100644 --- a/apps/storefront/src/shared/routes/routes.ts +++ b/apps/storefront/src/shared/routes/routes.ts @@ -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')) @@ -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 @@ -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 } diff --git a/apps/storefront/vite.config.ts b/apps/storefront/vite.config.ts index 6bbc2b4e..71270b42 100644 --- a/apps/storefront/vite.config.ts +++ b/apps/storefront/vite.config.ts @@ -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'], + }, + }, + }, + } })