Selection reset logic update

This commit is contained in:
Serkan Reis 2022-11-04 16:25:31 +03:00
parent 2579e449be
commit 68e6b80d2d

View File

@ -11,15 +11,15 @@ interface WhitelistUploadProps {
export const WhitelistUpload = ({ onChange }: WhitelistUploadProps) => { export const WhitelistUpload = ({ onChange }: WhitelistUploadProps) => {
const onFileChange = (event: React.ChangeEvent<HTMLInputElement>) => { const onFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
if (!event.target.files) return toast.error('Error opening file') if (!event.target.files) return toast.error('Error opening file')
if (event.target.files.length !== 1) {
toast.error('No file selected')
return onChange([])
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (event.target.files[0]?.type !== 'text/plain') { if (event.target.files[0]?.type !== 'text/plain') {
toast.error('Invalid file type') toast.error('Invalid file type')
return onChange([]) return onChange([])
} }
if (event.target.files.length === 0) {
toast.error('No file selected')
return onChange([])
}
const reader = new FileReader() const reader = new FileReader()
reader.onload = (e: ProgressEvent<FileReader>) => { reader.onload = (e: ProgressEvent<FileReader>) => {
const text = e.target?.result?.toString() const text = e.target?.result?.toString()