1
0
Fork 0
polaris-task-force/src/app/(frontend)/journals/page.tsx
Z8MB1E b1dbf5569c feat(journals): min in-world date 2156-03-19 and main-ops-only related mission dropdown
- Reject any journal in-world date before March 19, 2156 in the
  create/update validation (server-side) and add min to the date picker.
- Filter the related-mission dropdown to operationType = "main" only.
2026-10-13 12:13:49 -04:00

89 lines
3 KiB
TypeScript

import config from "@payload-config";
import { getPayload } from "payload";
import { headers as nextHeaders } from "next/headers";
import type { Journal, Mission, User } from "@/payload-types";
import { isPayloadUser } from "@/utils/access-control/isPayloadUser";
import { extractExcerpt } from "@/lib/journals/excerpt";
import { JournalsList, type JournalCard } from "@/components/frontend/journals/JournalsList";
import type { MissionOption } from "@/components/frontend/journals/JournalFormDialog";
export const metadata = {
title: "Journals",
};
const DATE_FORMAT = new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "long",
day: "numeric",
});
function missionLabel(mission: Mission): string {
return mission.codeName ? `${mission.codeName} · ${mission.name}` : mission.name;
}
function authorName(author: number | User): string {
if (typeof author === "number") return "Unknown operator";
return author.displayName || author.username || "Unknown operator";
}
export default async function JournalsPage() {
const payloadConfig = await config;
const payload = await getPayload({ config: payloadConfig });
const headers = await nextHeaders();
const { user } = await payload.auth({ headers, canSetHeaders: false });
if (!isPayloadUser(user)) return null;
// The collection's read access already limits non-staff to published docs
// plus their own drafts; the explicit filter keeps authors' drafts first-
// class in their list without needing a staff permission.
const journalsResult = await payload.find({
collection: "journals",
where: {
or: [{ status: { equals: "published" } }, { author: { equals: user.id } }],
},
sort: "-createdAt",
limit: 100,
depth: 1,
overrideAccess: false,
user,
});
const missionsResult = await payload.find({
collection: "missions",
// Only main operations are eligible as a journal's related mission.
where: { operationType: { equals: "main" } },
limit: 200,
depth: 0,
sort: "-id",
select: { name: true, codeName: true },
overrideAccess: false,
user,
});
const cards: JournalCard[] = (journalsResult.docs as Journal[]).map((journal) => {
const mission =
journal.mission && typeof journal.mission !== "number" ? (journal.mission as Mission) : null;
const dateSource = journal.occurredAt ?? journal.createdAt;
return {
id: journal.id,
title: journal.title,
status: journal.status,
authorName: authorName(journal.author),
dateLabel: dateSource ? DATE_FORMAT.format(new Date(dateSource)) : null,
missionLabel: mission ? missionLabel(mission) : null,
excerpt: extractExcerpt(journal.body),
};
});
const missionOptions: MissionOption[] = (missionsResult.docs as Mission[]).map((mission) => ({
id: mission.id,
label: missionLabel(mission),
}));
return (
<div className="mx-auto max-w-6xl px-4 py-10">
<JournalsList journals={cards} missions={missionOptions} />
</div>
);
}