Skip to content

Commit

Permalink
feat: update quote file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton authored and BrianJiang2021 committed Feb 13, 2023
1 parent 7a79438 commit 455fc60
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 27 deletions.
12 changes: 5 additions & 7 deletions apps/storefront/src/components/B3QuantityTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export const B3QuantityTextField = (props: B3NumberTextFieldProps) => {
validMessage = ('Out of stock')
} else if (isStock === '1' && quantity > stock) {
validMessage = (`${stock} in stock`)
} else if (minQuantity !== 0 && quantity < minQuantity) {
validMessage = (`Min is ${minQuantity}`)
} else if (maxQuantity !== 0 && quantity > maxQuantity) {
validMessage = (`Max is ${maxQuantity}`)
}

setValidMessage(validMessage)
Expand All @@ -69,13 +73,7 @@ export const B3QuantityTextField = (props: B3NumberTextFieldProps) => {
}

const handleBlur = () => {
let quantity = parseInt(`${value}`, 10) || 0

if (minQuantity !== 0 && quantity < minQuantity) {
quantity = minQuantity
} else if (maxQuantity !== 0 && quantity > maxQuantity) {
quantity = maxQuantity
}
const quantity = parseInt(`${value}`, 10) || 0

onChange(quantity, !validateQuantity(quantity))
}
Expand Down
39 changes: 38 additions & 1 deletion apps/storefront/src/pages/quote/QuoteDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ const QuoteDetail = () => {
const [quoteDetail, setQuoteDetail] = useState<any>({})
const [productList, setProductList] = useState<any>([])
const [currency, setCurrency] = useState<any>({})
const [fileList, setFileList] = useState<any>([])

const [quoteSummary, setQuoteSummary] = useState<any>({
originalSubtotal: 0,
discount: 0,
Expand Down Expand Up @@ -113,6 +115,34 @@ const QuoteDetail = () => {
setCurrency(quote.currency)
setProductList(quote.productsList)

const {
backendAttachFiles = [],
storefrontAttachFiles = [],
} = quote

const newFileList: CustomFieldItems[] = []
storefrontAttachFiles.forEach((file: CustomFieldItems) => {
newFileList.push({
fileName: file.fileName,
fileType: file.fileType,
fileUrl: file.fileUrl,
id: file.fileUrl,
title: 'Uploaded by customer: xxxx', // TODO
})
})

backendAttachFiles.forEach((file: CustomFieldItems) => {
newFileList.push({
fileName: file.fileName,
fileType: file.fileType,
fileUrl: file.fileUrl,
id: file.fileUrl,
title: 'Uploaded by sales rep: xxxx', // TODO
})
})

setFileList(newFileList)

return quote
} catch (err: any) {
snackbar.error(err)
Expand Down Expand Up @@ -339,7 +369,14 @@ const QuoteDetail = () => {
displayPrint: 'none',
}}
>
<QuoteAttachment />
{
fileList.length > 0 && (
<QuoteAttachment
allowUpload={false}
defaultFileList={fileList}
/>
)
}
</Box>
</Grid>
</Grid>
Expand Down
20 changes: 19 additions & 1 deletion apps/storefront/src/pages/quote/QuoteDraft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,19 @@ const QuoteDraft = ({
quoteTableRef.current?.refreshList()
}

const getFileList = (files: CustomFieldItems[]) => {
if (role === 100) {
return []
}

return files.map((file) => ({
fileUrl: file.fileUrl,
fileName: file.fileName,
fileType: file.fileType,
fileSize: `${file.fileSize}`,
}))
}

const handleSubmit = async () => {
setLoading(true)
try {
Expand Down Expand Up @@ -467,6 +480,8 @@ const QuoteDraft = ({

const currency = getDefaultCurrencyInfo()

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

const data = {
notes: note,
legalTerms: '',
Expand All @@ -482,6 +497,7 @@ const QuoteDraft = ({
billingAddress,
contactInfo,
productList,
fileList,
currency: {
currencyExchangeRate: currency.currency_exchange_rate,
token: currency.token,
Expand Down Expand Up @@ -745,7 +761,9 @@ const QuoteDraft = ({

<QuoteNote />

<QuoteAttachment />
{
role !== 100 && <QuoteAttachment />
}
</Stack>
</Container>
</Box>
Expand Down
Loading

0 comments on commit 455fc60

Please sign in to comment.