Skip to content

Commit

Permalink
feat: block pending account view products & price
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlLiu2023 committed Jul 28, 2023
1 parent 37899d7 commit a15a14e
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 28 deletions.
26 changes: 21 additions & 5 deletions apps/storefront/src/components/layout/B3StatusNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export default function B3StatusNotification(props: B3StatusNotificationProps) {
const blockPendingAccountOrderCreation = B3SStorage.get(
'blockPendingAccountOrderCreation'
)
const blockPendingAccountViewPrice = B3SStorage.get(
'blockPendingAccountViewPrice'
)
const loginType = JSON.parse(sessionStorage.getItem('loginType') || 'false')

const [tip, setTip] = useState<string>('')
Expand All @@ -54,11 +57,24 @@ export default function B3StatusNotification(props: B3StatusNotificationProps) {
setIsShow(showTip)
if (showTip) {
if (+companyStatus === 0) {
setTip(
blockPendingAccountOrderCreation
? StatusNotifications.pendingOrderingBlocked
: StatusNotifications.pendingOrderingNotBlocked
)
if (blockPendingAccountOrderCreation && blockPendingAccountViewPrice) {
setTip(StatusNotifications.pendingOrderingAndViewPriceBlocked)
}

if (blockPendingAccountOrderCreation && !blockPendingAccountViewPrice) {
setTip(StatusNotifications.pendingOrderingBlocked)
}

if (!blockPendingAccountOrderCreation && blockPendingAccountViewPrice) {
setTip(StatusNotifications.pendingViewPriceBlocked)
}

if (
!blockPendingAccountOrderCreation &&
!blockPendingAccountViewPrice
) {
setTip(StatusNotifications.pendingOrderingNotBlocked)
}
setType('info')
setBcColor('#0288D1')
}
Expand Down
4 changes: 4 additions & 0 deletions apps/storefront/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export const StatusNotifications = {
'Your business account is pending approval. Ordering will be enabled after account approval.',
pendingOrderingNotBlocked:
'Your business account is pending approval. You will gain access to business account features after account approval.',
pendingViewPriceBlocked:
'Your business account is pending approval. You will gain access to business account features, products, and pricing after account approval.',
pendingOrderingAndViewPriceBlocked:
'Your business account is pending approval. Products, pricing, and ordering will be enabled after account approval',
approvedTip:
'Your business account has been approved. Check your email inbox, we sent you a letter with all details.',
rejectedTip:
Expand Down
12 changes: 11 additions & 1 deletion apps/storefront/src/pages/quickorder/components/QuickAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Box, Grid, Typography } from '@mui/material'

import { B3CustomForm, B3Sping, CustomButton } from '@/components'
import { GlobaledContext } from '@/shared/global'
import { snackbar } from '@/utils'
import { B3SStorage, snackbar } from '@/utils'
import { getQuickAddRowFields } from '@/utils/b3Product/shared/config'

import {
Expand Down Expand Up @@ -288,6 +288,16 @@ export default function QuickAdd(props: AddToListContentProps) {
}

const handleAddToList = () => {
const blockPendingAccountViewPrice = B3SStorage.get(
'blockPendingAccountViewPrice'
)
if (blockPendingAccountViewPrice) {
snackbar.info(
'Your business account is pending approval. This feature is currently disabled.'
)
return
}

handleSubmit(async (value) => {
try {
setIsLoading(true)
Expand Down
22 changes: 15 additions & 7 deletions apps/storefront/src/pages/quickorder/components/QuickOrderPad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { B3Upload, CustomButton, successTip } from '@/components'
import { useMobile } from '@/hooks'
import { addProductToCart, createCart, getCartInfo } from '@/shared/service/bc'
import { snackbar } from '@/utils'
import { B3SStorage, snackbar } from '@/utils'

import SearchProduct from '../../shoppingListDetails/components/SearchProduct'

Expand Down Expand Up @@ -401,6 +401,19 @@ export default function QuickOrderPad(props: QuickOrderPadProps) {
return productData
}

const handleOpenUploadDiag = () => {
const blockPendingAccountViewPrice = B3SStorage.get(
'blockPendingAccountViewPrice'
)
if (blockPendingAccountViewPrice) {
snackbar.info(
'Your business account is pending approval. This feature is currently disabled.'
)
} else {
setIsOpenBulkLoadCSV(true)
}
}

useEffect(() => {
if (productData?.length > 0) {
setAddBtnText(`Add ${productData.length} products to cart`)
Expand Down Expand Up @@ -445,12 +458,7 @@ export default function QuickOrderPad(props: QuickOrderPadProps) {
margin: '20px 0 0',
}}
>
<CustomButton
variant="text"
onClick={() => {
setIsOpenBulkLoadCSV(true)
}}
>
<CustomButton variant="text" onClick={() => handleOpenUploadDiag()}>
<UploadFileIcon
sx={{
marginRight: '8px',
Expand Down
21 changes: 15 additions & 6 deletions apps/storefront/src/pages/quote/components/AddToQuote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { GlobaledContext } from '@/shared/global'
import { searchB2BProducts, searchBcProducts } from '@/shared/service/b2b'
import {
addQuoteDraftProducts,
B3SStorage,
calculateProductListPrice,
snackbar,
validProductQty,
Expand Down Expand Up @@ -259,6 +260,19 @@ export default function AddToQuote(props: AddToListProps) {
}
}

const handleOpenUploadDiag = () => {
const blockPendingAccountViewPrice = B3SStorage.get(
'blockPendingAccountViewPrice'
)
if (blockPendingAccountViewPrice) {
snackbar.info(
'Your business account is pending approval. This feature is currently disabled.'
)
} else {
setIsOpenBulkLoadCSV(true)
}
}

return (
<Card>
<CardContent>
Expand Down Expand Up @@ -287,12 +301,7 @@ export default function AddToQuote(props: AddToListProps) {
margin: '20px 0 0',
}}
>
<CustomButton
variant="text"
onClick={() => {
setIsOpenBulkLoadCSV(true)
}}
>
<CustomButton variant="text" onClick={() => handleOpenUploadDiag()}>
<UploadFileIcon
sx={{
marginRight: '8px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
addProductToBcShoppingList,
addProductToShoppingList,
} from '@/shared/service/b2b'
import { snackbar } from '@/utils'
import { B3SStorage, snackbar } from '@/utils'

import { getAllModifierDefaultValue } from '../../../utils/b3Product/shared/config'
import { ShoppingListDetailsContext } from '../context/ShoppingListDetailsContext'
Expand Down Expand Up @@ -179,6 +179,19 @@ export default function AddToShoppingList(props: AddToListProps) {
}
}

const handleOpenUploadDiag = () => {
const blockPendingAccountViewPrice = B3SStorage.get(
'blockPendingAccountViewPrice'
)
if (blockPendingAccountViewPrice) {
snackbar.info(
'Your business account is pending approval. This feature is currently disabled.'
)
} else {
setIsOpenBulkLoadCSV(true)
}
}

return (
<Card
sx={{
Expand All @@ -205,12 +218,7 @@ export default function AddToShoppingList(props: AddToListProps) {
margin: '20px 0 0',
}}
>
<CustomButton
variant="text"
onClick={() => {
setIsOpenBulkLoadCSV(true)
}}
>
<CustomButton variant="text" onClick={() => handleOpenUploadDiag()}>
<UploadFileIcon
sx={{
marginRight: '8px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Box, Grid, Typography } from '@mui/material'
import { B3CustomForm, B3Sping, CustomButton } from '@/components'
import { QuoteListitemProps } from '@/pages/quote/shared/config'
import { GlobaledContext } from '@/shared/global'
import { B3LStorage, compareOption, snackbar } from '@/utils'
import { B3LStorage, B3SStorage, compareOption, snackbar } from '@/utils'
import {
getAllModifierDefaultValue,
getQuickAddRowFields,
Expand Down Expand Up @@ -319,6 +319,16 @@ export default function QuickAdd(props: AddToListContentProps) {
}

const handleAddToList = () => {
const blockPendingAccountViewPrice = B3SStorage.get(
'blockPendingAccountViewPrice'
)
if (blockPendingAccountViewPrice) {
snackbar.info(
'Your business account is pending approval. This feature is currently disabled.'
)
return
}

handleSubmit(async (value) => {
try {
setIsLoading(true)
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 { B3SStorage, calculateProductListPrice } from '@/utils'
import { B3SStorage, calculateProductListPrice, snackbar } from '@/utils'
import { conversionProductsList } from '@/utils/b3Product/shared/config'

import { ShoppingListProductItem } from '../../../types'
Expand Down Expand Up @@ -45,6 +45,17 @@ export default function SearchProduct({
if (!searchText || isLoading) {
return
}

const blockPendingAccountViewPrice = B3SStorage.get(
'blockPendingAccountViewPrice'
)
if (blockPendingAccountViewPrice) {
snackbar.info(
'Your business account is pending approval. This feature is currently disabled.'
)
return
}

const companyId =
B3SStorage.get('B3CompanyInfo')?.id || B3SStorage.get('salesRepCompanyId')
const customerGroupId = B3SStorage.get('B3CustomerInfo')?.customerGroupId
Expand Down
15 changes: 15 additions & 0 deletions apps/storefront/src/utils/storefrontConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ const storeforntKeys: StoreforntKeysProps[] = [
key: 'block_pending_account_order_creation',
name: 'blockPendingAccountOrderCreation',
},
{
key: 'block_pending_account_seeing_products_pricing',
name: 'blockPendingAccountViewPrice',
},
]

const getTemPlateConfig = async (
Expand All @@ -153,6 +157,7 @@ const getTemPlateConfig = async (

const obj: Partial<CustomStyleButtonState> | {} = {}
let blockPendingAccountOrderCreation = true
let blockPendingAccountViewPrice = true
storefrontConfigs.forEach((item: any) => {
const storeforntKey: StoreforntKeysProps | undefined = storeforntKeys.find(
(option) => option.key === item.key
Expand Down Expand Up @@ -215,6 +220,16 @@ const getTemPlateConfig = async (
)
}

if (
storeforntKey.key === 'block_pending_account_seeing_products_pricing'
) {
blockPendingAccountViewPrice = item.value === '1'
B3SStorage.set(
'blockPendingAccountViewPrice',
blockPendingAccountViewPrice
)
}

;(obj as CustomFieldItems)[(storeforntKey as StoreforntKeysProps).name] =
{
...item.extraFields,
Expand Down

0 comments on commit a15a14e

Please sign in to comment.