From d0a8faa3e7fded1b917d204174eb74c9c1e5a7b9 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Wed, 15 Feb 2023 18:26:49 +0100 Subject: [PATCH] :bug: Fix input file empty error --- .../src/components/ImageUploadContent/UploadButton.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/builder/src/components/ImageUploadContent/UploadButton.tsx b/apps/builder/src/components/ImageUploadContent/UploadButton.tsx index 978204054..6293e1101 100644 --- a/apps/builder/src/components/ImageUploadContent/UploadButton.tsx +++ b/apps/builder/src/components/ImageUploadContent/UploadButton.tsx @@ -1,3 +1,4 @@ +import { useToast } from '@/hooks/useToast' import { compressFile } from '@/utils/helpers' import { Button, ButtonProps, chakra } from '@chakra-ui/react' import { ChangeEvent, useState } from 'react' @@ -18,11 +19,14 @@ export const UploadButton = ({ ...props }: UploadButtonProps) => { const [isUploading, setIsUploading] = useState(false) + const { showToast } = useToast() const handleInputChange = async (e: ChangeEvent) => { if (!e.target?.files) return 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({ files: [ {