mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
dashboard
This commit is contained in:
@ -4,19 +4,15 @@ import Layout from "../components/layout";
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import type { NextPageWithLayout } from "./_app";
|
import type { NextPageWithLayout } from "./_app";
|
||||||
import {
|
import {
|
||||||
BellSnoozeIcon,
|
|
||||||
CheckBadgeIcon,
|
CheckBadgeIcon,
|
||||||
EnvelopeIcon,
|
DocumentIcon,
|
||||||
EyeIcon,
|
ExclamationTriangleIcon,
|
||||||
SunIcon,
|
UsersIcon,
|
||||||
XCircleIcon,
|
|
||||||
} from "@heroicons/react/24/outline";
|
} from "@heroicons/react/24/outline";
|
||||||
import { uploadDocument } from "@documenso/features";
|
import { uploadDocument } from "@documenso/features";
|
||||||
import prisma from "@documenso/prisma";
|
|
||||||
import {
|
import {
|
||||||
ReadStatus,
|
|
||||||
SendStatus,
|
|
||||||
DocumentStatus,
|
DocumentStatus,
|
||||||
|
SendStatus,
|
||||||
Document as PrismaDocument,
|
Document as PrismaDocument,
|
||||||
} from "@prisma/client";
|
} from "@prisma/client";
|
||||||
import { getUserFromToken } from "@documenso/lib/server";
|
import { getUserFromToken } from "@documenso/lib/server";
|
||||||
@ -31,38 +27,26 @@ const DashboardPage: NextPageWithLayout = (props: any) => {
|
|||||||
{
|
{
|
||||||
name: "Draft",
|
name: "Draft",
|
||||||
stat: "0",
|
stat: "0",
|
||||||
icon: SunIcon,
|
icon: DocumentIcon,
|
||||||
link: "/documents?filter=",
|
link: "/documents?filter=draft",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Sent",
|
name: "Action required",
|
||||||
stat: "0",
|
stat: "0",
|
||||||
icon: EnvelopeIcon,
|
icon: ExclamationTriangleIcon,
|
||||||
link: "/documents?filter=",
|
link: "/documents?filter=action_required",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Viewed",
|
name: "Waiting for others",
|
||||||
stat: "0",
|
stat: "0",
|
||||||
icon: EyeIcon,
|
icon: UsersIcon,
|
||||||
link: "/documents?filter=",
|
link: "/documents?filter=waiting_for_others",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Signed",
|
name: "Completed",
|
||||||
stat: "0",
|
stat: "0",
|
||||||
icon: CheckBadgeIcon,
|
icon: CheckBadgeIcon,
|
||||||
link: "/documents?filter=",
|
link: "/documents?filter=completed",
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Expired",
|
|
||||||
stat: "0",
|
|
||||||
icon: BellSnoozeIcon,
|
|
||||||
link: "/documents?filter=",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Declined",
|
|
||||||
stat: "0",
|
|
||||||
icon: XCircleIcon,
|
|
||||||
link: "/documents?filter=",
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -77,11 +61,11 @@ const DashboardPage: NextPageWithLayout = (props: any) => {
|
|||||||
Dashboard
|
Dashboard
|
||||||
</h1>
|
</h1>
|
||||||
</header>
|
</header>
|
||||||
<dl className="mt-8 grid grid-cols-1 gap-5 sm:grid-cols-3">
|
<dl className="mt-8 grid grid-cols-4 xs:grid-cols-2 gap-5">
|
||||||
{stats.map((item) => (
|
{stats.map((item) => (
|
||||||
<Link href={item.link} key={item.name}>
|
<Link href={item.link} key={item.name}>
|
||||||
<div className="overflow-hidden rounded-lg bg-white px-4 py-5 shadow sm:p-6">
|
<div className="overflow-hidden rounded-lg bg-white px-4 py-5 shadow sm:p-6 ">
|
||||||
<dt className="truncate text-sm font-medium text-gray-500">
|
<dt className="truncate text-sm font-medium text-gray-500 ">
|
||||||
<item.icon
|
<item.icon
|
||||||
className="flex-shrink-0 mr-3 h-6 w-6 inline text-neon"
|
className="flex-shrink-0 mr-3 h-6 w-6 inline text-neon"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
@ -141,9 +125,9 @@ DashboardPage.getLayout = function getLayout(page: ReactElement) {
|
|||||||
|
|
||||||
function getStat(name: string, props: any) {
|
function getStat(name: string, props: any) {
|
||||||
if (name === "Draft") return props.dashboard.drafts;
|
if (name === "Draft") return props.dashboard.drafts;
|
||||||
if (name === "Sent") return props.dashboard.sent;
|
if (name === "Action required") return props.dashboard.action;
|
||||||
if (name === "Viewed") return props.dashboard.viewed;
|
if (name === "Waiting for others") return props.dashboard.waiting;
|
||||||
if (name === "Signed") return props.dashboard.signed;
|
if (name === "Completed") return props.dashboard.completed;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,41 +138,30 @@ export async function getServerSideProps(context: any) {
|
|||||||
// todo optimize querys
|
// todo optimize querys
|
||||||
// todo no intersection groups
|
// todo no intersection groups
|
||||||
|
|
||||||
const documents: PrismaDocument[] = await getDocumentsForUserFromToken(
|
const documents: any[] = await getDocumentsForUserFromToken(context);
|
||||||
context
|
|
||||||
);
|
|
||||||
|
|
||||||
const drafts: PrismaDocument[] = documents.filter(
|
const drafts: PrismaDocument[] = documents.filter(
|
||||||
(d) => d.status === DocumentStatus.DRAFT
|
(d) => d.status === DocumentStatus.DRAFT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Todo count declined, expired etc.
|
||||||
|
const action: PrismaDocument[] = [];
|
||||||
|
|
||||||
|
const waiting: any[] = documents.filter((e) =>
|
||||||
|
e.Recipient.some((e: any) => e.sendStatus === SendStatus.SENT)
|
||||||
|
);
|
||||||
|
|
||||||
const completed: PrismaDocument[] = documents.filter(
|
const completed: PrismaDocument[] = documents.filter(
|
||||||
(d) => d.status === DocumentStatus.COMPLETED
|
(d) => d.status === DocumentStatus.COMPLETED
|
||||||
);
|
);
|
||||||
|
|
||||||
const sent = await prisma.recipient.groupBy({
|
|
||||||
by: ["documentId"],
|
|
||||||
where: {
|
|
||||||
sendStatus: SendStatus.SENT,
|
|
||||||
readStatus: ReadStatus.NOT_OPENED,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const opened = await prisma.recipient.groupBy({
|
|
||||||
by: ["documentId"],
|
|
||||||
where: {
|
|
||||||
sendStatus: SendStatus.SENT,
|
|
||||||
readStatus: ReadStatus.OPENED,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
dashboard: {
|
dashboard: {
|
||||||
drafts: drafts.length,
|
drafts: drafts.length,
|
||||||
sent: sent.length,
|
action: action.length,
|
||||||
viewed: opened.length,
|
waiting: waiting.length,
|
||||||
signed: completed.length,
|
completed: completed.length,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,15 +1,14 @@
|
|||||||
import { getUserFromToken } from "@documenso/lib/server";
|
import { getUserFromToken } from "@documenso/lib/server";
|
||||||
import prisma from "@documenso/prisma";
|
import prisma from "@documenso/prisma";
|
||||||
import { Document as PrismaDocument } from "@prisma/client";
|
|
||||||
|
|
||||||
export const getDocumentsForUserFromToken = async (
|
export const getDocumentsForUserFromToken = async (
|
||||||
context: any
|
context: any
|
||||||
): Promise<PrismaDocument[]> => {
|
): Promise<any> => {
|
||||||
const user = await getUserFromToken(context.req, context.res);
|
const user = await getUserFromToken(context.req, context.res);
|
||||||
if (!user) return Promise.reject("Invalid user or token.");
|
if (!user) return Promise.reject("Invalid user or token.");
|
||||||
|
|
||||||
// todo remove document base64 data
|
// todo remove document base64 data
|
||||||
const documents: PrismaDocument[] = await prisma.document.findMany({
|
const documents = await prisma.document.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user