Skip to content

Commit feeb5e0

Browse files
1 parent d33e7cc commit feeb5e0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

app/components/DragAndDropForm.tsx

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { ArrowCircleDownIcon } from "@heroicons/react/outline";
2-
import { useCallback, useRef } from "react";
2+
import { useCallback, useRef, useState } from "react";
33
import { useDropzone } from "react-dropzone";
44
import { Form, useSubmit } from "remix";
55
import invariant from "tiny-invariant";
6-
6+
import ToastPopover from "./UI/ToastPopover";
77
export function DragAndDropForm() {
88
const formRef = useRef<HTMLFormElement>(null);
99
const filenameInputRef = useRef<HTMLInputElement>(null);
1010
const rawJsonInputRef = useRef<HTMLInputElement>(null);
11-
11+
const [error, setError] = useState<string | null>(null);
1212
const submit = useSubmit();
1313

1414
const onDrop = useCallback(
@@ -60,6 +60,10 @@ export function DragAndDropForm() {
6060
maxSize: 1024 * 1024 * 1,
6161
multiple: false,
6262
accept: "application/json",
63+
onDropRejected: (fileRejections) => {
64+
setError(fileRejections[0].errors[0].message);
65+
setTimeout(() => setError(null), 4000);
66+
},
6367
});
6468

6569
return (
@@ -85,6 +89,14 @@ export function DragAndDropForm() {
8589
<input type="hidden" name="filename" ref={filenameInputRef} />
8690
<input type="hidden" name="rawJson" ref={rawJsonInputRef} />
8791
</div>
92+
{error && (
93+
<ToastPopover
94+
message={error}
95+
title="Error"
96+
type="error"
97+
key={Date.now()}
98+
/>
99+
)}
88100
</Form>
89101
);
90102
}

0 commit comments

Comments
 (0)