2
0

🐛 Fix input file empty error

This commit is contained in:
Baptiste Arnaud
2023-02-15 18:26:49 +01:00
parent 8ac3784c0f
commit d0a8faa3e7

View File

@ -1,3 +1,4 @@
import { useToast } from '@/hooks/useToast'
import { compressFile } from '@/utils/helpers' import { compressFile } from '@/utils/helpers'
import { Button, ButtonProps, chakra } from '@chakra-ui/react' import { Button, ButtonProps, chakra } from '@chakra-ui/react'
import { ChangeEvent, useState } from 'react' import { ChangeEvent, useState } from 'react'
@ -18,11 +19,14 @@ export const UploadButton = ({
...props ...props
}: UploadButtonProps) => { }: UploadButtonProps) => {
const [isUploading, setIsUploading] = useState(false) const [isUploading, setIsUploading] = useState(false)
const { showToast } = useToast()
const handleInputChange = async (e: ChangeEvent<HTMLInputElement>) => { const handleInputChange = async (e: ChangeEvent<HTMLInputElement>) => {
if (!e.target?.files) return if (!e.target?.files) return
setIsUploading(true) setIsUploading(true)
const file = e.target.files[0] const file = e.target.files[0] as File | undefined
if (!file)
return showToast({ description: 'Could not read file.', status: 'error' })
const urls = await uploadFiles({ const urls = await uploadFiles({
files: [ files: [
{ {