Give finished Rules a print path, folded launch counts, and a two-day follow-up.
Export is PDF, RULE.md, and Print on US Letter, with every shared term, no member names, and a takeaway that points at Ask an organizer. Finished Rules keep type and place so the team can read folded counts without a database, Umami can sit beside the app with no cookies, and the person who holds the pen gets working PDF and RULE.md links 48 hours later.
This commit is contained in:
1 parent
0efc907633
commit
d9c475a967
74 files changed
+2401
-630
No files matched your search
@@ -0,0 +1,114 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import messages from "../../../messages/en/index";
|
||||
import communityStructure from "../../../messages/en/create/community/communityStructure.json";
|
||||
import { routeMetadata } from "../../../lib/siteMetadata";
|
||||
import { getRuleAdminEmails, isDatabaseConfigured } from "../../../lib/server/env";
|
||||
import { prisma } from "../../../lib/server/db";
|
||||
import { isRuleAdminEmail } from "../../../lib/server/ruleAdmins";
|
||||
import { aggregateRuleLaunchCounts } from "../../../lib/server/ruleLaunchCounts";
|
||||
import { getSessionUser } from "../../../lib/server/session";
|
||||
|
||||
export const metadata: Metadata = routeMetadata("/rule-counts", {
|
||||
title: messages.metadata.ruleCounts.title,
|
||||
robots: { index: false, follow: false },
|
||||
});
|
||||
|
||||
const ORG_LABELS = Object.fromEntries(
|
||||
communityStructure.organizationTypes.map((row) => [row.id, row.label]),
|
||||
);
|
||||
|
||||
function typeLabel(orgType: string | null, folded: boolean, copy: typeof messages.pages.ruleCounts): string {
|
||||
if (folded) return copy.folded;
|
||||
if (!orgType) return copy.notGiven;
|
||||
return ORG_LABELS[orgType] ?? orgType;
|
||||
}
|
||||
|
||||
function placeLabel(place: string | null, folded: boolean, copy: typeof messages.pages.ruleCounts): string {
|
||||
if (folded) return copy.folded;
|
||||
if (!place) return copy.notGiven;
|
||||
return place;
|
||||
}
|
||||
|
||||
export default async function RuleCountsPage() {
|
||||
if (getRuleAdminEmails().length === 0) notFound();
|
||||
|
||||
const copy = messages.pages.ruleCounts;
|
||||
const user = await getSessionUser();
|
||||
if (!user) {
|
||||
return (
|
||||
<section className="mx-auto flex w-full max-w-md flex-col gap-4 px-6 py-16">
|
||||
<h1 className="x-large-heading text-[var(--color-content-default-primary)]">
|
||||
{copy.title}
|
||||
</h1>
|
||||
<p className="medium-paragraph">{copy.signIn}</p>
|
||||
<Link href="/login?next=/rule-counts" className="medium-label underline">
|
||||
{copy.signInButton}
|
||||
</Link>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
if (!isRuleAdminEmail(user.email)) {
|
||||
return (
|
||||
<section className="mx-auto flex w-full max-w-md flex-col gap-4 px-6 py-16">
|
||||
<h1 className="x-large-heading text-[var(--color-content-default-primary)]">
|
||||
{copy.title}
|
||||
</h1>
|
||||
<p className="medium-paragraph">{copy.forbidden}</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
const rows = isDatabaseConfigured()
|
||||
? await prisma.publishedRule.findMany({
|
||||
select: { orgType: true, communityLocation: true },
|
||||
})
|
||||
: [];
|
||||
const counts = aggregateRuleLaunchCounts(
|
||||
rows.map((row) => ({
|
||||
orgType: row.orgType,
|
||||
place: row.communityLocation,
|
||||
})),
|
||||
);
|
||||
|
||||
return (
|
||||
<section className="mx-auto flex w-full max-w-4xl flex-col gap-6 px-6 py-12">
|
||||
<h1 className="x-large-heading text-[var(--color-content-default-primary)]">
|
||||
{copy.title}
|
||||
</h1>
|
||||
<p className="medium-paragraph">{copy.intro}</p>
|
||||
<p className="large-label">
|
||||
{copy.finished}: {counts.finished}
|
||||
</p>
|
||||
{counts.cells.length === 0 ? (
|
||||
<p className="medium-paragraph">{copy.empty}</p>
|
||||
) : (
|
||||
<table className="w-full border-collapse text-left">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="medium-label py-2">{copy.columns.type}</th>
|
||||
<th className="medium-label py-2">{copy.columns.place}</th>
|
||||
<th className="medium-label py-2">{copy.columns.count}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{counts.cells.map((cell) => (
|
||||
<tr
|
||||
key={`${cell.folded ? "folded" : "open"}:${cell.orgType ?? ""}:${cell.place ?? ""}`}
|
||||
>
|
||||
<td className="small-paragraph py-2">
|
||||
{typeLabel(cell.orgType, cell.folded, copy)}
|
||||
</td>
|
||||
<td className="small-paragraph py-2">
|
||||
{placeLabel(cell.place, cell.folded, copy)}
|
||||
</td>
|
||||
<td className="small-paragraph py-2">{cell.count}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user