Skip to content

Commit

Permalink
feat: brian/feat/sprint52 (#1029)
Browse files Browse the repository at this point in the history
* feat(bun-2345): add products to quote without parent sku
https://bigc-b2b.atlassian.net/browse/BUN-2345

* feat(bun-2366): quote get active currency
https://bigc-b2b.atlassian.net/browse/BUN-2366

* feat(2382): get default state by counrty defaultValue
https://bigc-b2b.atlassian.net/browse/BUN-2382

* feat(bun-2389): fix the error message to remove flag
https://bigc-b2b.atlassian.net/browse/BUN-2389

* fix(bun-2366): quote submit value convert

* feat(bun-2371): the Invoice# presentation of the Buyer Portal and B2B app is inconsistent

* fix(bun-2366): global currency conversion

* feat(bun-2251): custom order status label
https://bigc-b2b.atlassian.net/browse/BUN-2251

* fix: invoice support checkout receiptId

* fix: clear redundant code

* fix(bun-2422): add address
https://bigc-b2b.atlassian.net/browse/BUN-2422

* fix: quit login clear cart

* feat(bun-2163): company user extra fields (#1035)

* feat: add user extraFileds

* feat(bun-2163): add user extraFileds
https://bigc-b2b.atlassian.net/browse/BUN-2163

* feat(2163): company user extraFields

* fix: user extra fields validate
  • Loading branch information
BrianJiang2021 authored and libruce committed Apr 29, 2024
1 parent a90d717 commit 7f970d4
Show file tree
Hide file tree
Showing 32 changed files with 612 additions and 107 deletions.
7 changes: 7 additions & 0 deletions apps/storefront/src/hooks/dom/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
B3LStorage,
B3SStorage,
calculateProductsPrice,
getActiveCurrencyInfo,
getCalculatedProductPrice,
getCookie,
getProductOptionList,
Expand Down Expand Up @@ -184,6 +185,8 @@ const addProductsToDraftQuote = async (
B3SStorage.get('B3CompanyInfo')?.id || B3SStorage.get('salesRepCompanyId')
const customerGroupId = B3SStorage.get('B3CustomerInfo')?.customerGroupId

const { currency_code: currencyCode } = getActiveCurrencyInfo()

// fetch data with products IDs
const { productsSearch } = await searchB2BProducts({
productIds: Array.from(
Expand All @@ -193,6 +196,7 @@ const addProductsToDraftQuote = async (
)
)
),
currencyCode,
companyId,
customerGroupId,
})
Expand Down Expand Up @@ -318,10 +322,13 @@ const addProductFromProductPageToQuote = (setOpenPage: DispatchProps) => {
const fn =
+role === 99 || +role === 100 ? searchBcProducts : searchB2BProducts

const { currency_code: currencyCode } = getActiveCurrencyInfo()

const { productsSearch } = await fn({
productIds: [+productId],
companyId,
customerGroupId,
currencyCode,
})

const newProductInfo: CustomFieldItems =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const getBcAddressFields = async () => {
const { accountFormFields } = await getB2BAccountFormFields(1)

const addressFields = accountFormFields.filter(
(field: AccountFormFieldsItems) => field.groupName === 'Address'
(field: AccountFormFieldsItems) => field.groupId === 4
)

const bcAddressFields = getAccountFormFields(addressFields).address
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 @@ -504,7 +504,7 @@ function Invoice() {
handleViewInvoice(item.id, item.status)
}}
>
{item?.id || '-'}
{item?.invoiceNumber ? item?.invoiceNumber : item?.id}
</Box>
),
width: '8%',
Expand Down
26 changes: 26 additions & 0 deletions apps/storefront/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ import {
superAdminEndMasquerade,
} from '@/shared/service/b2b'
import { b2bLogin, bcLogoutLogin, customerLoginAPI } from '@/shared/service/bc'
import { deleteCart, getCart } from '@/shared/service/bc/graphql/cart'
import { store } from '@/store'
import {
B3SStorage,
getCookie,
getCurrentCustomerInfo,
loginjump,
logoutSession,
snackbar,
storeHash,
} from '@/utils'
import { deleteCartData } from '@/utils/cartUtils'

import LoginWidget from './component/LoginWidget'
import {
Expand Down Expand Up @@ -148,6 +152,28 @@ export default function Login(props: RegisteredProps) {
snackbar.error(b3Lang('login.loginText.invoiceErrorTip'))
}
if (loginFlag === '3' && !isLogout) {
const cartEntityId: string = getCookie('cartId')

const {
global: {
storeInfo: { platform },
},
} = store.getState()

const cartInfo = cartEntityId
? await getCart(cartEntityId, platform)
: null

if (cartInfo) {
let newCartId = cartEntityId
if (cartInfo?.data && cartInfo?.data?.site) {
const { cart } = cartInfo.data.site
newCartId = cart?.entityId || cartEntityId
}
const deleteQuery = deleteCartData(newCartId)
await deleteCart(deleteQuery)
}

const { result } = (await bcLogoutLogin()).data.logout

if (result !== 'success') return
Expand Down
18 changes: 16 additions & 2 deletions apps/storefront/src/pages/order/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ function Order({ isCompanyOrder = false }: OrderProps) {
const optionLabel =
orderStatusTranslationVariables[option.systemLabel]
const elementOption = option
elementOption.customLabel = b3Lang(optionLabel)
elementOption.customLabel =
b3Lang(optionLabel) === elementOption.systemLabel
? elementOption.customLabel
: b3Lang(optionLabel)

return option
}
Expand Down Expand Up @@ -259,11 +262,22 @@ function Order({ isCompanyOrder = false }: OrderProps) {
}

const handleFirterChange = (value: SearchChangeProps) => {
let currentStatus = value?.orderStatus || ''
if (currentStatus) {
const originStatus = getOrderStatuses.find(
(status) =>
status.customLabel === currentStatus ||
status.systemLabel === currentStatus
)

currentStatus = originStatus?.systemLabel || currentStatus
}

const search: Partial<FilterSearchProps> = {
beginDateAt: value?.startValue || null,
endDateAt: value?.endValue || null,
createdBy: value?.PlacedBy || '',
statusCode: value?.orderStatus || '',
statusCode: currentStatus,
companyName: value?.company || '',
}
setFilterData({
Expand Down
19 changes: 16 additions & 3 deletions apps/storefront/src/pages/orderDetail/OrderDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
OrderStatusResponse,
} from '../../types'
import OrderStatus from '../order/components/OrderStatus'
import { orderStatusTranslationVariables } from '../order/shared/getOrderStatus'

import {
OrderDetailsContext,
Expand Down Expand Up @@ -193,9 +194,21 @@ function OrderDetail() {
getAddressLabelPermission()
}, [])

const getOrderStatusLabel = (status: string) =>
orderStatus.find((item: OrderStatusItem) => item.systemLabel === status)
?.customLabel || customStatus
const getOrderStatusLabel = (status: string) => {
const currentOrderStatus = orderStatus.find(
(item: OrderStatusItem) => item.systemLabel === status
)
let activeStatusLabel = currentOrderStatus?.customLabel || customStatus
if (currentOrderStatus) {
const optionLabel =
orderStatusTranslationVariables[currentOrderStatus.systemLabel]
activeStatusLabel =
optionLabel && b3Lang(optionLabel) !== currentOrderStatus.systemLabel
? b3Lang(optionLabel)
: activeStatusLabel
}
return activeStatusLabel
}

return (
<B3Sping isSpinning={isRequestLoading} background="rgba(255,255,255,0.2)">
Expand Down
24 changes: 20 additions & 4 deletions apps/storefront/src/pages/orderDetail/components/OrderHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { RootState } from '@/store'

import { OrderHistoryItem, OrderStatusItem } from '../../../types'
import OrderStatus from '../../order/components/OrderStatus'
import { orderStatusTranslationVariables } from '../../order/shared/getOrderStatus'
import { OrderDetailsContext } from '../context/OrderDetailsContext'

const HistoryListContainer = styled('div')(() => ({
Expand All @@ -30,7 +31,7 @@ const HistoryListContainer = styled('div')(() => ({
export default function OrderHistory() {
const b3Lang = useB3Lang()
const {
state: { history = [], orderStatus: orderStatusLabel = [] },
state: { history = [], orderStatus: orderStatusLabel = [], customStatus },
} = useContext(OrderDetailsContext)

const lang = useSelector(({ lang }: RootState) => lang)
Expand All @@ -41,10 +42,25 @@ export default function OrderHistory() {
locale: lang,
})

const getOrderStatusLabel = (status: string) =>
orderStatusLabel.find(
const getOrderStatusLabel = (status: string) => {
const currentOrderStatus = orderStatusLabel.find(
(item: OrderStatusItem) => item.systemLabel === status
)?.customLabel || status
)

let activeStatusLabel = currentOrderStatus?.customLabel || customStatus

if (currentOrderStatus) {
const optionLabel =
orderStatusTranslationVariables[currentOrderStatus.systemLabel]

activeStatusLabel =
optionLabel && b3Lang(optionLabel) !== currentOrderStatus.systemLabel
? b3Lang(optionLabel)
: activeStatusLabel
}

return activeStatusLabel
}

const columnItems: TableColumnItem<OrderHistoryItem>[] = [
{
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/pages/pdp/PDP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { globalStateSelector } from '@/store'
import {
B3SStorage,
getDefaultCurrencyInfo,
getActiveCurrencyInfo,
getProductOptionList,
getValidOptionsList,
globalSnackbar,
Expand Down Expand Up @@ -92,7 +92,7 @@ export const addProductsToShoppingList = async ({
gotoShoppingDetail,
b3Lang,
}: AddProductsToShoppingListParams) => {
const { currency_code: currencyCode } = getDefaultCurrencyInfo()
const { currency_code: currencyCode } = getActiveCurrencyInfo()
const companyId =
B3SStorage.get('B3CompanyInfo')?.id || B3SStorage.get('salesRepCompanyId')
const getProducts = isB2BUser ? searchB2BProducts : searchBcProducts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
b3TriggerCartNumber,
calculateProductListPrice,
currencyFormat,
getActiveCurrencyInfo,
getProductPriceIncTax,
getValidOptionsList,
snackbar,
Expand Down Expand Up @@ -340,10 +341,13 @@ function QuickOrderFooter(props: QuickOrderFooterProps) {

const getProducts = isB2BUser ? searchB2BProducts : searchBcProducts

const { currency_code: currencyCode } = getActiveCurrencyInfo()

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

const newProductInfo: CustomFieldItems =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
currencyFormat,
displayFormat,
distanceDay,
getDefaultCurrencyInfo,
getActiveCurrencyInfo,
getProductPriceIncTax,
snackbar,
} from '@/utils'
Expand Down Expand Up @@ -162,7 +162,7 @@ function QuickorderTable({

const b3Lang = useB3Lang()

const { currency_code: currencyCode } = getDefaultCurrencyInfo()
const { currency_code: currencyCode } = getActiveCurrencyInfo()

const handleGetProductsById = async (listProducts: ListItemProps[]) => {
if (listProducts.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/pages/quote/QuoteDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@/shared/service/b2b'
import { store, TaxZoneRates, TaxZoneRatesProps } from '@/store'
import {
getDefaultCurrencyInfo,
getActiveCurrencyInfo,
getSearchVal,
getVariantInfoOOSAndPurchase,
snackbar,
Expand Down Expand Up @@ -69,7 +69,7 @@ function QuoteDetail() {
})
const [isRequestLoading, setIsRequestLoading] = useState(false)
const [isShowFooter, setIsShowFooter] = useState(false)
const { currency_code: currencyCode } = getDefaultCurrencyInfo()
const { currency_code: currencyCode } = getActiveCurrencyInfo()

const [quoteDetailTax, setQuoteDetailTax] = useState(0)

Expand Down
5 changes: 1 addition & 4 deletions apps/storefront/src/pages/quote/QuoteDraft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
B3LStorage,
B3SStorage,
getActiveCurrencyInfo,
getDefaultCurrencyInfo,
snackbar,
storeHash,
} from '@/utils'
Expand Down Expand Up @@ -515,8 +514,6 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) {
(item: CustomFieldItems) => item.sku === node.variantSku
)

// const salePrice = getBCPrice(+(node?.basePrice || 0), +(node?.taxPrice || 0))

allPrice += +(node?.basePrice || 0) * +(node?.quantity || 0)

allTaxPrice += +(node?.taxPrice || 0) * +(node?.quantity || 0)
Expand All @@ -538,7 +535,7 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) {
}
)

const currency = getDefaultCurrencyInfo()
const currency = getActiveCurrencyInfo()

const fileList = getFileList(info.fileInfo || [])

Expand Down
12 changes: 10 additions & 2 deletions apps/storefront/src/pages/quote/components/AddToQuote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,16 @@ export default function AddToQuote(props: AddToListProps) {

const addToList = async (products: CustomFieldItems[]) => {
const newProducts = getNewQuoteProduct(products)
const noSkuProducts = products.filter(({ sku, variantId, variants }) => {
const currentProduct = variants.find(
(item: CustomFieldItems) =>
item.variant_id === variantId || item.variantId === variantId
)

const variantSku = currentProduct.sku

const noSkuProducts = products.filter(({ sku }) => !sku)
return !(sku || variantSku)
})
if (noSkuProducts.length > 0) {
snackbar.error(b3Lang('quoteDraft.notification.cantAddProductsNoSku'), {
isClose: true,
Expand Down Expand Up @@ -154,7 +162,7 @@ export default function AddToQuote(props: AddToListProps) {

addToQuote(newProducts)

snackbar.success(b3Lang('quoteDraft.notification.productPlural.'), {
snackbar.success(b3Lang('quoteDraft.notification.productPlural'), {
isClose: true,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const QuoteSummary = forwardRef((_, ref: Ref<unknown>) => {
const isHidePrice = getQuoteDraftShowPriceTBD(productList)

setHideQuoteDraftPrice(isHidePrice)

const newQuoteSummary = productList.reduce(
(summary: Summary, product: CustomFieldItems) => {
const { basePrice, taxPrice: productTax = 0, quantity } = product.node
Expand Down
20 changes: 19 additions & 1 deletion apps/storefront/src/pages/registered/RegisterComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default function RegisterComplete(props: RegisterCompleteProps) {
if (name === 'accepts_marketing_emails') {
bcFields.accepts_product_review_abandoned_cart_emails =
!!item?.default?.length
} else {
} else if (!item.custom) {
bcFields[name] = item?.default || ''
}
})
Expand Down Expand Up @@ -199,6 +199,24 @@ export default function RegisterComplete(props: RegisterCompleteProps) {
const b2bFields: CustomFieldItems = {}
b2bFields.customerId = customerId || ''
b2bFields.storeHash = storeHash

// company user extra field
const b2bContactInformationList = list || []
const companyUserExtraFieldsList = b2bContactInformationList.filter(
(item) => !!item.custom
)

if (companyUserExtraFieldsList.length) {
const companyUserExtraFields: Array<CustomFieldItems> = []
companyUserExtraFieldsList.forEach((item: CustomFieldItems) => {
const itemExtraField: CustomFieldItems = {}
itemExtraField.fieldName = deCodeField(item.name)
itemExtraField.fieldValue = item?.default || ''
companyUserExtraFields.push(itemExtraField)
})
b2bFields.userExtraFields = companyUserExtraFields
}

const companyInfo = companyInformation.filter(
(list) => !list.custom && list.fieldType !== 'files'
)
Expand Down
Loading

0 comments on commit 7f970d4

Please sign in to comment.