Skip to content

The Open Source DocuSign Alternative.

render doc list

Timur Ercan9a7a2bdd87fa
diff --git a/apps/web/pages/api/documents/index.ts b/apps/web/pages/api/documents/index.ts
index 66f479835..fc14bb89e 100644
--- a/apps/web/pages/api/documents/index.ts
+++ b/apps/web/pages/api/documents/index.ts
@@ -47,9 +47,12 @@ async function getHandler(req: NextApiRequest, res: NextApiResponse) {
let user = await getUserFromToken(req, res);
if (!user) return;
- return res
- .status(200)
- .json(await prisma.document.findMany({ where: { userId: user?.id } }));
+ return res.status(200).json(
+ await prisma.document.findMany({
+ where: { userId: user?.id },
+ select: { id: true },
+ })
+ );
}
export default defaultHandler({
diff --git a/apps/web/pages/documents.tsx b/apps/web/pages/documents.tsx
index 0b3966c96..07d34e83f 100644
--- a/apps/web/pages/documents.tsx
+++ b/apps/web/pages/documents.tsx
@@ -1,17 +1,45 @@
import { useSession } from "next-auth/react";
-import type { ReactElement } from "react";
+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 { Document as PrismaDocument } from "@prisma/client";
+import { getUserFromToken } from "@documenso/lib/server";
+import Link from "next/link";
+
+const DocumentsPage: NextPageWithLayout = (req, res) => {
+ const [documents = [], setDocuments] = useState([]);
+
+ useEffect(() => {
+ getDocuments();
+ }, []);
+
+ const getDocuments = async () => {
+ fetch("/api/documents", {
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }).then((res) => {
+ res.json().then((j) => {
+ setDocuments(j);
+ });
+ });
+ };
-const DocumentsPage: NextPageWithLayout = () => {
return (
<>
<Head>
<title>Documents | Documenso</title>
</Head>
- <div className="text-center mt-24" id="empty">
+ {documents.map((item: any) => (
+ <div>
+ <Link key={item.id} href={"/documents/" + item.id} target="_blank">
+ Document Nr.{item.id}
+ </Link>
+ </div>
+ ))}
+ <div className="text-center mt-24" id="empty" hidden>
<svg
className="mx-auto h-12 w-12 text-gray-400"
fill="none"