- Add success/warning/info semantic design tokens to globals.css - Replace all raw HTML elements (input, select, textarea, button, label) with shadcn components (Input, Select, Textarea, Button, Label, Dialog) across settings, issues, agents, inbox, knowledge-base, and pair pages - Replace all hardcoded Tailwind colors with design tokens (text-red-500 → text-destructive, text-green-600 → text-success, etc.) - Extract shared ActorAvatar component to packages/ui/components/common - Update status and priority configs to use semantic tokens - Update CLAUDE.md with component organization guidelines - Fix login page tests to use label-based queries Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
172 lines
6.4 KiB
TypeScript
172 lines
6.4 KiB
TypeScript
"use client";
|
|
|
|
import Link from "next/link";
|
|
import { Suspense, useEffect, useMemo, useState } from "react";
|
|
import { useSearchParams } from "next/navigation";
|
|
import type { DaemonPairingSession } from "@multica/types";
|
|
import { Button } from "@multica/ui/components/ui/button";
|
|
import { Label } from "@multica/ui/components/ui/label";
|
|
import {
|
|
Select,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
SelectContent,
|
|
SelectItem,
|
|
} from "@multica/ui/components/ui/select";
|
|
import { api } from "../../../lib/api";
|
|
import { useAuth } from "../../../lib/auth-context";
|
|
|
|
function formatExpiresAt(value: string) {
|
|
return new Date(value).toLocaleString("en-US", {
|
|
month: "short",
|
|
day: "numeric",
|
|
hour: "numeric",
|
|
minute: "2-digit",
|
|
});
|
|
}
|
|
|
|
function LocalDaemonPairPageContent() {
|
|
const searchParams = useSearchParams();
|
|
const token = searchParams.get("token") ?? "";
|
|
const { user, workspaces, workspace, isLoading } = useAuth();
|
|
const [session, setSession] = useState<DaemonPairingSession | null>(null);
|
|
const [selectedWorkspaceId, setSelectedWorkspaceId] = useState("");
|
|
const [loading, setLoading] = useState(true);
|
|
const [submitting, setSubmitting] = useState(false);
|
|
const [error, setError] = useState("");
|
|
|
|
const nextLoginURL = useMemo(() => {
|
|
const next = `/pair/local?token=${encodeURIComponent(token)}`;
|
|
return `/login?next=${encodeURIComponent(next)}`;
|
|
}, [token]);
|
|
|
|
useEffect(() => {
|
|
if (!token) {
|
|
setError("Missing pairing token.");
|
|
setLoading(false);
|
|
return;
|
|
}
|
|
|
|
setLoading(true);
|
|
api.getDaemonPairingSession(token)
|
|
.then((value) => {
|
|
setSession(value);
|
|
setSelectedWorkspaceId(value.workspace_id || workspace?.id || workspaces[0]?.id || "");
|
|
})
|
|
.catch((err) => setError(err instanceof Error ? err.message : "Failed to load pairing session."))
|
|
.finally(() => setLoading(false));
|
|
}, [token, workspace?.id, workspaces]);
|
|
|
|
const approve = async () => {
|
|
if (!token || !selectedWorkspaceId) return;
|
|
setSubmitting(true);
|
|
setError("");
|
|
try {
|
|
const approved = await api.approveDaemonPairingSession(token, {
|
|
workspace_id: selectedWorkspaceId,
|
|
});
|
|
setSession(approved);
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : "Failed to approve pairing session.");
|
|
} finally {
|
|
setSubmitting(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center bg-canvas px-6 py-12">
|
|
<div className="w-full max-w-xl rounded-2xl border bg-background p-8 shadow-sm">
|
|
<div>
|
|
<h1 className="text-2xl font-semibold">Connect Local Codex Runtime</h1>
|
|
<p className="mt-2 text-sm text-muted-foreground">
|
|
Approve this pairing request to register your local Codex runtime with a workspace.
|
|
</p>
|
|
</div>
|
|
|
|
{loading || isLoading ? (
|
|
<div className="mt-8 text-sm text-muted-foreground">Loading pairing session...</div>
|
|
) : error ? (
|
|
<div className="mt-8 rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive">
|
|
{error}
|
|
</div>
|
|
) : session ? (
|
|
<>
|
|
<div className="mt-6 rounded-xl border bg-muted/30 p-4">
|
|
<div className="text-sm font-medium">{session.runtime_name}</div>
|
|
<div className="mt-1 text-sm text-muted-foreground">
|
|
{session.device_name}
|
|
{session.runtime_version ? ` · ${session.runtime_version}` : ""}
|
|
</div>
|
|
<div className="mt-1 text-xs uppercase tracking-wide text-muted-foreground">
|
|
{session.runtime_type}
|
|
</div>
|
|
<div className="mt-3 text-xs text-muted-foreground">
|
|
Expires {formatExpiresAt(session.expires_at)}
|
|
</div>
|
|
</div>
|
|
|
|
{!user ? (
|
|
<div className="mt-6 space-y-3">
|
|
<p className="text-sm text-muted-foreground">
|
|
Sign in first, then choose which workspace should own this local runtime.
|
|
</p>
|
|
<Link
|
|
href={nextLoginURL}
|
|
className="inline-flex rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90"
|
|
>
|
|
Sign in to continue
|
|
</Link>
|
|
</div>
|
|
) : session.status === "approved" || session.status === "claimed" ? (
|
|
<div className="mt-6 rounded-xl border border-success/30 bg-success/5 px-4 py-3 text-sm text-success">
|
|
This runtime is linked to a workspace. Return to the daemon window to finish setup.
|
|
</div>
|
|
) : session.status === "expired" ? (
|
|
<div className="mt-6 rounded-xl border border-warning/30 bg-warning/5 px-4 py-3 text-sm text-warning">
|
|
This pairing link expired. Restart the daemon to generate a new link.
|
|
</div>
|
|
) : workspaces.length === 0 ? (
|
|
<div className="mt-6 rounded-xl border px-4 py-3 text-sm text-muted-foreground">
|
|
You do not have a workspace yet. Create one first, then reopen this pairing link.
|
|
</div>
|
|
) : (
|
|
<div className="mt-6 space-y-4">
|
|
<div>
|
|
<Label className="mb-2">Workspace</Label>
|
|
<Select value={selectedWorkspaceId} onValueChange={(v) => setSelectedWorkspaceId(v ?? "")}>
|
|
<SelectTrigger className="w-full">
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{workspaces.map((item) => (
|
|
<SelectItem key={item.id} value={item.id}>
|
|
{item.name}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
|
|
<Button
|
|
type="button"
|
|
onClick={approve}
|
|
disabled={submitting || !selectedWorkspaceId}
|
|
>
|
|
{submitting ? "Registering..." : "Register runtime"}
|
|
</Button>
|
|
</div>
|
|
)}
|
|
</>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function LocalDaemonPairPage() {
|
|
return (
|
|
<Suspense fallback={null}>
|
|
<LocalDaemonPairPageContent />
|
|
</Suspense>
|
|
);
|
|
}
|