Skip to content

Commit

Permalink
fix: fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 authored and kris-liu-smile committed Mar 10, 2023
1 parent 4e881be commit 9347229
Show file tree
Hide file tree
Showing 20 changed files with 447 additions and 310 deletions.
7 changes: 1 addition & 6 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import {
showPageMask,
} from '@/utils'

import {
removeCartPermissions,
} from '@/utils/b3RolePermissions'

import {
GlobaledContext,
} from '@/shared/global'
Expand Down Expand Up @@ -98,6 +94,7 @@ export default function App() {
setOpenPage,
productQuoteEnabled,
B3UserId,
role,
})
useCartToQuote({
setOpenPage,
Expand Down Expand Up @@ -238,8 +235,6 @@ export default function App() {
},
})
}

removeCartPermissions(role)
}, [isB2BUser, isAgenting, role, quoteConfig, storefrontConfig])

useRegisteredbctob2b(setOpenPage, isB2BUser, customerId)
Expand Down
11 changes: 6 additions & 5 deletions apps/storefront/src/components/B3Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export const B3Dialog:<T> ({
}
}

const handleCloseClick = () => {
const handleCloseClick = (reason?: string) => {
if (reason === 'backdropClick') return
if (handleLeftClick) handleLeftClick()
}

Expand All @@ -115,7 +116,7 @@ export const B3Dialog:<T> ({
fullWidth={fullWidth}
open={isOpen}
container={container.current}
onClose={handleCloseClick}
onClose={(event: object, reason: string) => handleCloseClick(reason)}
fullScreen={isMobile}
maxWidth={maxWidth}
aria-labelledby="alert-dialog-title"
Expand Down Expand Up @@ -143,9 +144,9 @@ export const B3Dialog:<T> ({
sx={
isShowBordered ? {
borderTop: '1px solid #D9DCE9',
marginBottom: isAgenting ? '52px' : '0',
marginBottom: (isAgenting && isMobile) ? '52px' : '0',
} : {
marginBottom: isAgenting ? '52px' : '0',
marginBottom: (isAgenting && isMobile) ? '52px' : '0',
}
}
>
Expand All @@ -156,7 +157,7 @@ export const B3Dialog:<T> ({
sx={{
...leftStyleBtn,
}}
onClick={handleCloseClick}
onClick={() => handleCloseClick('')}
>
{leftSizeBtn || 'cancel'}

Expand Down
1 change: 0 additions & 1 deletion apps/storefront/src/components/layout/B3RenderRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const B3RenderRouter = (props: B3RenderRouterProps) => {
}, [location])

useEffect(() => {
console.log(location.pathname, openUrl, 'openUrl')
if (openUrl && openUrl === '/?closeMasqurade=1') {
navigate('/', {
state: {
Expand Down
145 changes: 48 additions & 97 deletions apps/storefront/src/components/upload/B3Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Box,
Button,
Link,
Alert,
} from '@mui/material'

import Grid from '@mui/material/Unstable_Grid2'
Expand All @@ -12,6 +13,7 @@ import {
Dispatch,
SetStateAction,
useContext,
useEffect,
} from 'react'

import {
Expand All @@ -23,7 +25,6 @@ import styled from '@emotion/styled'
import InsertDriveFile from '@mui/icons-material/InsertDriveFile'

import {
snackbar,
getDefaultCurrencyInfo,
} from '@/utils'

Expand Down Expand Up @@ -111,6 +112,7 @@ export const B3Upload = (props: B3UploadProps) => {
const [step, setStep] = useState<string>('init')
const [fileDatas, setFileDatas] = useState<CustomFieldItems>({})
const [fileName, setFileName] = useState('')
const [fileErrorText, setFileErrorText] = useState('')

const {
currency_code: currencyCode,
Expand Down Expand Up @@ -182,7 +184,6 @@ export const B3Upload = (props: B3UploadProps) => {
const signleRow = EmptyData[i].split(',')
if (signleRow.length > columns) {
error = 'redundant data;'
return
}
}
}
Expand All @@ -207,12 +208,15 @@ export const B3Upload = (props: B3UploadProps) => {
try {
const parseData = await parseFile(file)
if (parseData.length) {
setFileErrorText('')
setStep('loadding')
setFileName(file.name)
await handleBulkUploadCSV(parseData)
}
} catch (error) {
console.log((error as Error).message)
if ((error as Error)?.message) {
setFileErrorText((error as Error)?.message)
}
}
}
}
Expand All @@ -221,104 +225,24 @@ export const B3Upload = (props: B3UploadProps) => {
if (uploadRef.current) (uploadRef.current.children[1] as HTMLElement).click()
}

const getValidProducts = (products: CustomFieldItems) => {
const notPurchaseSku: string[] = []
const productItems: CustomFieldItems[] = []
const limitProduct: CustomFieldItems[] = []
const minLimitQuantity: CustomFieldItems[] = []
const maxLimitQuantity: CustomFieldItems[] = []
const outOfStock: CustomFieldItems[] = []

products.forEach((item: CustomFieldItems) => {
const {
products: currentProduct,
qty,
} = item
const {
option,
isStock,
stock,
purchasingDisabled,
maxQuantity,
minQuantity,
variantSku,
variantId,
productId,
} = currentProduct

if (purchasingDisabled === '1') {
notPurchaseSku.push(variantSku)
return
}

if (isStock === '1' && stock === 0) {
outOfStock.push(variantSku)
return
}

if ((isStock === '1' && stock > 0) && stock < +qty) {
limitProduct.push({
variantSku,
AvailableAmount: stock,
})
return
}

if (+minQuantity > 0 && +qty < +minQuantity) {
minLimitQuantity.push({
variantSku,
minQuantity,
})

return
}

if (+maxQuantity > 0 && +qty > +maxQuantity) {
maxLimitQuantity.push({
variantSku,
maxQuantity,
})

return
}

const optionsList = option.map((item: CustomFieldItems) => ({
optionId: item.option_id,
optionValue: item.id,
}))

productItems.push({
productId: parseInt(productId, 10) || 0,
variantId: parseInt(variantId, 10) || 0,
quantity: +qty,
optionList: optionsList,
})
})

return {
notPurchaseSku,
productItems,
limitProduct,
minLimitQuantity,
maxLimitQuantity,
outOfStock,
}
}

const handleConfirmToList = () => {
const handleConfirmToList = async () => {
const validProduct = fileDatas?.validProduct || []
const stockErrorFile = fileDatas?.stockErrorFile || ''
const stockErrorSkus = fileDatas?.stockErrorSkus || []
if (validProduct?.length === 0) return

if (validProduct) {
const productsData: CustomFieldItems = getValidProducts(validProduct)
const productsData: CustomFieldItems = {
validProduct,
}

if (stockErrorSkus.length > 0) {
productsData.stockErrorFile = stockErrorFile
}

handleAddToList(productsData)
await handleAddToList(productsData)

setStep('init')
}
}

Expand Down Expand Up @@ -388,7 +312,10 @@ export const B3Upload = (props: B3UploadProps) => {
marginLeft: '0.5rem',
}}
>
<Link href="https://silk-demo-store45.mybigcommerce.com/content/sample_template.csv">
<Link
href="https://silk-demo-store45.mybigcommerce.com/content/sample_template.csv"
underline="none"
>
Download sample
</Link>
</Box>
Expand All @@ -411,28 +338,52 @@ export const B3Upload = (props: B3UploadProps) => {
</Box>
)

useEffect(() => {
setFileErrorText('')
setStep('init')
}, [isOpen])

return (
<B3Dialog
isOpen={isOpen}
title={bulkUploadTitle}
maxWidth="lg"
leftSizeBtn={step === 'end' ? addBtnText : 'cancel'}
handleLeftClick={step === 'end' ? () => {
handleConfirmToList()
} : () => {
rightSizeBtn={addBtnText}
leftSizeBtn="cancel"
handleLeftClick={() => {
setStep('init')
setIsOpen(false)
}}
showRightBtn={false}
handRightClick={() => {
handleConfirmToList()
}}
showRightBtn={step === 'end'}
isShowBordered={false}
>
{
fileErrorText.length > 0 && (
<Box
sx={{
m: '0 0 1rem 0',
p: '0 1rem',
}}
>
<Alert
variant="filled"
severity="error"
>
{fileErrorText}
</Alert>
</Box>
)
}
<Box
sx={{
maxHeight: isMobile ? '200px' : 'calc(100% - 64px)',
minWidth: isMobile ? '100%' : '600px',
margin: isMobile ? '' : '1rem',
}}
>

{
step === 'init' && (
<FileUploadContainer ref={uploadRef}>
Expand Down
Loading

0 comments on commit 9347229

Please sign in to comment.