1
0
Fork 0
polaris-task-force/src/app/(frontend)/projects/[key]/releases/page.tsx
Z8MB1E e0f305b026 feat(tickets): allow staff to archive tickets, hiding them from the front-end
Archived tickets disappear from every front-end surface for all users
(staff included): helpdesk list, detail page 404s, dashboard widget, and
project board/sprints/releases/search views. They remain fully visible in
the Payload admin panel, where un-archiving restores them. The collection
hook stamps archivedAt and appends an activity entry on each toggle; the
archiveTicket server action is tickets:staff gated and emits a
ticket:archive event. Edits and votes on archived tickets are rejected.
2026-10-07 01:22:51 -04:00

100 lines
2.9 KiB
TypeScript

import config from "@payload-config";
import { headers as nextHeaders } from "next/headers";
import { notFound, redirect } from "next/navigation";
import { getPayload } from "payload";
import { ReleasesView } from "@/components/frontend/projects/ReleasesView";
import { hasPermission } from "@/utils/access-control/hasPermission";
import { richTextToPlaintext } from "@/lib/projects/projectMeta";
import { NON_ARCHIVED_WHERE } from "@/lib/tickets/ticketMeta";
export const metadata = {
title: "Releases: Polaris Task Force",
};
export default async function ReleasesPage({ params }: { params: Promise<{ key: string }> }) {
const { key } = await params;
const headers = await nextHeaders();
const payload = await getPayload({ config });
const { user } = await payload.auth({ headers, canSetHeaders: false });
if (!user) {
redirect(`/login?returnTo=/projects/${key}/releases`);
}
const projectResult = await payload.find({
collection: "projects" as any,
where: { key: { equals: key.toUpperCase() } },
limit: 1,
depth: 0,
overrideAccess: true,
});
if (projectResult.docs.length === 0) {
notFound();
}
const project = projectResult.docs[0] as any;
const canManage = await hasPermission(payload, user, "releases:update");
const canCreate = await hasPermission(payload, user, "releases:create");
const [releaseResult, ticketResult] = await Promise.all([
payload.find({
collection: "releases" as any,
where: { project: { equals: project.id } },
sort: "-releaseDate",
depth: 0,
limit: 100,
overrideAccess: true,
}),
payload.find({
collection: "tickets" as any,
where: { and: [{ project: { equals: project.id } }, NON_ARCHIVED_WHERE] },
depth: 0,
limit: 500,
overrideAccess: true,
}),
]);
const tickets = ticketResult.docs as any[];
const releases = releaseResult.docs.map((r: any) => {
const releaseTickets = tickets.filter((ticket: any) => {
const releaseId =
typeof ticket.release === "object" && ticket.release !== null
? ticket.release.id
: ticket.release;
return releaseId === r.id;
});
const ticketsTotal = releaseTickets.length;
const ticketsResolved = releaseTickets.filter(
(ticket: any) => ticket.status === "resolved",
).length;
return {
id: r.id,
name: r.name,
status: r.status,
targetVersion: r.targetVersion,
releaseDate: r.releaseDate,
description: richTextToPlaintext(r.description) || null,
createdAt: r.createdAt,
ticketsTotal,
ticketsResolved,
};
});
return (
<div className="flex flex-col gap-6 p-5">
<ReleasesView
project={{
id: project.id,
name: project.name,
key: project.key,
}}
releases={releases}
isAdmin={canManage || canCreate}
/>
</div>
);
}