@@ -23,6 +23,7 @@ import { useS3Upload } from "next-s3-upload";
23
23
import { useState } from "react" ;
24
24
import { useDropzone } from "react-dropzone" ;
25
25
import { MdCheckCircle , MdCloud } from "react-icons/md" ;
26
+ import { IoIosClose } from "react-icons/io" ;
26
27
import { useMutation } from "react-query" ;
27
28
import AvatarsPlaceholder from "../home/AvatarsPlaceholder" ;
28
29
import { CheckedListItem } from "../home/Pricing" ;
@@ -84,6 +85,17 @@ const Uploader = ({ handleOnAdd }: { handleOnAdd: () => void }) => {
84
85
} ) ;
85
86
86
87
const handleUpload = async ( ) => {
88
+ if ( files . length < 5 ) {
89
+ toast ( {
90
+ title : "You need to upload at least 5 photos" ,
91
+ duration : 3000 ,
92
+ isClosable : true ,
93
+ position : "top-right" ,
94
+ status : "error" ,
95
+ } ) ;
96
+ return ;
97
+ }
98
+
87
99
const filesToUpload = Array . from ( files ) ;
88
100
setUploadState ( "uploading" ) ;
89
101
@@ -197,14 +209,28 @@ const Uploader = ({ handleOnAdd }: { handleOnAdd: () => void }) => {
197
209
key = { file . name }
198
210
>
199
211
< Center top = { - 2 } right = { - 2 } position = "absolute" >
200
- { uploadState == "uploading" && ! urls [ index ] && (
212
+ { uploadState === "uploading" && ! urls [ index ] && (
201
213
< Spinner
202
214
size = "lg"
203
215
thickness = "8px"
204
216
speed = "1s"
205
217
color = "brand.500"
206
218
/>
207
219
) }
220
+
221
+ { uploadState !== "uploading" && ! urls [ index ] && (
222
+ < Icon
223
+ cursor = "pointer"
224
+ onClick = { ( ) => {
225
+ setFiles ( files . filter ( ( _ , i ) => i !== index ) ) ;
226
+ } }
227
+ borderRadius = "full"
228
+ backgroundColor = "brand.500"
229
+ as = { IoIosClose }
230
+ fontSize = "2rem"
231
+ />
232
+ ) }
233
+
208
234
{ urls [ index ] && (
209
235
< Icon
210
236
borderRadius = "full"
@@ -241,7 +267,9 @@ const Uploader = ({ handleOnAdd }: { handleOnAdd: () => void }) => {
241
267
onClick = { handleUpload }
242
268
variant = "brand"
243
269
>
244
- Upload { files . length } image{ files . length > 1 && "s" }
270
+ { files . length < 5
271
+ ? "Upload (min 5 photos)"
272
+ : `Upload ${ files . length } photo${ files . length > 1 && "s" } ` }
245
273
</ Button >
246
274
</ Box >
247
275
) }
0 commit comments