Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions atlas/app/admin/approvals/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
235 changes: 235 additions & 0 deletions atlas/app/admin/closeout/[token]/page.tsx
Original file line number Diff line number Diff line change
@@ -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<string, string> = {
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<Detail | null>(null);
const [err, setErr] = useState<string | null>(null);
const [keep, setKeep] = useState<string[]>([]);
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 (
<>
<PageHeader eyebrow="Pipeline" title="Close-out" />
<div className="content"><div className="card card-pad">{err} · <Link href="/admin/approvals">Back to Approvals</Link></div></div>
</>
);
}
if (!d) {
return (
<>
<PageHeader eyebrow="Pipeline" title="Close-out" />
<div className="content"><div className="card card-pad"><div className="sk" style={{ height: 14, width: "50%" }} /></div></div>
</>
);
}

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}
<PageHeader eyebrow={`Close-out · ${r.term ?? ""}`} title={d.project.title}>
<Link href={`/admin/edit/${encodeURIComponent(d.project.id)}`} className="btn-sm" style={{ textDecoration: "none" }}>Open project</Link>
</PageHeader>
<div className="content" style={{ maxWidth: 920 }}>
<p className="subcopy" style={{ marginTop: 0 }}>
Submitted by {r.from ?? "the PM"}
{r.submittedAt && ` on ${new Date(r.submittedAt).toLocaleDateString()}`}. Sign-off:{" "}
<strong>{d.leadName ?? "no lead chosen"}</strong>. Approving updates the description, tech,
topics, links, screenshots and this term&rsquo;s contributors, and marks the project complete.
Visibility is not changed.
</p>

{!pending && (
<div className="card card-pad" style={{ marginTop: 14 }}>This close-out is <strong>{r.status}</strong> — nothing to sign off.</div>
)}
{pending && !d.canApprove && (
<div className="card card-pad" style={{ marginTop: 14, color: "var(--amber-ink)" }}>
Waiting on {d.leadName ?? "the chosen program lead"}. Only they or a super admin can sign this off.
</div>
)}

{d.problems.length > 0 && (
<div className="card card-pad" style={{ marginTop: 14 }}>
<div className="lab">Checks</div>
{d.problems.map((p, i) => (
<div key={i} style={{ borderLeft: `2px solid ${SEV[p.severity]}`, paddingLeft: 10, fontSize: 13.5, margin: "6px 0" }}>
<span className="mono" style={{ fontSize: 10.5, textTransform: "uppercase", color: SEV[p.severity], marginRight: 8 }}>
{p.severity === "blocker" ? "Blocker" : "Check"}
</span>
{p.field}: {p.message}
</div>
))}
</div>
)}

<h2 className="sec-title" style={{ marginTop: 22 }}>Project fields</h2>
<div className="card card-pad">
{diff.fields.length === 0 ? (
<div className="meta">No changes to the project fields.</div>
) : (
diff.fields.map((f) => (
<div key={f.field} style={{ padding: "10px 0", borderBottom: "1px solid var(--rowsep)" }}>
<div className="lab">{LABEL[f.field] ?? f.field}</div>
<div style={{ display: "grid", gap: 6, fontSize: 14, lineHeight: 1.5 }}>
<div style={{ color: "var(--sec)", textDecoration: "line-through", whiteSpace: "pre-wrap", overflowWrap: "anywhere" }}>{show(f.before)}</div>
<div style={{ color: "var(--ink)", whiteSpace: "pre-wrap", overflowWrap: "anywhere" }}>→ {show(f.after)}</div>
</div>
</div>
))
)}
</div>

<h2 className="sec-title" style={{ marginTop: 22 }}>Contributors ({r.term})</h2>
<div className="card card-pad" style={{ fontSize: 14 }}>
{noTeamChange ? (
<div className="meta">No changes to the team.</div>
) : (
<>
{c.added.map((x, i) => <div key={`a${i}`} style={{ color: "var(--ok-ink)", padding: "3px 0" }}>+ {person(x)}</div>)}
{c.removed.map((x, i) => <div key={`r${i}`} style={{ color: "var(--danger)", padding: "3px 0" }}>− {person(x)}</div>)}
{c.changed.map((x, i) => (
<div key={`c${i}`} style={{ color: "var(--amber-ink)", padding: "3px 0" }}>
~ {person(x.before)} <span style={{ color: "var(--ink)" }}>→ {person(x.after)}</span>
</div>
))}
</>
)}
</div>

<h2 className="sec-title" style={{ marginTop: 22 }}>Screenshots</h2>
<div className="card card-pad">
{allImages.length === 0 ? (
<div className="meta">No screenshots.</div>
) : (
<>
<div className="meta" style={{ marginBottom: 10 }}>
Tick up to {CAP} to keep, in order. New uploads are marked; un-kept uploads are deleted on approve.
</div>
<div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(160px, 1fr))", gap: 12 }}>
{allImages.map((k) => {
const i = keep.indexOf(k);
return (
<label key={k} style={{ position: "relative", cursor: pending && d.canApprove ? "pointer" : "default" }}>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={keyToUrl(k)} alt="" style={{ width: "100%", aspectRatio: "4 / 3", objectFit: "cover", borderRadius: 8, opacity: i < 0 ? 0.45 : 1, display: "block" }} />
<span style={{ display: "flex", gap: 6, alignItems: "center", marginTop: 6, fontSize: 12.5 }}>
<input
type="checkbox"
disabled={!pending || !d.canApprove || (i < 0 && keep.length >= CAP)}
checked={i >= 0}
onChange={() => setKeep((ks) => (i >= 0 ? ks.filter((x) => x !== k) : [...ks, k]))}
/>
{i >= 0 ? `#${i + 1}` : "not kept"}
{r.images.includes(k) && <span className="badge badge-accent">new</span>}
</span>
</label>
);
})}
</div>
</>
)}
</div>

{pending && d.canApprove && (
<div className="card card-pad" style={{ marginTop: 22, display: "grid", gap: 14 }}>
<div>
<button className="btn btn-dark" disabled={busy || blockers.length > 0} onClick={() => act("approve")} style={{ padding: "11px 18px", fontSize: 14 }}>
{busy ? "Working…" : "Approve & update project"}
</button>
{blockers.length > 0 && <span className="meta" style={{ marginLeft: 12 }}>Blockers must be fixed — send it back.</span>}
</div>
<div>
<label className="lab" htmlFor="co-note">Send back with a note</label>
<textarea id="co-note" className="fld" rows={3} value={note} onChange={(e) => setNote(e.target.value)} placeholder="What should the PM change?" />
<button className="btn btn-ghost" style={{ marginTop: 8, padding: "10px 16px", fontSize: 14 }} disabled={busy || !note.trim()} onClick={() => act("send-back")}>
Send back to PM
</button>
</div>
</div>
)}
</div>
</>
);
}
Loading
Loading