Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Pushpender1122 committed Oct 2, 2024
1 parent d33e7cc commit feeb5e0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/components/DragAndDropForm.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ArrowCircleDownIcon } from "@heroicons/react/outline";
import { useCallback, useRef } from "react";
import { useCallback, useRef, useState } from "react";
import { useDropzone } from "react-dropzone";
import { Form, useSubmit } from "remix";
import invariant from "tiny-invariant";

import ToastPopover from "./UI/ToastPopover";
export function DragAndDropForm() {
const formRef = useRef<HTMLFormElement>(null);
const filenameInputRef = useRef<HTMLInputElement>(null);
const rawJsonInputRef = useRef<HTMLInputElement>(null);

const [error, setError] = useState<string | null>(null);
const submit = useSubmit();

const onDrop = useCallback(
Expand Down Expand Up @@ -60,6 +60,10 @@ export function DragAndDropForm() {
maxSize: 1024 * 1024 * 1,
multiple: false,
accept: "application/json",
onDropRejected: (fileRejections) => {
setError(fileRejections[0].errors[0].message);
setTimeout(() => setError(null), 4000);
},
});

return (
Expand All @@ -85,6 +89,14 @@ export function DragAndDropForm() {
<input type="hidden" name="filename" ref={filenameInputRef} />
<input type="hidden" name="rawJson" ref={rawJsonInputRef} />
</div>
{error && (
<ToastPopover
message={error}
title="Error"
type="error"
key={Date.now()}
/>
)}
</Form>
);
}

0 comments on commit feeb5e0

Please sign in to comment.