"use client"; import Link from "next/link"; import React, { useState } from "react"; import { Button, Card, Field, Heading, Notice, Shell } from "@crosscode/ui"; import { useBranding } from "@/components/BrandingProvider"; import { call, type ApiError } from "@/lib/api"; import { useExternalEffect } from "@/lib/hooks"; type Status = { needed: boolean; hubConnected: boolean; adminEmail: string | null }; /** First run: the church's name, the first admin and the licence key (docs/ACCOUNTS-1.0-PLAN.md §8). */ export function Setup() { const branding = useBranding(); const [status, setStatus] = useState(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); useExternalEffect(() => { let alive = true; call("GET", "/setup").then((r) => { if (alive && r.ok) setStatus(r.data); }); return () => { alive = false; }; }, []); const f = (n: string) => error?.fields?.[n] ?? null; return ( Set up Accounts {!status ?

Loading…

: !status.needed ? ( Accounts is already set up. Sign in ) : (
{ e.preventDefault(); const d = new FormData(e.currentTarget); setBusy(true); setError(null); const r = await call<{ next: string }>("POST", "/setup", { churchName: d.get("churchName"), name: d.get("name"), email: d.get("email"), password: d.get("password"), licenceKey: d.get("licenceKey") || undefined }); setBusy(false); if (r.ok) window.location.assign(r.data.next); else setError(r.error); }}> {error && !error.fields && {error.message}} {!status.hubConnected && } )}
); }