1
1
import { ArrowCircleDownIcon } from "@heroicons/react/outline" ;
2
- import { useCallback , useRef } from "react" ;
2
+ import { useCallback , useRef , useState } from "react" ;
3
3
import { useDropzone } from "react-dropzone" ;
4
4
import { Form , useSubmit } from "remix" ;
5
5
import invariant from "tiny-invariant" ;
6
-
6
+ import ToastPopover from "./UI/ToastPopover" ;
7
7
export function DragAndDropForm ( ) {
8
8
const formRef = useRef < HTMLFormElement > ( null ) ;
9
9
const filenameInputRef = useRef < HTMLInputElement > ( null ) ;
10
10
const rawJsonInputRef = useRef < HTMLInputElement > ( null ) ;
11
-
11
+ const [ error , setError ] = useState < string | null > ( null ) ;
12
12
const submit = useSubmit ( ) ;
13
13
14
14
const onDrop = useCallback (
@@ -60,6 +60,10 @@ export function DragAndDropForm() {
60
60
maxSize : 1024 * 1024 * 1 ,
61
61
multiple : false ,
62
62
accept : "application/json" ,
63
+ onDropRejected : ( fileRejections ) => {
64
+ setError ( fileRejections [ 0 ] . errors [ 0 ] . message ) ;
65
+ setTimeout ( ( ) => setError ( null ) , 4000 ) ;
66
+ } ,
63
67
} ) ;
64
68
65
69
return (
@@ -85,6 +89,14 @@ export function DragAndDropForm() {
85
89
< input type = "hidden" name = "filename" ref = { filenameInputRef } />
86
90
< input type = "hidden" name = "rawJson" ref = { rawJsonInputRef } />
87
91
</ div >
92
+ { error && (
93
+ < ToastPopover
94
+ message = { error }
95
+ title = "Error"
96
+ type = "error"
97
+ key = { Date . now ( ) }
98
+ />
99
+ ) }
88
100
</ Form >
89
101
) ;
90
102
}
0 commit comments