Skip to content

Commit

Permalink
fix: changing imports to avoid cycle dependencies (#1024)
Browse files Browse the repository at this point in the history
* fix: changing imports to avoid cycle dependencies

* fix: reset before assing new values on quoteinfo slice

Co-authored-by: Marco Loyo <marco.loyo@bigcommerce.com>
  • Loading branch information
deov31 and bc-marco authored Apr 23, 2024
1 parent 4676f7f commit 905d8e2
Show file tree
Hide file tree
Showing 51 changed files with 129 additions and 178 deletions.
1 change: 0 additions & 1 deletion apps/storefront/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
{
"files": [
"src/pages/**/*.{ts,tsx}",
"src/utils/**/*.{ts,tsx}",
"src/components/**/*.{ts,tsx}",
"src/hooks/dom/*.ts",
"src/hooks/*.ts",
Expand Down
22 changes: 13 additions & 9 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ import { GlobaledContext } from '@/shared/global'
import { gotoAllowedAppPage } from '@/shared/routes'
import { setChannelStoreType } from '@/shared/service/b2b'
import {
clearInvoiceCart,
getCompanyUserInfo,
getCurrentCustomerInfo,
getQuoteEnabled,
getStoreTaxZoneRates,
getTemPlateConfig,
handleHideRegisterPage,
isUserGotoLogin,
loginInfo,
openPageByClick,
removeBCMenus,
setStorefrontConfig,
} from '@/utils'

import { getCompanyInfo } from './utils/loginInfo'
import clearInvoiceCart from './utils/b3ClearCart'
import { isUserGotoLogin } from './utils/b3logout'
import {
getCompanyInfo,
getCompanyUserInfo,
getCurrentCustomerInfo,
loginInfo,
} from './utils/loginInfo'
import {
getStoreTaxZoneRates,
getTemPlateConfig,
setStorefrontConfig,
} from './utils/storefrontConfig'
import {
isB2BUserSelector,
setGlabolCommonState,
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/buyerPortal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { b2bLogger } from '@/utils'
import b2bLogger from './utils/b3Logger'

const { MODE: mode, VITE_LOCAL_GRAPHQL_ORIGIN } = import.meta.env

Expand Down
11 changes: 4 additions & 7 deletions apps/storefront/src/components/HeadlessController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ import {
import { setB2BToken } from '@/store/slices/company'
import { OpenPageState } from '@/types/hooks'
import { QuoteItem } from '@/types/quotes'
import {
endMasquerade,
getCurrentCustomerInfo,
LineItems,
startMasquerade,
} from '@/utils'
import CallbackManager from '@/utils/b3Callbacks'
import { LineItems } from '@/utils/b3Product/b3Product'
import createShoppingList from '@/utils/b3ShoppingList/b3ShoppingList'
import { getCurrentCustomerInfo } from '@/utils/loginInfo'
import { endMasquerade, startMasquerade } from '@/utils/masquerade'

export interface FormatedQuoteItem
extends Omit<
Expand Down Expand Up @@ -91,7 +88,7 @@ export default function HeadlessController({
const role = useAppSelector(({ company }) => company.customer.role)
const platform = useAppSelector(({ global }) => global.storeInfo.platform)
const productList = useAppSelector(formatedQuoteDraftListSelector)
const B2BToken = useAppSelector(({company}) => company.tokens.B2BToken);
const B2BToken = useAppSelector(({ company }) => company.tokens.B2BToken)

const {
state: { addQuoteBtn, shoppingListBtn, addToAllQuoteBtn },
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/components/layout/B3Mainheader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useMobile from '@/hooks/useMobile'
import { CustomStyleContext } from '@/shared/customStyleButtton'
import { GlobaledContext } from '@/shared/global'
import { useAppSelector } from '@/store'
import { b3TriggerCartNumber } from '@/utils'
import b3TriggerCartNumber from '@/utils/b3TriggerCartNumber'

import { getContrastColor } from '../outSideComponents/utils/b3CustomStyles'

Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/components/upload/B3Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
useAppSelector,
} from '@/store'
import { Currency } from '@/types'
import { b2bLogger } from '@/utils'
import b2bLogger from '@/utils/b3Logger'

import B3Dialog from '../B3Dialog'

Expand Down
5 changes: 3 additions & 2 deletions apps/storefront/src/hooks/dom/useMyQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ const useMyQuote = ({
)
const b2bId = useAppSelector(({ company }) => company.customer.b2bId)
useEffect(() => {
const isLogin = role !== CustomerRole.GUEST
const isLoginAndNotB2CAccount =
role !== CustomerRole.GUEST && role !== CustomerRole.B2C

if (
quoteDraftUserId &&
isLogin &&
isLoginAndNotB2CAccount &&
+quoteDraftUserId !== 0 &&
+quoteDraftUserId !== b2bId
) {
Expand Down
19 changes: 10 additions & 9 deletions apps/storefront/src/hooks/dom/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ import { getCart } from '@/shared/service/bc/graphql/cart'
import { store } from '@/store'
import { OpenPageState } from '@/types/hooks'
import {
addQuoteDraftProduce,
addQuoteDraftProducts,
b2bLogger,
B3LStorage,
B3SStorage,
calculateProductsPrice,
getCalculatedProductPrice,
getCookie,
getProductOptionList,
globalSnackbar,
isAllRequiredOptionFilled,
LineItems,
serialize,
validProductQty,
} from '@/utils'
import { getProductOptionList, isAllRequiredOptionFilled } from '@/utils/b3AddToShoppingList'
import b2bLogger from '@/utils/b3Logger'
import {
addQuoteDraftProduce,
addQuoteDraftProducts,
calculateProductsPrice,
getCalculatedProductPrice,
LineItems,
validProductQty,
} from '@/utils/b3Product/b3Product'

import { conversionProductsList } from '../../utils/b3Product/shared/config'

Expand Down
3 changes: 2 additions & 1 deletion apps/storefront/src/pages/accountSetting/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { store } from '@/store/reducer'
import { Fields, ParamProps } from '@/types/accountSetting'
import { b2bLogger, validatorRules } from '@/utils'
import { validatorRules } from '@/utils'
import b2bLogger from '@/utils/b3Logger'

import { deCodeField } from '../registered/config'

Expand Down
3 changes: 2 additions & 1 deletion apps/storefront/src/pages/address/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
} from '@/shared/service/b2b'
import { isB2BUserSelector, useAppSelector } from '@/store'
import { CustomerRole } from '@/types'
import { b2bLogger, snackbar } from '@/utils'
import { snackbar } from '@/utils'
import b2bLogger from '@/utils/b3Logger'

import B3Filter from '../../components/filter/B3Filter'
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
getB2BAccountFormFields,
getB2BAddressExtraFields,
} from '@/shared/service/b2b'
import { b2bLogger } from '@/utils'
import b2bLogger from '@/utils/b3Logger'

import {
AccountFormFieldsItems,
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/pages/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { GlobaledContext } from '@/shared/global'
import { superAdminCompanies } from '@/shared/service/b2b'
import { useAppSelector } from '@/store'
import { OpenPageState } from '@/types/hooks'
import { endMasquerade, startMasquerade } from '@/utils'
import { endMasquerade, startMasquerade } from '@/utils/masquerade'

import B3FilterSearch from '../../components/filter/B3FilterSearch'

Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/pages/invoice/Invoice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import {
import { useAppSelector } from '@/store'
import { InvoiceList, InvoiceListNode } from '@/types/invoice'
import {
b2bLogger,
currencyFormat,
currencyFormatInfo,
displayFormat,
getUTCTimestamp,
handleGetCorrespondingCurrencyToken,
snackbar,
} from '@/utils'
import b2bLogger from '@/utils/b3Logger'

import B3Filter from '../../components/filter/B3Filter'

Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/pages/invoice/utils/payment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getInvoiceCheckoutUrl } from '@/shared/service/b2b'
import { BcCartData } from '@/types/invoice'
import { b2bLogger } from '@/utils'
import { attemptCheckoutLoginAndRedirect } from '@/utils/b3checkout'
import b2bLogger from '@/utils/b3Logger'

export const getCheckouUrlAndCart = async (params: BcCartData) => {
const {
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/pages/login/ForgotPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useMobile } from '@/hooks'
import { CustomStyleContext } from '@/shared/customStyleButtton'
import { GlobaledContext } from '@/shared/global'
import { OpenPageState } from '@/types/hooks'
import { b2bLogger } from '@/utils'
import b2bLogger from '@/utils/b3Logger'

import { getForgotPasswordFields, LoginConfig, sendEmail } from './config'
import { B3ResetPassWordButton, LoginImage } from './styled'
Expand Down
13 changes: 4 additions & 9 deletions apps/storefront/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,10 @@ import { isLoggedInSelector, useAppDispatch, useAppSelector } from '@/store'
import { setB2BToken } from '@/store/slices/company'
import { CustomerRole, UserTypes } from '@/types'
import { OpenPageState } from '@/types/hooks'
import {
b2bLogger,
B3SStorage,
getCurrentCustomerInfo,
loginjump,
logoutSession,
snackbar,
storeHash,
} from '@/utils'
import { B3SStorage, loginjump, snackbar, storeHash } from '@/utils'
import b2bLogger from '@/utils/b3Logger'
import { logoutSession } from '@/utils/b3logout'
import { getCurrentCustomerInfo } from '@/utils/loginInfo'

import LoginWidget from './component/LoginWidget'
import { loginCheckout, LoginConfig, LoginInfoInit } from './config'
Expand Down
3 changes: 2 additions & 1 deletion apps/storefront/src/pages/login/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { LangFormatFunction } from '@b3/lang'

import { store } from '@/store/reducer'
import { b2bLogger, storeHash, validatorRules } from '@/utils'
import { storeHash, validatorRules } from '@/utils'
import b2bLogger from '@/utils/b3Logger'

export interface QuoteConfig {
[key: string]: string
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/pages/orderDetail/OrderDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
getOrderStatusType,
} from '@/shared/service/b2b'
import { isB2BUserSelector, useAppSelector } from '@/store'
import { b2bLogger } from '@/utils'
import b2bLogger from '@/utils/b3Logger'

import {
AddressConfigItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
getBcVariantInfoBySkus,
} from '@/shared/service/b2b'
import { isB2BUserSelector, store, useAppSelector } from '@/store'
import { b2bLogger, b3TriggerCartNumber, snackbar } from '@/utils'
import { snackbar } from '@/utils'
import b2bLogger from '@/utils/b3Logger'
import b3TriggerCartNumber from '@/utils/b3TriggerCartNumber'
import { callCart } from '@/utils/cartUtils'

import { EditableProductItem, OrderProductItem } from '../../../types'
Expand Down
11 changes: 3 additions & 8 deletions apps/storefront/src/pages/pdp/PDP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@ import {
} from '@/shared/service/b2b'
import { isB2BUserSelector, store, useAppSelector } from '@/store'
import { OpenPageState } from '@/types/hooks'
import {
getDefaultCurrencyInfo,
getProductOptionList,
getValidOptionsList,
globalSnackbar,
isAllRequiredOptionFilled,
serialize,
} from '@/utils'
import { getDefaultCurrencyInfo, globalSnackbar, serialize } from '@/utils'
import { getProductOptionList, isAllRequiredOptionFilled } from '@/utils/b3AddToShoppingList'
import { getValidOptionsList } from '@/utils/b3Product/b3Product'

import { conversionProductsList } from '../../utils/b3Product/shared/config'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,16 @@ import {
searchBcProducts,
} from '@/shared/service/b2b'
import { useAppSelector } from '@/store'
import { currencyFormat, getProductPriceIncTax, snackbar } from '@/utils'
import b2bLogger from '@/utils/b3Logger'
import {
addQuoteDraftProducts,
b2bLogger,
b3TriggerCartNumber,
calculateProductListPrice,
currencyFormat,
getProductPriceIncTax,
getValidOptionsList,
snackbar,
validProductQty,
} from '@/utils'
} from '@/utils/b3Product/b3Product'
import { conversionProductsList } from '@/utils/b3Product/shared/config'
import b3TriggerCartNumber from '@/utils/b3TriggerCartNumber'
import { callCart } from '@/utils/cartUtils'

import CreateShoppingList from '../../orderDetail/components/CreateShoppingList'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
import { B3Upload, CustomButton, successTip } from '@/components'
import { useBlockPendingAccountViewPrice, useMobile } from '@/hooks'
import { useAppSelector } from '@/store'
import { b2bLogger, b3TriggerCartNumber, snackbar } from '@/utils'
import { snackbar } from '@/utils'
import b2bLogger from '@/utils/b3Logger'
import b3TriggerCartNumber from '@/utils/b3TriggerCartNumber'
import { callCart } from '@/utils/cartUtils'

import SearchProduct from '../../shoppingListDetails/components/SearchProduct'
Expand Down
4 changes: 3 additions & 1 deletion apps/storefront/src/pages/quote/QuoteDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import {
useAppSelector,
} from '@/store'
import { Currency } from '@/types'
import { getSearchVal, getVariantInfoOOSAndPurchase, snackbar } from '@/utils'
import { snackbar } from '@/utils'
import { getVariantInfoOOSAndPurchase } from '@/utils/b3Product/b3Product'
import { conversionProductsList } from '@/utils/b3Product/shared/config'
import { getSearchVal } from '@/utils/loginInfo'

import Message from './components/Message'
import QuoteAttachment from './components/QuoteAttachment'
Expand Down
8 changes: 2 additions & 6 deletions apps/storefront/src/pages/quote/QuoteDraft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ import {
ShippingAddress,
} from '@/types/quotes'
import {
addQuoteDraftProducts,
B3LStorage,
getActiveCurrencyInfo,
getDefaultCurrencyInfo,
snackbar,
storeHash,
} from '@/utils'
import { addQuoteDraftProducts } from '@/utils/b3Product/b3Product'
import { deleteCartData } from '@/utils/cartUtils'
import validateObject from '@/utils/quoteUtils'

Expand Down Expand Up @@ -136,11 +136,7 @@ const billingAddress = {

function QuoteDraft({ setOpenPage }: QuoteDraftProps) {
const {
state: {
countriesList,
currentChannelId: channelId,
openAPPParams,
},
state: { countriesList, currentChannelId: channelId, openAPPParams },
} = useContext(GlobaledContext)
const isB2BUser = useAppSelector(isB2BUserSelector)
const companyB2BId = useAppSelector(({ company }) => company.companyInfo.id)
Expand Down
6 changes: 3 additions & 3 deletions apps/storefront/src/pages/quote/components/AddToQuote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { PRODUCT_DEFAULT_IMAGE } from '@/constants'
import { useBlockPendingAccountViewPrice } from '@/hooks'
import { searchB2BProducts, searchBcProducts } from '@/shared/service/b2b'
import { useAppSelector } from '@/store'
import { snackbar } from '@/utils'
import b2bLogger from '@/utils/b3Logger'
import {
addQuoteDraftProducts,
b2bLogger,
calculateProductListPrice,
snackbar,
validProductQty,
} from '@/utils'
} from '@/utils/b3Product/b3Product'
import { conversionProductsList } from '@/utils/b3Product/shared/config'

import QuickAdd from '../../shoppingListDetails/components/QuickAdd'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { CustomButton } from '@/components'
import { useMobile } from '@/hooks'
import { b2bQuoteCheckout, bcQuoteCheckout } from '@/shared/service/b2b'
import { useAppSelector } from '@/store'
import { b2bLogger, getSearchVal } from '@/utils'
import {
attemptCheckoutLoginAndRedirect,
setQuoteToStorage,
} from '@/utils/b3checkout'
import b2bLogger from '@/utils/b3Logger'
import { getSearchVal } from '@/utils/loginInfo'

interface QuoteDetailFooterProps {
quoteId: string
Expand Down
Loading

0 comments on commit 905d8e2

Please sign in to comment.