Skip to content

Commit

Permalink
fix: upload type limit
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 committed Apr 21, 2023
1 parent eb8e001 commit 8980f3b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
41 changes: 40 additions & 1 deletion apps/storefront/src/components/upload/B3Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,42 @@ export const B3Upload = (props: B3UploadProps) => {
currency_code: currencyCode,
} = getDefaultCurrencyInfo()

const getRejectMessage = (
rejectedFile: File,
acceptedFiles: string[],
maxFileSize: number,
) => {
const {
size,
type,
} = rejectedFile

let isAcceptFileType = false
acceptedFiles.forEach((acceptedFileType: string) => {
isAcceptFileType = new RegExp(acceptedFileType).test(type) || isAcceptFileType
})

let message = ''
if (!isAcceptFileType) {
message = 'Table structure is wrong. Please download sample and follow it\'s structure.'
setFileErrorText(message)
return message
}

if (size > maxFileSize) {
message = 'Maximum file size 50MB'
setFileErrorText(message)
return message
}

return message
}

const getFileLimitExceedMessage = () => {
setFileErrorText('Maximum file size 50MB')
return ''
}

const handleVerificationFile = (size: number, type: string): string => {
if (type !== 'text/csv') {
return 'Table structure is wrong. Please download sample and follow it\'s structure.'
Expand Down Expand Up @@ -407,7 +443,6 @@ export const B3Upload = (props: B3UploadProps) => {
<Box
sx={{
m: '0 0 1rem 0',
p: '0 1rem',
}}
>
<Alert
Expand Down Expand Up @@ -437,6 +472,10 @@ export const B3Upload = (props: B3UploadProps) => {
showPreviewsInDropzone={false}
showAlerts={false}
dropzoneText=""
maxFileSize={50 * 1024 * 1024}
acceptedFiles={['text/csv']}
getDropRejectMessage={getRejectMessage}
getFileLimitExceedMessage={getFileLimitExceedMessage}
/>
</FileUploadContainer>
)
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default function Login(props:RegisteredProps) {
}

init()
}, [])
}, [loginPageButton, loginPageDisplay, loginPageHtml])

const tipInfo = (loginFlag: string, email = '') => {
if (!loginFlag) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const QuoteTermsAndConditions = (props: QuoteTermsAndConditionsProps) =>
quoteLegalTerms = '',
} = props

const isMobile = useMobile()
const [isMobile] = useMobile()
const [isOpen, setIsOpen] = useState(false)

const handleOnChange = (open: boolean) => {
Expand Down

0 comments on commit 8980f3b

Please sign in to comment.