Merge branch 'main' into email-view

This commit is contained in:
Dries Augustyns
2025-08-22 14:48:54 +02:00
committed by GitHub
4 changed files with 150 additions and 32 deletions
+48 -29
View File
@@ -33,8 +33,8 @@ export class ProjectService {
emails: { select: { createdAt: true } },
},
orderBy: [{ createdAt: "desc" }],
take: 20,
skip: (page - 1) * 20,
take: 100,
skip: (page - 1) * 100,
});
});
},
@@ -145,41 +145,60 @@ export class ProjectService {
const itemsPerPage = 10;
const skip = (page - 1) * itemsPerPage;
const triggers = await prisma.trigger.findMany({
where: { contact: { projectId: id } },
include: {
contact: {
select: {
id: true,
email: true,
const [triggers, emails] = await Promise.all([
prisma.trigger.findMany({
where: {
contact: {
projectId: id
}
},
select: {
id: true,
createdAt: true,
contact: {
select: {
id: true,
email: true,
},
},
event: {
select: {
name: true,
},
},
},
event: {
select: {
name: true,
orderBy: {createdAt: 'desc'},
take: itemsPerPage,
skip,
}),
prisma.email.findMany({
where: {
contact: {
projectId: id
}
},
select: {
id: true,
createdAt: true,
messageId: true,
status: true,
contact: {
select: {
id: true,
email: true,
},
},
},
},
orderBy: { createdAt: "desc" },
});
const emails = await prisma.email.findMany({
where: { contact: { projectId: id } },
include: {
contact: {
select: {
id: true,
email: true,
},
},
},
orderBy: { createdAt: "desc" },
});
orderBy: {createdAt: 'desc'},
take: itemsPerPage,
skip,
}),
]);
const combined = [...triggers, ...emails];
combined.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
return combined.slice(skip, skip + itemsPerPage);
return combined.slice(0, itemsPerPage);
}
public static usage(id: string) {
@@ -237,8 +237,8 @@ export default function Index() {
<nav className="flex items-center justify-between py-3" aria-label="Pagination">
<div className="hidden sm:block">
<p className="text-sm text-neutral-700">
Showing <span className="font-medium">{(page - 1) * 20}</span> to{" "}
<span className="font-medium">{page * 20}</span> of <span className="font-medium">{filtered.length}</span>{" "}
Showing <span className="font-medium">{(page - 1) * 100}</span> to{" "}
<span className="font-medium">{page * 100}</span> of <span className="font-medium">{contacts.count}</span>{" "}
contacts
</p>
</div>