Skip to content

Commit

Permalink
feat: quote & shopping list show price list prices
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlLiu2023 authored and kris-liu-smile committed Jun 27, 2023
1 parent 0c4ca43 commit b9cd016
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 7 deletions.
13 changes: 13 additions & 0 deletions apps/storefront/src/hooks/dom/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getCartInfoWithOptions } from '@/shared/service/bc'
import {
addQuoteDraftProduce,
addQuoteDraftProducts,
B3SStorage,
calculateProductListPrice,
getCalculatedProductPrice,
globalSnackbar,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
7 changes: 6 additions & 1 deletion apps/storefront/src/pages/pdp/PDP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(false)
Expand Down Expand Up @@ -182,6 +186,7 @@ function PDP({ setOpenPage }: PDPProps) {
productIds: [+productId],
currencyCode,
companyId,
customerGroupId,
})

const newProductInfo: any = conversionProductsList(productsSearch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Dispatch,
MouseEvent,
SetStateAction,
useContext,
useEffect,
useState,
} from 'react'
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -278,6 +287,8 @@ function QuickOrderFooter(props: QuickOrderFooterProps) {

const { productsSearch } = await getProducts({
productIds,
companyId,
customerGroupId,
})

const newProductInfo: CustomFieldItems =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function QuickorderTable({
state: {
isB2BUser,
companyInfo: { id: companyInfoId },
customer: { customerGroupId },
},
} = useContext(GlobaledContext)

Expand Down Expand Up @@ -159,6 +160,7 @@ function QuickorderTable({
productIds,
currencyCode,
companyId: companyInfoId,
customerGroupId,
})

const newProductsSearch = conversionProductsList(productsSearch)
Expand Down
5 changes: 3 additions & 2 deletions apps/storefront/src/pages/quote/QuoteDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function QuoteDetail() {
state: {
companyInfo: { id: companyInfoId },
role,
customer,
customer: { emailAddress, customerGroupId },
isB2BUser,
isAgenting,
},
Expand Down Expand Up @@ -76,6 +76,7 @@ function QuoteDetail() {
productIds,
currencyCode,
companyId: companyInfoId,
customerGroupId,
})

const newProductsSearch = conversionProductsList(productsSearch)
Expand Down Expand Up @@ -436,7 +437,7 @@ function QuoteDetail() {
id={id}
status={quoteDetail.status}
isB2BUser={isB2BUser}
email={customer?.emailAddress || ''}
email={emailAddress || ''}
msgs={quoteDetail?.trackingHistory || []}
/>
</Box>
Expand Down
14 changes: 13 additions & 1 deletion apps/storefront/src/pages/quote/components/AddToQuote.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -103,6 +111,8 @@ export default function AddToQuote(props: AddToListProps) {

const { productsSearch }: CustomFieldItems = await searchB2BProducts({
productIds,
companyId,
customerGroupId,
})

const productList = productsSearch.map((product: CustomFieldItems) => {
Expand Down Expand Up @@ -172,6 +182,8 @@ export default function AddToQuote(props: AddToListProps) {

const { productsSearch } = await getProducts({
productIds,
companyId,
customerGroupId,
})

const newProductInfo: CustomFieldItems =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function ShoppingListDetails({ setOpenPage }: ShoppingListDetailsProps) {
currentChannelId,
isAgenting,
openAPPParams,
customer: { customerGroupId },
},
} = useContext(GlobaledContext)
const navigate = useNavigate()
Expand Down Expand Up @@ -162,6 +163,7 @@ function ShoppingListDetails({ setOpenPage }: ShoppingListDetailsProps) {
productIds,
currencyCode,
companyId: companyInfoId,
customerGroupId,
})

const newProductsSearch = conversionProductsList(productsSearch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions apps/storefront/src/shared/global/context/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface CustomerInfo {
firstName: string
lastName: string
emailAddress: string
customerGroupId?: number
}

export type AlertTip = 'error' | 'info' | 'success' | 'warning'
Expand Down
1 change: 1 addition & 0 deletions apps/storefront/src/shared/service/b2b/graphql/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const searchProducts = (data: CustomFieldItems) => `{
companyId: "${data.companyId || ''}"
storeHash: "${storeHash}"
channelId: ${B3SStorage.get('B3channelId') || 1}
customerGroupId: ${data.customerGroupId || 0}
){
id,
name,
Expand Down
2 changes: 2 additions & 0 deletions apps/storefront/src/utils/b3AddToShoppingList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -27,6 +28,7 @@ export const handleGetCurrentProductInfo = async (
productIds: [+productId],
currencyCode,
companyId,
customerGroupId,
})

const currentProductInfo = conversionProductsList(productsSearch)
Expand Down
8 changes: 7 additions & 1 deletion apps/storefront/src/utils/b3Product.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { searchB2BProducts, searchBcProducts } from '@/shared/service/b2b'
import { B3LStorage } from '@/utils'
import { B3LStorage, B3SStorage } from '@/utils'

interface QuoteListitemProps {
node: {
Expand Down Expand Up @@ -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) => {
Expand Down
12 changes: 12 additions & 0 deletions apps/storefront/src/utils/b3Product/b3Product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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<Product>[] =
Expand Down

0 comments on commit b9cd016

Please sign in to comment.