diff --git a/apps/storefront/src/hooks/dom/utils.ts b/apps/storefront/src/hooks/dom/utils.ts index 1af733a7..5fdcf382 100644 --- a/apps/storefront/src/hooks/dom/utils.ts +++ b/apps/storefront/src/hooks/dom/utils.ts @@ -10,6 +10,7 @@ import { getCartInfoWithOptions } from '@/shared/service/bc' import { addQuoteDraftProduce, addQuoteDraftProducts, + B3SStorage, calculateProductListPrice, getCalculatedProductPrice, globalSnackbar, @@ -190,11 +191,17 @@ const addProductsToDraftQuote = async (products: CustomFieldItems[]) => { // filter products with SKU const productsWithSKU = products.filter(({ sku }) => !!sku) + const companyId = + B3SStorage.get('B3CompanyInfo')?.id || B3SStorage.get('salesRepCompanyId') + const customerGroupId = B3SStorage.get('B3CustomerInfo')?.customerGroupId + // fetch data with products IDs const { productsSearch } = await searchB2BProducts({ productIds: Array.from( new Set(products.map(({ productId }) => +productId)) ), + companyId, + customerGroupId, }) // convert to product search response format @@ -325,11 +332,17 @@ const addProductFromProductPageToQuote = (setOpenPage: DispatchProps) => { ).trim() const form = productView.querySelector('form[data-cart-item-add]') + const companyId = + B3SStorage.get('B3CompanyInfo')?.id || + B3SStorage.get('salesRepCompanyId') + const customerGroupId = B3SStorage.get('B3CustomerInfo')?.customerGroupId const fn = +role === 99 || +role === 100 ? searchBcProducts : searchB2BProducts const { productsSearch } = await fn({ productIds: [+productId], + companyId, + customerGroupId, }) const newProductInfo: CustomFieldItems = diff --git a/apps/storefront/src/pages/pdp/PDP.tsx b/apps/storefront/src/pages/pdp/PDP.tsx index 4c6f0d56..0f0c15b0 100644 --- a/apps/storefront/src/pages/pdp/PDP.tsx +++ b/apps/storefront/src/pages/pdp/PDP.tsx @@ -90,7 +90,11 @@ export const getProductOptionList = (optionMap: CustomFieldItems) => { function PDP({ setOpenPage }: PDPProps) { const isPromission = true const { - state: { isB2BUser, shoppingListClickNode }, + state: { + isB2BUser, + shoppingListClickNode, + customer: { customerGroupId }, + }, } = useContext(GlobaledContext) const [openShoppingList, setOpenShoppingList] = useState(false) @@ -182,6 +186,7 @@ function PDP({ setOpenPage }: PDPProps) { productIds: [+productId], currencyCode, companyId, + customerGroupId, }) const newProductInfo: any = conversionProductsList(productsSearch) diff --git a/apps/storefront/src/pages/quickorder/components/QuickOrderFooter.tsx b/apps/storefront/src/pages/quickorder/components/QuickOrderFooter.tsx index 194cb51d..04830a62 100644 --- a/apps/storefront/src/pages/quickorder/components/QuickOrderFooter.tsx +++ b/apps/storefront/src/pages/quickorder/components/QuickOrderFooter.tsx @@ -2,6 +2,7 @@ import { Dispatch, MouseEvent, SetStateAction, + useContext, useEffect, useState, } from 'react' @@ -13,6 +14,7 @@ import { v1 as uuid } from 'uuid' import { CustomButton, successTip } from '@/components' import { PRODUCT_DEFAULT_IMAGE } from '@/constants' import { useMobile } from '@/hooks' +import { GlobaledContext } from '@/shared/global' import { addProductToBcShoppingList, addProductToShoppingList, @@ -102,6 +104,13 @@ interface QuickOrderFooterProps { } function QuickOrderFooter(props: QuickOrderFooterProps) { + const { + state: { + companyInfo: { id: companyId }, + customer: { customerGroupId }, + }, + } = useContext(GlobaledContext) + const { role, checkedArr, isAgenting, setIsRequestLoading, isB2BUser } = props const [isMobile] = useMobile() @@ -278,6 +287,8 @@ function QuickOrderFooter(props: QuickOrderFooterProps) { const { productsSearch } = await getProducts({ productIds, + companyId, + customerGroupId, }) const newProductInfo: CustomFieldItems = diff --git a/apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx b/apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx index 6875c048..a3d3c933 100644 --- a/apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx +++ b/apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx @@ -126,6 +126,7 @@ function QuickorderTable({ state: { isB2BUser, companyInfo: { id: companyInfoId }, + customer: { customerGroupId }, }, } = useContext(GlobaledContext) @@ -159,6 +160,7 @@ function QuickorderTable({ productIds, currencyCode, companyId: companyInfoId, + customerGroupId, }) const newProductsSearch = conversionProductsList(productsSearch) diff --git a/apps/storefront/src/pages/quote/QuoteDetail.tsx b/apps/storefront/src/pages/quote/QuoteDetail.tsx index fe15643b..dd5df3ae 100644 --- a/apps/storefront/src/pages/quote/QuoteDetail.tsx +++ b/apps/storefront/src/pages/quote/QuoteDetail.tsx @@ -36,7 +36,7 @@ function QuoteDetail() { state: { companyInfo: { id: companyInfoId }, role, - customer, + customer: { emailAddress, customerGroupId }, isB2BUser, isAgenting, }, @@ -76,6 +76,7 @@ function QuoteDetail() { productIds, currencyCode, companyId: companyInfoId, + customerGroupId, }) const newProductsSearch = conversionProductsList(productsSearch) @@ -436,7 +437,7 @@ function QuoteDetail() { id={id} status={quoteDetail.status} isB2BUser={isB2BUser} - email={customer?.emailAddress || ''} + email={emailAddress || ''} msgs={quoteDetail?.trackingHistory || []} /> diff --git a/apps/storefront/src/pages/quote/components/AddToQuote.tsx b/apps/storefront/src/pages/quote/components/AddToQuote.tsx index f4e4556d..841e57b9 100644 --- a/apps/storefront/src/pages/quote/components/AddToQuote.tsx +++ b/apps/storefront/src/pages/quote/components/AddToQuote.tsx @@ -1,10 +1,11 @@ -import { useState } from 'react' +import { useContext, useState } from 'react' import UploadFileIcon from '@mui/icons-material/UploadFile' import { Box, Card, CardContent, Divider } from '@mui/material' import { v1 as uuid } from 'uuid' import { B3CollapseContainer, B3Upload, CustomButton } from '@/components' import { PRODUCT_DEFAULT_IMAGE } from '@/constants' +import { GlobaledContext } from '@/shared/global' import { searchB2BProducts, searchBcProducts } from '@/shared/service/b2b' import { addQuoteDraftProducts, @@ -26,6 +27,13 @@ interface AddToListProps { export default function AddToQuote(props: AddToListProps) { const { updateList, addToQuote, isB2BUser } = props + const { + state: { + companyInfo: { id: companyId }, + customer: { customerGroupId }, + }, + } = useContext(GlobaledContext) + const [isOpenBulkLoadCSV, setIsOpenBulkLoadCSV] = useState(false) const [isLoading, setIsLoading] = useState(false) @@ -103,6 +111,8 @@ export default function AddToQuote(props: AddToListProps) { const { productsSearch }: CustomFieldItems = await searchB2BProducts({ productIds, + companyId, + customerGroupId, }) const productList = productsSearch.map((product: CustomFieldItems) => { @@ -172,6 +182,8 @@ export default function AddToQuote(props: AddToListProps) { const { productsSearch } = await getProducts({ productIds, + companyId, + customerGroupId, }) const newProductInfo: CustomFieldItems = diff --git a/apps/storefront/src/pages/shoppingListDetails/ShoppingListDetails.tsx b/apps/storefront/src/pages/shoppingListDetails/ShoppingListDetails.tsx index 01cdf5e5..9d5f9cf9 100644 --- a/apps/storefront/src/pages/shoppingListDetails/ShoppingListDetails.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/ShoppingListDetails.tsx @@ -86,6 +86,7 @@ function ShoppingListDetails({ setOpenPage }: ShoppingListDetailsProps) { currentChannelId, isAgenting, openAPPParams, + customer: { customerGroupId }, }, } = useContext(GlobaledContext) const navigate = useNavigate() @@ -162,6 +163,7 @@ function ShoppingListDetails({ setOpenPage }: ShoppingListDetailsProps) { productIds, currencyCode, companyId: companyInfoId, + customerGroupId, }) const newProductsSearch = conversionProductsList(productsSearch) diff --git a/apps/storefront/src/pages/shoppingListDetails/components/ChooseOptionsDialog.tsx b/apps/storefront/src/pages/shoppingListDetails/components/ChooseOptionsDialog.tsx index 8b8409b2..9e3a1447 100644 --- a/apps/storefront/src/pages/shoppingListDetails/components/ChooseOptionsDialog.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/components/ChooseOptionsDialog.tsx @@ -13,7 +13,7 @@ import { Box, Divider, TextField, Typography } from '@mui/material' import { B3CustomForm, B3Dialog, B3Sping } from '@/components' import { PRODUCT_DEFAULT_IMAGE } from '@/constants' import { searchB2BProducts, searchBcProducts } from '@/shared/service/b2b' -import { currencyFormat, snackbar } from '@/utils' +import { B3SStorage, currencyFormat, snackbar } from '@/utils' import { ShoppingListProductItem, SimpleObject, Variant } from '../../../types' import { @@ -123,8 +123,15 @@ export default function ChooseOptionsDialog(props: ChooseOptionsDialogProps) { if (productIds.length > 0) { const getProducts = isB2BUser ? searchB2BProducts : searchBcProducts + const companyId = + B3SStorage.get('B3CompanyInfo')?.id || + B3SStorage.get('salesRepCompanyId') + const customerGroupId = + B3SStorage.get('B3CustomerInfo')?.customerGroupId const { productsSearch }: CustomFieldItems = await getProducts({ productIds, + companyId, + customerGroupId, }) productsSearch.forEach((product: CustomFieldItems) => { diff --git a/apps/storefront/src/pages/shoppingListDetails/components/SearchProduct.tsx b/apps/storefront/src/pages/shoppingListDetails/components/SearchProduct.tsx index 69c4e3b2..f0a9866d 100644 --- a/apps/storefront/src/pages/shoppingListDetails/components/SearchProduct.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/components/SearchProduct.tsx @@ -4,7 +4,7 @@ import { Box, InputAdornment, TextField, Typography } from '@mui/material' import { B3Sping, CustomButton } from '@/components' import { searchB2BProducts, searchBcProducts } from '@/shared/service/b2b' -import { calculateProductListPrice } from '@/utils' +import { B3SStorage, calculateProductListPrice } from '@/utils' import { conversionProductsList } from '@/utils/b3Product/shared/config' import { ShoppingListProductItem } from '../../../types' @@ -45,12 +45,17 @@ export default function SearchProduct({ if (!searchText || isLoading) { return } + const companyId = + B3SStorage.get('B3CompanyInfo')?.id || B3SStorage.get('salesRepCompanyId') + const customerGroupId = B3SStorage.get('B3CustomerInfo')?.customerGroupId const getProducts = isB2BUser ? searchB2BProducts : searchBcProducts setIsLoading(true) try { const { productsSearch }: CustomFieldItems = await getProducts({ search: searchText, + companyId, + customerGroupId, }) const product = conversionProductsList(productsSearch) diff --git a/apps/storefront/src/shared/global/context/config.ts b/apps/storefront/src/shared/global/context/config.ts index 4329b090..8b4305c2 100644 --- a/apps/storefront/src/shared/global/context/config.ts +++ b/apps/storefront/src/shared/global/context/config.ts @@ -7,6 +7,7 @@ export interface CustomerInfo { firstName: string lastName: string emailAddress: string + customerGroupId?: number } export type AlertTip = 'error' | 'info' | 'success' | 'warning' diff --git a/apps/storefront/src/shared/service/b2b/graphql/product.ts b/apps/storefront/src/shared/service/b2b/graphql/product.ts index 414c1329..f24d6afb 100644 --- a/apps/storefront/src/shared/service/b2b/graphql/product.ts +++ b/apps/storefront/src/shared/service/b2b/graphql/product.ts @@ -42,6 +42,7 @@ const searchProducts = (data: CustomFieldItems) => `{ companyId: "${data.companyId || ''}" storeHash: "${storeHash}" channelId: ${B3SStorage.get('B3channelId') || 1} + customerGroupId: ${data.customerGroupId || 0} ){ id, name, diff --git a/apps/storefront/src/utils/b3AddToShoppingList.ts b/apps/storefront/src/utils/b3AddToShoppingList.ts index 033e4388..b03261a2 100644 --- a/apps/storefront/src/utils/b3AddToShoppingList.ts +++ b/apps/storefront/src/utils/b3AddToShoppingList.ts @@ -9,6 +9,7 @@ export const handleGetCurrentProductInfo = async ( const currencies = B3SStorage.get('currencies') const companyId = B3SStorage.get('B3CompanyInfo')?.id || B3SStorage.get('salesRepCompanyId') + const customerGroupId = B3SStorage.get('B3CustomerInfo')?.customerGroupId let currencyCode = '$' if (currencies) { @@ -27,6 +28,7 @@ export const handleGetCurrentProductInfo = async ( productIds: [+productId], currencyCode, companyId, + customerGroupId, }) const currentProductInfo = conversionProductsList(productsSearch) diff --git a/apps/storefront/src/utils/b3Product.ts b/apps/storefront/src/utils/b3Product.ts index 7b2be50e..01153e64 100644 --- a/apps/storefront/src/utils/b3Product.ts +++ b/apps/storefront/src/utils/b3Product.ts @@ -1,5 +1,5 @@ import { searchB2BProducts, searchBcProducts } from '@/shared/service/b2b' -import { B3LStorage } from '@/utils' +import { B3LStorage, B3SStorage } from '@/utils' interface QuoteListitemProps { node: { @@ -135,8 +135,14 @@ const getProductExtraPrice = async ( const fn = +role === 99 || +role === 100 ? searchBcProducts : searchB2BProducts + const companyId = + B3SStorage.get('B3CompanyInfo')?.id || B3SStorage.get('salesRepCompanyId') + const customerGroupId = B3SStorage.get('B3CustomerInfo')?.customerGroupId + const { productsSearch: additionalProductsSearch } = await fn({ productIds, + companyId, + customerGroupId, }) additionalProductsSearch.forEach((item: CustomFieldItems) => { diff --git a/apps/storefront/src/utils/b3Product/b3Product.ts b/apps/storefront/src/utils/b3Product/b3Product.ts index d872248d..b817a0cd 100644 --- a/apps/storefront/src/utils/b3Product/b3Product.ts +++ b/apps/storefront/src/utils/b3Product/b3Product.ts @@ -120,8 +120,13 @@ const getProductExtraPrice = async ( const fn = +role === 99 || +role === 100 ? searchBcProducts : searchB2BProducts + const companyId = + B3SStorage.get('B3CompanyInfo')?.id || B3SStorage.get('salesRepCompanyId') + const customerGroupId = B3SStorage.get('B3CustomerInfo')?.customerGroupId const { productsSearch: additionalProductsSearch } = await fn({ productIds, + companyId, + customerGroupId, }) additionalProductsSearch.forEach((item: CustomFieldItems) => { @@ -390,11 +395,18 @@ const getNewProductsList = async ( productIds.push(node.productId) } }) + const companyId = + B3SStorage.get('B3CompanyInfo')?.id || + B3SStorage.get('salesRepCompanyId') + const customerGroupId = B3SStorage.get('B3CustomerInfo')?.customerGroupId + const getProducts = isB2BUser ? searchB2BProducts : searchBcProducts const { productsSearch } = await getProducts({ productIds, currencyCode, + companyId, + customerGroupId, }) const newProductsSearch: Partial[] =