Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: add lastUpdatedAt for dataroom and latest document

Marc Seitzae44faad2422
diff --git a/components/view/dataroom/nav-dataroom.tsx b/components/view/dataroom/nav-dataroom.tsx
index c1988fa9..46c101db 100644
--- a/components/view/dataroom/nav-dataroom.tsx
+++ b/components/view/dataroom/nav-dataroom.tsx
@@ -6,7 +6,7 @@ import { DataroomBrand } from "@prisma/client";
import { Download, MessagesSquareIcon } from "lucide-react";
import { toast } from "sonner";
-import { timeAgo } from "@/lib/utils";
+import { formatDate } from "@/lib/utils";
import {
Tooltip,
@@ -198,7 +198,7 @@ export default function DataroomNav({
className="text-sm"
dateTime={new Date(dataroom.lastUpdatedAt).toISOString()}
>
- {`Last updated ${timeAgo(dataroom.lastUpdatedAt)}`}
+ {`Last updated ${formatDate(dataroom.lastUpdatedAt)}`}
</time>
</div>
</div>
diff --git a/lib/types.ts b/lib/types.ts
index 4f6a721d..a4a3753a 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -126,6 +126,7 @@ export interface LinkWithDataroom extends Link {
documents: {
id: string;
folderId: string | null;
+ updatedAt: Date;
orderIndex: number | null;
document: {
id: string;
diff --git a/pages/view/[linkId]/index.tsx b/pages/view/[linkId]/index.tsx
index 17e2f05a..88ce892c 100644
--- a/pages/view/[linkId]/index.tsx
+++ b/pages/view/[linkId]/index.tsx
@@ -155,7 +155,7 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
// iterate the link.documents and extract type and file and rest of the props
let documents = [];
for (const document of link.dataroom.documents) {
- const { file, ...versionWithoutTypeAndFile } =
+ const { file, updatedAt, ...versionWithoutTypeAndFile } =
document.document.versions[0];
const newDocument = {
@@ -163,7 +163,13 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
dataroomDocumentId: document.id,
folderId: document.folderId,
orderIndex: document.orderIndex,
- versions: [versionWithoutTypeAndFile],
+ versions: [
+ {
+ ...versionWithoutTypeAndFile,
+ updatedAt:
+ document.updatedAt > updatedAt ? document.updatedAt : updatedAt, // use the latest updatedAt
+ },
+ ],
};
documents.push(newDocument);
@@ -171,6 +177,13 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
const { teamId } = link.dataroom;
+ const lastUpdatedAt = link.dataroom.documents.reduce((max, doc) => {
+ return Math.max(
+ max,
+ new Date(doc.document.versions[0].updatedAt).getTime(),
+ );
+ }, 0);
+
return {
props: {
linkData: {
@@ -180,7 +193,7 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
dataroom: {
...link.dataroom,
documents,
- lastUpdatedAt: null, // TODO: fix this to get the actual lastUpdatedAt
+ lastUpdatedAt: lastUpdatedAt,
},
},
brand,
diff --git a/pages/view/domains/[domain]/[slug]/index.tsx b/pages/view/domains/[domain]/[slug]/index.tsx
index 3dc753f4..d75cc8ca 100644
--- a/pages/view/domains/[domain]/[slug]/index.tsx
+++ b/pages/view/domains/[domain]/[slug]/index.tsx
@@ -128,7 +128,7 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
// iterate the link.documents and extract type and file and rest of the props
let documents = [];
for (const document of link.dataroom.documents) {
- const { file, ...versionWithoutTypeAndFile } =
+ const { file, updatedAt, ...versionWithoutTypeAndFile } =
document.document.versions[0];
const newDocument = {
@@ -136,7 +136,13 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
dataroomDocumentId: document.id,
folderId: document.folderId,
orderIndex: document.orderIndex,
- versions: [versionWithoutTypeAndFile],
+ versions: [
+ {
+ ...versionWithoutTypeAndFile,
+ updatedAt:
+ document.updatedAt > updatedAt ? document.updatedAt : updatedAt, // use the latest updatedAt
+ },
+ ],
};
documents.push(newDocument);
@@ -144,6 +150,13 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
const { teamId } = link.dataroom;
+ const lastUpdatedAt = link.dataroom.documents.reduce((max, doc) => {
+ return Math.max(
+ max,
+ new Date(doc.document.versions[0].updatedAt).getTime(),
+ );
+ }, 0);
+
return {
props: {
linkData: {
@@ -153,7 +166,7 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
dataroom: {
...link.dataroom,
documents,
- lastUpdatedAt: null, // TODO: fix this to get the actual lastUpdatedAt
+ lastUpdatedAt: lastUpdatedAt,
},
},
brand,