diff --git a/atlas/app/admin/approvals/page.tsx b/atlas/app/admin/approvals/page.tsx index fa35a3a..40d10ae 100644 --- a/atlas/app/admin/approvals/page.tsx +++ b/atlas/app/admin/approvals/page.tsx @@ -36,6 +36,12 @@ const KINDS: Record< href: () => "/admin/uploads", cta: "Review", }, + closeout: { + label: "Semester close-outs to sign off", + // ref is the token; the detail page shows old → new and who may sign off. + href: (ref) => `/admin/closeout/${encodeURIComponent(ref)}`, + cta: "Review", + }, nudge: { label: "Waiting on a PM", // ref is the project id. Not the bulk tab: it lists only image-less projects. diff --git a/atlas/app/admin/closeout/[token]/page.tsx b/atlas/app/admin/closeout/[token]/page.tsx new file mode 100644 index 0000000..43d9d4a --- /dev/null +++ b/atlas/app/admin/closeout/[token]/page.tsx @@ -0,0 +1,235 @@ +"use client"; +// Sign-off view for one PM close-out: old → new per field, contributors as +// added / removed / changed rows, screenshots to keep, and Approve / Send back. +// Only the program lead the PM chose (or a super admin) gets the buttons; everyone +// else sees it read-only with who it is waiting on. The server enforces the same. +import { use, useCallback, useEffect, useState } from "react"; +import Link from "next/link"; +import { useRouter } from "next/navigation"; +import PageHeader from "@/components/admin/PageHeader"; +import { useToast } from "@/components/admin/useToast"; +import { keyToUrl } from "@/lib/imageClient"; +import type { CloseoutContributor, CloseoutDiff, Problem } from "@/lib/closeout"; + +const CAP = 4; +const LABEL: Record = { + blurb: "Description", tech: "Tech stack", topics: "Topics", repoUrl: "Repository", prodUrl: "Live site / demo", +}; +const SEV = { blocker: "var(--danger)", warning: "var(--amber-ink)" } as const; + +interface Detail { + request: { + token: string; + status: string; + term: string | null; + submittedAt: string | null; + reviewNote: string | null; + from: string | null; + programLead: string | null; + images: string[]; + }; + project: { id: string; title: string; images: string[] }; + leadName: string | null; + canApprove: boolean; + diff: CloseoutDiff; + problems: Problem[]; +} + +const show = (v: string | string[]) => (Array.isArray(v) ? v.join(", ") : v) || "—"; +const person = (c: CloseoutContributor) => + [`${c.firstName} ${c.lastName}`.trim() || "(no name)", c.githubUsername && `@${c.githubUsername}`, c.email] + .filter(Boolean) + .join(" · "); + +export default function CloseoutReview({ params }: { params: Promise<{ token: string }> }) { + const { token } = use(params); + const router = useRouter(); + const { toastEl, notify } = useToast(); + const [d, setD] = useState(null); + const [err, setErr] = useState(null); + const [keep, setKeep] = useState([]); + const [note, setNote] = useState(""); + const [busy, setBusy] = useState(false); + + const load = useCallback(async () => { + const res = await fetch(`/api/closeout/${encodeURIComponent(token)}`); + const j = await res.json().catch(() => ({})); + if (!res.ok) return setErr(j.error || `HTTP ${res.status}`); + setD(j); + // Default: the PM's new screenshots first, then the project's current ones. + setKeep([...new Set([...j.request.images, ...j.project.images])].slice(0, CAP)); + }, [token]); + useEffect(() => { load(); }, [load]); + + const act = async (path: "approve" | "send-back") => { + setBusy(true); + try { + const res = await fetch(`/api/closeout/${encodeURIComponent(token)}/${path}`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + // submittedAt pins the version on screen: a resubmit in between makes approve fail, not apply unseen edits. + body: JSON.stringify(path === "approve" ? { images: keep, submittedAt: d?.request.submittedAt ?? null } : { note }), + }); + const j = await res.json().catch(() => ({})); + if (!res.ok) throw new Error(j.error || `HTTP ${res.status}`); + if (path === "approve") notify("ok", "Signed off — the project is updated."); + else notify(j.emailed ? "ok" : "err", j.emailed ? `Sent back to ${j.to}.` : `Reopened, but not emailed (${j.reason}). Copy the link: ${j.url}`); + router.push("/admin/approvals"); + } catch (e) { + notify("err", e instanceof Error ? e.message : "Failed."); + } finally { + setBusy(false); + } + }; + + if (err) { + return ( + <> + +
{err} · Back to Approvals
+ + ); + } + if (!d) { + return ( + <> + +
+ + ); + } + + const { request: r, diff } = d; + const blockers = d.problems.filter((p) => p.severity === "blocker"); + const pending = r.status === "submitted"; + const allImages = [...new Set([...r.images, ...d.project.images])]; + const c = diff.contributors; + const noTeamChange = !c.added.length && !c.removed.length && !c.changed.length; + + return ( + <> + {toastEl} + + Open project + +
+

+ Submitted by {r.from ?? "the PM"} + {r.submittedAt && ` on ${new Date(r.submittedAt).toLocaleDateString()}`}. Sign-off:{" "} + {d.leadName ?? "no lead chosen"}. Approving updates the description, tech, + topics, links, screenshots and this term’s contributors, and marks the project complete. + Visibility is not changed. +

+ + {!pending && ( +
This close-out is {r.status} — nothing to sign off.
+ )} + {pending && !d.canApprove && ( +
+ Waiting on {d.leadName ?? "the chosen program lead"}. Only they or a super admin can sign this off. +
+ )} + + {d.problems.length > 0 && ( +
+
Checks
+ {d.problems.map((p, i) => ( +
+ + {p.severity === "blocker" ? "Blocker" : "Check"} + + {p.field}: {p.message} +
+ ))} +
+ )} + +

Project fields

+
+ {diff.fields.length === 0 ? ( +
No changes to the project fields.
+ ) : ( + diff.fields.map((f) => ( +
+
{LABEL[f.field] ?? f.field}
+
+
{show(f.before)}
+
→ {show(f.after)}
+
+
+ )) + )} +
+ +

Contributors ({r.term})

+
+ {noTeamChange ? ( +
No changes to the team.
+ ) : ( + <> + {c.added.map((x, i) =>
+ {person(x)}
)} + {c.removed.map((x, i) =>
− {person(x)}
)} + {c.changed.map((x, i) => ( +
+ ~ {person(x.before)} → {person(x.after)} +
+ ))} + + )} +
+ +

Screenshots

+
+ {allImages.length === 0 ? ( +
No screenshots.
+ ) : ( + <> +
+ Tick up to {CAP} to keep, in order. New uploads are marked; un-kept uploads are deleted on approve. +
+
+ {allImages.map((k) => { + const i = keep.indexOf(k); + return ( + + ); + })} +
+ + )} +
+ + {pending && d.canApprove && ( +
+
+ + {blockers.length > 0 && Blockers must be fixed — send it back.} +
+
+ +