Skip to content

Commit 79d90e5

Browse files
document dropzone working for PDFs at /upload
1 parent 1c777ba commit 79d90e5

2 files changed

Lines changed: 111 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import DocumentDropzoneComponent from "@/components/form/form-elements/DocumentDropZone";
3+
import { Metadata } from "next";
4+
5+
export const metadata: Metadata = {
6+
title: "Upload Page",
7+
description: "This is Next.js Upload Page",
8+
};
9+
10+
export default function Upload() {
11+
return <DocumentDropzoneComponent />;
12+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"use client";
2+
import React, { useState } from "react";
3+
import ComponentCard from "../../common/ComponentCard";
4+
import { useDropzone } from "react-dropzone";
5+
6+
const DropzoneComponent: React.FC = () => {
7+
const [files, setFiles] = useState<File[]>([]);
8+
9+
const onDrop = (acceptedFiles: File[]) => {
10+
setFiles(prev => [...prev, ...acceptedFiles]); // add new files
11+
};
12+
13+
const { getRootProps, getInputProps, isDragActive } = useDropzone({
14+
onDrop,
15+
accept: {
16+
"application/pdf": [],
17+
},
18+
});
19+
20+
const handleDelete = (index: number) => {
21+
setFiles(prev => prev.filter((_, i) => i !== index));
22+
};
23+
24+
return (
25+
<ComponentCard title="Upload Documents">
26+
<div className="transition border border-gray-300 border-dashed cursor-pointer dark:hover:border-brand-500 dark:border-gray-700 rounded-xl hover:border-brand-500">
27+
<div>
28+
<form
29+
{...getRootProps()}
30+
className={`dropzone rounded-xl border-dashed border-gray-300 p-7 lg:p-10 ${
31+
isDragActive
32+
? "border-brand-500 bg-gray-100 dark:bg-gray-800"
33+
: "border-gray-300 bg-gray-50 dark:border-gray-700 dark:bg-gray-900"
34+
}`}
35+
id="demo-upload"
36+
>
37+
<input {...getInputProps()} />
38+
<div className="dz-message flex flex-col items-center m-0!">
39+
<div className="mb-[22px] flex justify-center">
40+
<div className="flex h-[68px] w-[68px] items-center justify-center rounded-full bg-gray-200 text-gray-700 dark:bg-gray-800 dark:text-gray-400">
41+
<svg
42+
className="fill-current"
43+
width="29"
44+
height="28"
45+
viewBox="0 0 29 28"
46+
xmlns="http://www.w3.org/2000/svg"
47+
>
48+
<path
49+
fillRule="evenodd"
50+
clipRule="evenodd"
51+
d="M14.5019 3.91699C14.2852 3.91699 14.0899 4.00891 13.953 4.15589L8.57363 9.53186C8.28065 9.82466 8.2805 10.2995 8.5733 10.5925C8.8661 10.8855 9.34097 10.8857 9.63396 10.5929L13.7519 6.47752V18.667C13.7519 19.0812 14.0877 19.417 14.5019 19.417C14.9161 19.417 15.2519 19.0812 15.2519 18.667V6.48234L19.3653 10.5929C19.6583 10.8857 20.1332 10.8855 20.426 10.5925C20.7188 10.2995 20.7186 9.82463 20.4256 9.53184L15.0838 4.19378C14.9463 4.02488 14.7367 3.91699 14.5019 3.91699ZM5.91626 18.667C5.91626 18.2528 5.58047 17.917 5.16626 17.917C4.75205 17.917 4.41626 18.2528 4.41626 18.667V21.8337C4.41626 23.0763 5.42362 24.0837 6.66626 24.0837H22.3339C23.5766 24.0837 24.5839 23.0763 24.5839 21.8337V18.667C24.5839 18.2528 24.2482 17.917 23.8339 17.917C23.4197 17.917 23.0839 18.2528 23.0839 18.667V21.8337C23.0839 22.2479 22.7482 22.5837 22.3339 22.5837H6.66626C6.25205 22.5837 5.91626 22.2479 5.91626 21.8337V18.667Z"
52+
/>
53+
</svg>
54+
</div>
55+
</div>
56+
57+
<h4 className="mb-3 font-semibold text-gray-800 text-theme-xl dark:text-white/90">
58+
{isDragActive ? "Drop Files Here" : "Drag & Drop Files Here"}
59+
</h4>
60+
<span className="text-center mb-5 block w-full max-w-[290px] text-sm text-gray-700 dark:text-gray-400">
61+
Drag and drop your PDF documents here or browse
62+
</span>
63+
<span className="font-medium underline text-theme-sm text-brand-500">
64+
Browse File
65+
</span>
66+
</div>
67+
</form>
68+
</div>
69+
70+
<div className="mt-4 text-sm text-gray-500 dark:text-gray-400">
71+
72+
{/* File List */}
73+
{files.length > 0 && (
74+
<ul className="mt-4 space-y-2">
75+
{files.map((file, index) => (
76+
<li
77+
key={index}
78+
className="flex items-center justify-between rounded-md border border-gray-300 p-2 dark:border-gray-700"
79+
>
80+
<span className="truncate">{file.name}</span>
81+
<button
82+
onClick={() => handleDelete(index)}
83+
className="ml-2 text-red-500 hover:text-red-700"
84+
type="button"
85+
>
86+
Delete
87+
</button>
88+
</li>
89+
))}
90+
</ul>
91+
)}
92+
</div>
93+
94+
</div>
95+
</ComponentCard>
96+
);
97+
};
98+
99+
export default DropzoneComponent;

0 commit comments

Comments
 (0)