UI_REDESIGN chunk 4 was never finished: 39 app/component files still used raw Tailwind greys, kept readable in light mode only by the !important override sheet. In dark mode text-gray-600 is ~2.3:1 on surface, and the light override maps it to #94a3b8 (~2.6:1 on white) — unreadable in both. Mechanical mapping (886 classes): gray-100/200 -> ink, 300/400 -> ink-2, 500/600/700 -> ink-muted, bg 950/900/800 -> page/surface/raised, border 800 -> line, 700/600 -> line-strong, plus hover/divide/placeholder. Alpha suffixes kept (tokens are color-mix, so /60 works). bg-gray-700, text-white and marketing pages left alone. text-[9px] -> text-[10px]. Frontend unverified: no Node on the authoring box (#207). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
3.2 KiB
TypeScript
88 lines
3.2 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useAuth } from "@/components/AuthProvider";
|
|
import { c2api } from "@/lib/c2api";
|
|
import { Button } from "@/components/ui/Button";
|
|
|
|
/**
|
|
* Shown to any signed-in user with no org_id claim — see ChromeSwitcher's
|
|
* no-claim guard (SAAS_PLAN.md B3). Two ways to land here:
|
|
* 1. Just created an account via /signup, org name not collected yet.
|
|
* 2. Signed in via Google on /login (which auto-creates a Firebase account
|
|
* on first use) and was never provisioned into anything.
|
|
* Either way, this is the one screen an unprovisioned account can reach,
|
|
* and completing it is what POST /auth/signup uses to grant org_id/org_role.
|
|
*/
|
|
export default function OnboardingPage() {
|
|
const { user, loading, orgId, refreshClaims } = useAuth();
|
|
const router = useRouter();
|
|
const [orgName, setOrgName] = useState("");
|
|
const [submitting, setSubmitting] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (loading) return;
|
|
if (!user) {
|
|
router.replace("/login");
|
|
return;
|
|
}
|
|
if (orgId) {
|
|
router.replace("/");
|
|
}
|
|
}, [loading, user, orgId, router]);
|
|
|
|
async function handleSubmit(e: React.FormEvent) {
|
|
e.preventDefault();
|
|
if (!orgName.trim()) return;
|
|
setSubmitting(true);
|
|
setError(null);
|
|
try {
|
|
await c2api.signup(orgName.trim());
|
|
// Firebase custom claims only show up in a *freshly fetched* ID token —
|
|
// getIdTokenResult(true) inside refreshClaims forces that fetch, then
|
|
// AuthProvider's own state (orgId) updates and the effect above
|
|
// redirects to "/" (Live).
|
|
await refreshClaims();
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : "Could not set up your organization. Try again.");
|
|
setSubmitting(false);
|
|
}
|
|
}
|
|
|
|
if (loading || !user || orgId) return null;
|
|
|
|
return (
|
|
<div className="max-w-sm mx-auto pt-16">
|
|
<div className="bg-surface border border-line-strong rounded-xl p-8 space-y-5 font-mono">
|
|
<div>
|
|
<h1 className="text-white text-lg font-bold">Set up your organization</h1>
|
|
<p className="text-ink-2 text-xs mt-2 leading-relaxed">
|
|
One more step — name the organization your nodes, calls, and incidents will belong to. You can change this later.
|
|
</p>
|
|
</div>
|
|
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
<div>
|
|
<label className="text-xs text-ink-2 block mb-1">Organization name</label>
|
|
<input
|
|
type="text"
|
|
value={orgName}
|
|
onChange={(e) => setOrgName(e.target.value)}
|
|
required
|
|
autoFocus
|
|
placeholder="e.g. Riverside County Scanner"
|
|
className="w-full bg-raised border border-line-strong rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-indigo-500"
|
|
/>
|
|
</div>
|
|
{error && <p className="text-red-400 text-xs">{error}</p>}
|
|
<Button type="submit" disabled={submitting || !orgName.trim()} fullWidth>
|
|
{submitting ? "Setting up…" : "Continue"}
|
|
</Button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|