diff --git a/apps/web/pages/api/documents/[id].ts b/apps/web/pages/api/documents/[id].ts
index f378d5372..f921e218d 100644
--- a/apps/web/pages/api/documents/[id].ts
+++ b/apps/web/pages/api/documents/[id].ts
@@ -40,6 +40,29 @@ async function getHandler(req: NextApiRequest, res: NextApiResponse) {
return;
}
+async function deleteHandler(req: NextApiRequest, res: NextApiResponse) {
+ const user = getUserFromToken(req, res);
+ const { id: documentId } = req.query;
+
+ if (!user) return;
+
+ if (!documentId) {
+ res.status(400).send("Missing parameter documentId.");
+ return;
+ }
+
+ await prisma.document
+ .delete({
+ where: {
+ id: +documentId,
+ },
+ })
+ .then(() => {
+ res.status(200).end();
+ });
+}
+
export default defaultHandler({
GET: Promise.resolve({ default: defaultResponder(getHandler) }),
+ DELETE: Promise.resolve({ default: defaultResponder(deleteHandler) }),
});
diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsx
index 76dd49474..7bd0b6335 100644
--- a/apps/web/pages/dashboard.tsx
+++ b/apps/web/pages/dashboard.tsx
@@ -60,6 +60,7 @@ const DashboardPage: NextPageWithLayout = () => {
link: "/documents?filter=",
},
];
+
const uploadToServer = async (event: any) => {
if (event.target.files && event.target.files[0]) {
const body = new FormData();
@@ -108,30 +109,6 @@ const DashboardPage: NextPageWithLayout = () => {
))}
+
>
);
diff --git a/apps/web/pages/documents.tsx b/apps/web/pages/documents.tsx
index 07d34e83f..4b62084b9 100644
--- a/apps/web/pages/documents.tsx
+++ b/apps/web/pages/documents.tsx
@@ -3,17 +3,20 @@ import { ReactElement, useEffect, useState } from "react";
import Layout from "../components/layout";
import type { NextPageWithLayout } from "./_app";
import Head from "next/head";
-import { PlusIcon } from "@heroicons/react/24/outline";
+import { PlusIcon, TrashIcon } from "@heroicons/react/24/outline";
import { Document as PrismaDocument } from "@prisma/client";
import { getUserFromToken } from "@documenso/lib/server";
import Link from "next/link";
+import { useRouter } from "next/router";
+import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants";
const DocumentsPage: NextPageWithLayout = (req, res) => {
- const [documents = [], setDocuments] = useState([]);
+ const router = useRouter();
+ const [documents, setDocuments] = useState([]);
useEffect(() => {
getDocuments();
- }, []);
+ });
const getDocuments = async () => {
fetch("/api/documents", {
@@ -27,19 +30,143 @@ const DocumentsPage: NextPageWithLayout = (req, res) => {
});
};
+ function showDocument(documentId: number) {
+ router.push("/documents/" + documentId);
+ }
+
+ const uploadToServer = async (event: any) => {
+ if (event.target.files && event.target.files[0]) {
+ const body = new FormData();
+ const document = event.target.files[0];
+ body.append("document", document || "");
+ const response: any = await fetch("/api/documents", {
+ method: "POST",
+ body,
+ }).then((response: Response) => {
+ response.json().then((createdDocumentIdFromBody) => {
+ router.push(
+ `${NEXT_PUBLIC_WEBAPP_URL}/documents/${createdDocumentIdFromBody}`
+ );
+ });
+ });
+ }
+ };
+
return (
<>
Documents | Documenso
- {documents.map((item: any) => (
-
-
- Document Nr.{item.id}
-
+
+
- ))}
-
+
+
+
+
+
+
+
+ |
+ Title
+ |
+
+ Recipients
+ |
+
+ Status
+ |
+
+ Delete
+ |
+
+
+
+ {documents.map((document: any) => (
+ showDocument(document.id)}
+ >
+ |
+ {document.title || "#" + document.id}
+ |
+
+ {document.recipients || "-"}
+ |
+
+ {document.status || "Draft"}
+ |
+
+
+ {
+ event.preventDefault();
+ event.stopPropagation();
+ if (
+ confirm(
+ "Are you sure you want to delete this document"
+ )
+ ) {
+ fetch(`/api/documents/${document.id}`, {
+ method: "DELETE",
+ }).then(() => {
+ getDocuments();
+ });
+ }
+ }}
+ />
+ , {document.name}
+
+ |
+
+ ))}
+
+
+
+
+
+
+
+
>