1
0
Fork 0
polaris-task-force/src/components/frontend/promotions/PromotionsView.tsx
Z8MB1E 62573f74e6 feat(promotions): add promotion nominations and leadership transfers
- Promotion nominations: members can nominate a peer for promotion from their
  profile, and a new /personnel/promotions page lets staff review and action
  the nominations (with an optional note on each).
- Leadership transfers: a member's leadership can be handed over to another
  member, surfaced on the transfers page and in the roster (which also gains a
  staff remove-member dialog).
- Adds the PromotionNominations and LeadershipTransfers collections (registered
  in the Payload config), their service libs, the migration, and integration
  coverage.
2026-10-03 03:29:24 -04:00

142 lines
4.1 KiB
TypeScript

"use client";
import type { ReactNode } from "react";
import { ClipboardCheckIcon, FileClockIcon, GavelIcon, SendIcon } from "lucide-react";
import type { LucideIcon } from "lucide-react";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Badge } from "@/components/ui/badge";
import {
NominationCard,
type NominationCardActions,
} from "@/components/frontend/promotions/NominationCard";
import type { NominationView } from "@/components/frontend/promotions/nominationTypes";
interface PromotionsViewProps {
readonly isSuperuserViewer: boolean;
readonly isLeader: boolean;
readonly leaderQueue: readonly NominationView[];
readonly finalQueue: readonly NominationView[];
readonly mySubmissions: readonly NominationView[];
readonly recentlyResolved: readonly NominationView[];
}
function NominationSection({
icon: Icon,
title,
count,
children,
}: {
readonly icon: LucideIcon;
readonly title: string;
readonly count: number;
readonly children: ReactNode;
}) {
return (
<section aria-labelledby={`${title}-heading`} className="flex flex-col gap-3">
<div className="flex items-center gap-2">
<Icon className="size-4 text-muted-foreground" aria-hidden="true" />
<h2 id={`${title}-heading`} className="text-sm font-semibold uppercase tracking-wider">
{title}
</h2>
<Badge variant="outline" className="text-xs">
{count}
</Badge>
</div>
{children}
</section>
);
}
function EmptyNominationSection({ message }: { readonly message: string }) {
return (
<Alert>
<AlertDescription>{message}</AlertDescription>
</Alert>
);
}
function NominationGrid({
nominations,
actionFor,
}: {
readonly nominations: readonly NominationView[];
readonly actionFor: (nomination: NominationView) => NominationCardActions;
}) {
return (
<div className="grid grid-cols-1 gap-4 xl:grid-cols-2">
{nominations.map((nomination) => (
<NominationCard
key={nomination.id}
nomination={nomination}
actions={actionFor(nomination)}
/>
))}
</div>
);
}
export function PromotionsView({
isSuperuserViewer,
isLeader,
leaderQueue,
finalQueue,
mySubmissions,
recentlyResolved,
}: PromotionsViewProps) {
return (
<div className="flex flex-col gap-8">
{isLeader && (
<NominationSection
icon={ClipboardCheckIcon}
title="Awaiting your endorsement"
count={leaderQueue.length}
>
{leaderQueue.length === 0 ? (
<EmptyNominationSection message="No pending nominations need your endorsement." />
) : (
<NominationGrid nominations={leaderQueue} actionFor={() => "leader"} />
)}
</NominationSection>
)}
{isSuperuserViewer && (
<NominationSection
icon={GavelIcon}
title="Awaiting final approval"
count={finalQueue.length}
>
{finalQueue.length === 0 ? (
<EmptyNominationSection message="No nominations are awaiting a final decision." />
) : (
<NominationGrid nominations={finalQueue} actionFor={() => "final"} />
)}
</NominationSection>
)}
<NominationSection icon={SendIcon} title="My submissions" count={mySubmissions.length}>
{mySubmissions.length === 0 ? (
<EmptyNominationSection message="You have not nominated anyone for promotion yet." />
) : (
<NominationGrid
nominations={mySubmissions}
actionFor={(nomination) => (nomination.status === "pending" ? "withdraw" : "none")}
/>
)}
</NominationSection>
{(isSuperuserViewer || isLeader) && (
<NominationSection
icon={FileClockIcon}
title="Recently resolved"
count={recentlyResolved.length}
>
{recentlyResolved.length === 0 ? (
<EmptyNominationSection message="No resolved nominations to show." />
) : (
<NominationGrid nominations={recentlyResolved} actionFor={() => "none"} />
)}
</NominationSection>
)}
</div>
);
}