The TacticalFrame header (icon + 'OPERATION // Topic') now owns each card's heading; the duplicate per-component content titles are removed across Rating, Mission Details, Briefing (SQF export retained), Objectives, Factions, Roles (Max Players stat retained), Comms, Logistics, and Role Sign-Ups (queue note retained). The Command Chain title removal is left in the working tree, on top of the separate collapsible-panel work-in-progress in MissionCommandChainEditor.tsx. Cleans up the now-unused ClipboardListIcon import and a dangling aria-labelledby reference left by the removed Rating heading.
248 lines
9.4 KiB
TypeScript
248 lines
9.4 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { UserCheckIcon, UserPlusIcon, UsersIcon, XIcon } from "lucide-react";
|
|
import { Item, ItemContent, ItemHeader, ItemTitle } from "@/components/ui/item";
|
|
import { Button } from "@/components/ui/button";
|
|
import { cn } from "@/lib/utils";
|
|
import {
|
|
RoleDescription,
|
|
type RoleDescriptionData,
|
|
} from "@/components/frontend/intelligence/RoleDescription";
|
|
import {
|
|
removeMissionRoleSignup,
|
|
signupForMissionRole,
|
|
withdrawMissionRoleSignup,
|
|
type ActionResult,
|
|
} from "@/app/(frontend)/intelligence/missions/actions";
|
|
|
|
interface SignupPersonView {
|
|
signupId: number;
|
|
userId: number;
|
|
name: string;
|
|
holding: boolean;
|
|
position: number;
|
|
}
|
|
|
|
interface SignupRoleView {
|
|
roleIndex: number;
|
|
roleName: string;
|
|
description?: RoleDescriptionData;
|
|
missionCritical: boolean;
|
|
slots: number;
|
|
filled: number;
|
|
entries: SignupPersonView[];
|
|
eligibility: { eligible: boolean; reasons: string[] } | null;
|
|
}
|
|
|
|
interface MissionRoleSignupsProps {
|
|
missionId: number;
|
|
currentUserId: number | null;
|
|
closed: boolean;
|
|
closedReason?: string | null;
|
|
roles: SignupRoleView[];
|
|
mySignup: { roleIndex: number; holding: boolean; position: number } | null;
|
|
canManage: boolean;
|
|
}
|
|
|
|
export function MissionRoleSignups({
|
|
missionId,
|
|
currentUserId,
|
|
closed,
|
|
closedReason,
|
|
roles,
|
|
mySignup,
|
|
canManage,
|
|
}: MissionRoleSignupsProps) {
|
|
const router = useRouter();
|
|
const [pending, setPending] = useState<string | null>(null);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
if (roles.length === 0) return null;
|
|
|
|
async function run(key: string, action: () => Promise<ActionResult>) {
|
|
setPending(key);
|
|
setError(null);
|
|
const res = await action();
|
|
if (!res.success) {
|
|
setError(res.error ?? "Something went wrong.");
|
|
}
|
|
setPending(null);
|
|
router.refresh();
|
|
}
|
|
|
|
const signup = (role: SignupRoleView) =>
|
|
run(`signup:${role.roleIndex}`, () =>
|
|
signupForMissionRole({ missionId, roleIndex: role.roleIndex }),
|
|
);
|
|
const withdraw = () => run("withdraw", () => withdrawMissionRoleSignup({ missionId }));
|
|
const remove = (signupId: number) =>
|
|
run(`remove:${signupId}`, () => removeMissionRoleSignup({ missionId, signupId }));
|
|
|
|
return (
|
|
<Item variant="outline">
|
|
<ItemHeader>
|
|
<span className="text-[10px] font-semibold uppercase tracking-wider text-muted-foreground">
|
|
First come, first served
|
|
</span>
|
|
</ItemHeader>
|
|
<ItemContent className="flex flex-col gap-3">
|
|
{closed && closedReason && <p className="text-xs text-muted-foreground">{closedReason}</p>}
|
|
{!currentUserId && (
|
|
<p className="text-xs text-muted-foreground">Log in to sign up for a role.</p>
|
|
)}
|
|
{error && <p className="text-xs text-red-400">{error}</p>}
|
|
|
|
{roles.map((role) => {
|
|
const holders = role.entries.filter((e) => e.holding);
|
|
const waitlist = role.entries.filter((e) => !e.holding);
|
|
const isMine = mySignup?.roleIndex === role.roleIndex;
|
|
const openSlots = Math.max(0, role.slots - role.filled);
|
|
const eligible = role.eligibility?.eligible ?? true;
|
|
const reasons = role.eligibility?.reasons ?? [];
|
|
|
|
return (
|
|
<div
|
|
key={role.roleIndex}
|
|
className={cn(
|
|
"rounded-md border p-3 flex flex-col gap-2",
|
|
isMine ? "border-primary/40" : "border-border/60",
|
|
)}
|
|
>
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<span className="text-sm font-medium">{role.roleName}</span>
|
|
{role.missionCritical && (
|
|
<span className="rounded-sm bg-red-500/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-red-400">
|
|
Critical
|
|
</span>
|
|
)}
|
|
<span className="ml-auto font-mono text-xs text-muted-foreground">
|
|
{role.filled}/{role.slots}
|
|
</span>
|
|
</div>
|
|
{role.description && <RoleDescription description={role.description} />}
|
|
|
|
<div className="flex flex-col gap-1">
|
|
<div className="flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider">
|
|
<UserCheckIcon className="size-3.5 text-emerald-400" />
|
|
<span className="text-emerald-400">Slots</span>
|
|
{openSlots > 0 && (
|
|
<span className="font-mono text-amber-400">({openSlots} open)</span>
|
|
)}
|
|
</div>
|
|
{holders.length > 0 ? (
|
|
<ul className="flex flex-wrap gap-x-3 gap-y-0.5">
|
|
{holders.map((person) => (
|
|
<li
|
|
key={person.signupId}
|
|
className={cn(
|
|
"flex items-center gap-1 text-sm",
|
|
person.userId === currentUserId
|
|
? "text-foreground font-medium"
|
|
: "text-muted-foreground",
|
|
)}
|
|
>
|
|
{person.name}
|
|
{canManage && person.userId !== currentUserId && (
|
|
<button
|
|
type="button"
|
|
title="Remove sign-up"
|
|
disabled={pending !== null}
|
|
onClick={() => void remove(person.signupId)}
|
|
className="text-muted-foreground/50 transition-colors hover:text-red-400 disabled:opacity-50"
|
|
>
|
|
<XIcon className="size-3" />
|
|
</button>
|
|
)}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
) : (
|
|
<p className="text-sm text-muted-foreground italic">Unfilled.</p>
|
|
)}
|
|
</div>
|
|
|
|
{waitlist.length > 0 && (
|
|
<div className="flex flex-col gap-1">
|
|
<div className="flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider">
|
|
<UsersIcon className="size-3.5 text-muted-foreground" />
|
|
<span className="text-muted-foreground">Waitlist</span>
|
|
<span className="font-mono text-muted-foreground">({waitlist.length})</span>
|
|
</div>
|
|
<ul className="flex flex-wrap gap-x-3 gap-y-0.5">
|
|
{waitlist.map((person) => (
|
|
<li key={person.signupId} className="flex items-center gap-1 text-sm">
|
|
<span className="font-mono text-xs text-muted-foreground">
|
|
{person.position}.
|
|
</span>
|
|
<span
|
|
className={cn(
|
|
person.userId === currentUserId
|
|
? "text-foreground font-medium"
|
|
: "text-muted-foreground",
|
|
)}
|
|
>
|
|
{person.name}
|
|
</span>
|
|
{canManage && (
|
|
<button
|
|
type="button"
|
|
title="Remove sign-up"
|
|
disabled={pending !== null}
|
|
onClick={() => void remove(person.signupId)}
|
|
className="text-muted-foreground/50 transition-colors hover:text-red-400 disabled:opacity-50"
|
|
>
|
|
<XIcon className="size-3" />
|
|
</button>
|
|
)}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
)}
|
|
|
|
{isMine && (
|
|
<p className="text-xs text-muted-foreground">
|
|
{mySignup?.holding
|
|
? "You hold a slot for this role."
|
|
: `You are waitlisted (#${mySignup?.position}).`}
|
|
</p>
|
|
)}
|
|
{currentUserId !== null && !closed && !eligible && !isMine && reasons.length > 0 && (
|
|
<p className="text-xs text-red-400">{reasons.join(" ")}</p>
|
|
)}
|
|
|
|
{currentUserId !== null && !closed && (
|
|
<div className="flex items-center gap-2">
|
|
{isMine ? (
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
disabled={pending !== null}
|
|
onClick={() => void withdraw()}
|
|
>
|
|
<XIcon className="size-3.5" />
|
|
Withdraw
|
|
</Button>
|
|
) : (
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
disabled={pending !== null || !eligible}
|
|
title={eligible ? undefined : reasons.join(" ")}
|
|
onClick={() => void signup(role)}
|
|
>
|
|
<UserPlusIcon className="size-3.5" />
|
|
{mySignup ? "Switch to this role" : "Sign up"}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
})}
|
|
</ItemContent>
|
|
</Item>
|
|
);
|
|
}
|