From 82ebb805aa98980fff7bf8959e3d0a0ccf8d0ec2 Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Fri, 24 Feb 2023 10:34:01 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20=F0=9F=9A=B8=20documents?= =?UTF-8?q?=20list=20performance=20and=20empty=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/pages/documents.tsx | 322 ++++++++++++++++++----------------- 1 file changed, 166 insertions(+), 156 deletions(-) diff --git a/apps/web/pages/documents.tsx b/apps/web/pages/documents.tsx index f3fb52239..5f7a0db18 100644 --- a/apps/web/pages/documents.tsx +++ b/apps/web/pages/documents.tsx @@ -8,6 +8,7 @@ import { CheckIcon, DocumentPlusIcon, EnvelopeIcon, + FunnelIcon, PencilSquareIcon, PlusIcon, TrashIcon, @@ -23,6 +24,8 @@ import prisma from "@documenso/prisma"; const DocumentsPage: NextPageWithLayout = (props: any) => { const router = useRouter(); const [documents, setDocuments]: any[] = useState([]); + const [filterdDocuments, setFilteredDocuments] = useState([]); + const [loading, setLoading] = useState(true); const statusFilters = [ { label: "All", value: "ALL" }, @@ -70,6 +73,10 @@ const DocumentsPage: NextPageWithLayout = (props: any) => { }); }, []); + useEffect(() => { + setFilteredDocuments(filterDocumentes(documents)); + }, [selectedStatusFilter, selectedCreatedFilter]); + function showDocument(documentId: number) { router.push(`/documents/${documentId}/recipients`); } @@ -132,8 +139,8 @@ const DocumentsPage: NextPageWithLayout = (props: any) => {
- {filterDocumentes(documents).length > 1 - ? filterDocumentes(documents).length + " Documents" + {filterdDocuments.length != 1 + ? filterdDocuments.length + " Documents" : "1 Document"}
{ - {filterDocumentes(documents).map( - (document: any, index: number) => ( - showDocument(document.id)} - > - - {document.title || "#" + document.id} - - - {document.Recipient.map((item: any) => ( -
- {item.sendStatus === "NOT_SENT" ? ( + {filterdDocuments.map((document: any, index: number) => ( + showDocument(document.id)} + > + + {document.title || "#" + document.id} + + + {document.Recipient.map((item: any) => ( +
+ {item.sendStatus === "NOT_SENT" ? ( + + {item.name + ? item.name + " <" + item.email + ">" + : item.email} + + ) : ( + "" + )} + {item.sendStatus === "SENT" && + item.readStatus !== "OPENED" ? ( + + {item.name ? item.name + " <" + item.email + ">" : item.email} - ) : ( - "" - )} - {item.sendStatus === "SENT" && - item.readStatus !== "OPENED" ? ( - - - - {item.name - ? item.name + " <" + item.email + ">" - : item.email} - + + ) : ( + "" + )} + {item.readStatus === "OPENED" && + item.signingStatus === "NOT_SIGNED" ? ( + + + + + {item.name + ? item.name + " <" + item.email + ">" + : item.email} - ) : ( - "" - )} - {item.readStatus === "OPENED" && - item.signingStatus === "NOT_SIGNED" ? ( - - - - - {item.name - ? item.name + " <" + item.email + ">" - : item.email} - + + ) : ( + "" + )} + {item.signingStatus === "SIGNED" ? ( + + + {" "} + {item.email} - ) : ( - "" - )} - {item.signingStatus === "SIGNED" ? ( - - - {" "} - {item.email} - - - ) : ( - "" - )} -
- ))} - {document.Recipient.length === 0 ? "-" : null} - - - - - - {formatDocumentStatus(document.status)} -

- -

- - - {new Date(document.created).toLocaleDateString()} - - -
- { - event.preventDefault(); - event.stopPropagation(); - router.push("/documents/" + document.id); - }} - > - Edit - - { - event.preventDefault(); - event.stopPropagation(); - router.push("/api/documents/" + document.id); - }} - > - Download - - { - event.preventDefault(); - event.stopPropagation(); - if ( - confirm( - "Are you sure you want to delete this document" - ) - ) { - const documentsWithoutIndex = [ - ...documents, - ]; - const removedItem: any = - documentsWithoutIndex.splice(index, 1); - setDocuments(documentsWithoutIndex); - fetch(`/api/documents/${document.id}`, { - method: "DELETE", - }) - .catch((err) => { - documentsWithoutIndex.splice( - index, - 0, - removedItem - ); - setDocuments(documentsWithoutIndex); - }) - .then(() => { - getDocuments(); - }); - } - }} - > - , {document.name} + + ) : ( + "" + )}
- - - ) - )} + ))} + {document.Recipient.length === 0 ? "-" : null} + + + + + + {formatDocumentStatus(document.status)} +

+ +

+ + + {new Date(document.created).toLocaleDateString()} + + +
+ { + event.preventDefault(); + event.stopPropagation(); + router.push("/documents/" + document.id); + }} + > + Edit + + { + event.preventDefault(); + event.stopPropagation(); + router.push("/api/documents/" + document.id); + }} + > + Download + + { + event.preventDefault(); + event.stopPropagation(); + if ( + confirm( + "Are you sure you want to delete this document" + ) + ) { + const documentsWithoutIndex = [...documents]; + const removedItem: any = + documentsWithoutIndex.splice(index, 1); + setDocuments(documentsWithoutIndex); + fetch(`/api/documents/${document.id}`, { + method: "DELETE", + }) + .catch((err) => { + documentsWithoutIndex.splice( + index, + 0, + removedItem + ); + setDocuments(documentsWithoutIndex); + }) + .then(() => { + getDocuments(); + }); + } + }} + > + , {document.name} +
+ + + ))}
+