Intelligence
Artifacts
Browse the repository, read documents, and manage the governance folders. Source, runtime, and infrastructure are read-only.
Repository
assignment-dispatch-button.tsxassignment-status-badge.tsxassignments-panel.tsxcreate-mission-form.tsxgovernance-panels.tsxmission-dispatch.tsxmission-edit.tsxmission-state-actions.tsxmission-status-badge.tsxobjective-edit.tsxobjective-status-badge.tsxobjective-status-select.tsxobjectives-panel.tsxreport-list.tsxwork-orders-panel.tsx
README.md
CONSTITUTION_COMPLIANCE_AUDIT_V1.mdREADME.md
repositories/aaf-holdings/hq01/components/missions/objectives-panel.tsx
7.7 KB
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import Link from "next/link";
import { Plus, X, Loader2, Target, ArrowRight } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Card } from "@/components/ui/card";
import { PriorityBadge } from "@/components/shared/status-badge";
import { ObjectiveStatusSelect } from "./objective-status-select";
import type { OwnerOption } from "./create-mission-form";
import type {
MissionPriority,
MissionProgress,
Objective,
} from "@/lib/missions/types";
const PRIORITIES: MissionPriority[] = ["P0", "P1", "P2", "P3"];
/**
* Objectives section on a mission: mission progress, create objective, and the
* objective list with inline status control. Objectives do not dispatch — they
* organize future execution and gate mission completion.
*/
export function ObjectivesPanel({
missionId,
objectives,
progress,
owners,
}: {
missionId: string;
objectives: Objective[];
progress: MissionProgress;
owners: OwnerOption[];
}) {
const router = useRouter();
const [open, setOpen] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const firstActive = owners.find((o) => o.active)?.id ?? owners[0]?.id ?? "";
const [form, setForm] = useState({
title: "",
description: "",
owner_executive: firstActive,
priority: "P2" as MissionPriority,
success_criteria: "",
});
async function create(e: React.FormEvent) {
e.preventDefault();
setBusy(true);
setError(null);
try {
const res = await fetch(`/api/missions/${missionId}/objectives`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
...form,
success_criteria: form.success_criteria
.split("\n")
.map((s) => s.trim())
.filter(Boolean),
}),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(data.error ?? "Could not create objective.");
setForm({ ...form, title: "", description: "", success_criteria: "" });
setOpen(false);
router.refresh();
} catch (err) {
setError(err instanceof Error ? err.message : "Could not create objective.");
} finally {
setBusy(false);
}
}
return (
<Card className="p-6">
<div className="mb-4 flex flex-wrap items-center justify-between gap-3">
<div className="flex items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.1em] text-muted-foreground">
<Target className="h-3.5 w-3.5" /> Objectives
</div>
<Button type="button" size="sm" variant="outline" onClick={() => setOpen((v) => !v)}>
{open ? <X className="h-3.5 w-3.5" /> : <Plus className="h-3.5 w-3.5" />}
{open ? "Close" : "Create Objective"}
</Button>
</div>
{/* Mission progress */}
<div className="mb-5">
<div className="mb-1.5 flex items-center justify-between text-[13px]">
<span className="font-medium text-foreground">Mission Progress</span>
<span className="tabular-nums text-muted-foreground">
{progress.completed} / {progress.total} · {progress.percentage}%
</span>
</div>
<div className="h-2 w-full overflow-hidden rounded-full bg-secondary">
<div
className="h-full rounded-full bg-emerald-500 transition-all"
style={{ width: `${progress.percentage}%` }}
/>
</div>
</div>
{open && (
<form onSubmit={create} className="mb-5 space-y-3 rounded-md border border-border p-4">
<Input
value={form.title}
onChange={(e) => setForm({ ...form, title: e.target.value })}
placeholder="Objective title"
required
/>
<textarea
value={form.description}
onChange={(e) => setForm({ ...form, description: e.target.value })}
placeholder="What measurable outcome must become true?"
rows={2}
required
className="flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
/>
<textarea
value={form.success_criteria}
onChange={(e) => setForm({ ...form, success_criteria: e.target.value })}
placeholder="Success criteria (one per line)"
rows={2}
className="flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
/>
<div className="flex flex-wrap items-end gap-3">
<label className="flex-1">
<span className="mb-1 block text-[11px] font-semibold uppercase tracking-[0.08em] text-muted-foreground">
Owner
</span>
<select
value={form.owner_executive}
onChange={(e) => setForm({ ...form, owner_executive: e.target.value })}
className="h-9 w-full rounded-md border border-input bg-background px-2 text-sm"
>
{owners.map((o) => (
<option key={o.id} value={o.id}>
{o.label}
</option>
))}
</select>
</label>
<label>
<span className="mb-1 block text-[11px] font-semibold uppercase tracking-[0.08em] text-muted-foreground">
Priority
</span>
<select
value={form.priority}
onChange={(e) => setForm({ ...form, priority: e.target.value as MissionPriority })}
className="h-9 rounded-md border border-input bg-background px-2 text-sm"
>
{PRIORITIES.map((p) => (
<option key={p}>{p}</option>
))}
</select>
</label>
<Button type="submit" size="sm" disabled={busy}>
{busy ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : "Create"}
</Button>
</div>
{error && <p className="text-[12px] text-destructive">{error}</p>}
</form>
)}
{objectives.length === 0 ? (
<p className="text-sm text-muted-foreground">
No objectives yet. Mission completion requires every objective to be
Completed.
</p>
) : (
<ul className="divide-y divide-border">
{objectives.map((o) => (
<li key={o.id} className="flex flex-wrap items-center gap-3 py-2.5">
<div className="min-w-0 flex-1">
<Link
href={`/mission-control/${missionId}/objectives/${o.id}`}
className="inline-flex items-center gap-1.5 text-[14px] font-medium text-foreground hover:underline"
>
<span className="font-mono text-[11px] text-muted-foreground">
{o.id.replace("OBJECTIVE-", "O-")}
</span>
{o.title}
<ArrowRight className="h-3 w-3 text-muted-foreground/50" />
</Link>
<div className="mt-0.5 text-[12px] text-muted-foreground">
<span className="font-mono">{o.owner_executive ?? "—"}</span> ·{" "}
{o.completion_percentage}%
</div>
</div>
<PriorityBadge priority={o.priority} />
<ObjectiveStatusSelect missionId={missionId} oid={o.id} status={o.status} />
</li>
))}
</ul>
)}
</Card>
);
}
root · /srv/aaf