| @@ -1,40 +1,59 @@ |
| 1 | 1 | "use client"; |
| 2 | 2 | |
| 3 | | import { useEffect, useState } from "react"; |
| 3 | import { useEffect, useState, useCallback } from "react"; |
| 4 | 4 | import { useRouter } from "next/navigation"; |
| 5 | | import Link from "next/link"; |
| 6 | 5 | import { useAuth } from "@/lib/auth"; |
| 7 | | import { useTheme } from "@/lib/theme"; |
| 8 | | import { |
| 9 | | instances as instancesApi, |
| 10 | | repos as reposApi, |
| 11 | | orgs as orgsApi, |
| 12 | | ApiError, |
| 13 | | type Instance, |
| 14 | | type Repo, |
| 15 | | type Org, |
| 16 | | } from "@/lib/api"; |
| 17 | | import { timeAgo, timeAgoFromDate } from "@/lib/utils"; |
| 18 | 6 | import { Skeleton } from "@/app/components/skeleton"; |
| 19 | | import { Badge } from "@/app/components/ui/badge"; |
| 7 | |
| 8 | /* ── Types ── */ |
| 9 | |
| 10 | interface ServiceCheck { |
| 11 | name: string; |
| 12 | status: "operational" | "degraded" | "down"; |
| 13 | latency: number | null; |
| 14 | detail?: string; |
| 15 | } |
| 16 | |
| 17 | interface ContainerStats { |
| 18 | name: string; |
| 19 | status: string; |
| 20 | cpu_percent: number; |
| 21 | mem_usage_mb: number; |
| 22 | mem_limit_mb: number; |
| 23 | mem_percent: number; |
| 24 | net_rx_mb: number; |
| 25 | net_tx_mb: number; |
| 26 | uptime: string; |
| 27 | } |
| 28 | |
| 29 | interface SystemMetrics { |
| 30 | cpu_percent: number; |
| 31 | mem_total_mb: number; |
| 32 | mem_used_mb: number; |
| 33 | mem_percent: number; |
| 34 | disk_total_gb: number; |
| 35 | disk_used_gb: number; |
| 36 | disk_percent: number; |
| 37 | load_avg: number[]; |
| 38 | uptime: string; |
| 39 | } |
| 40 | |
| 41 | interface StatusResponse { |
| 42 | status: string; |
| 43 | services: ServiceCheck[]; |
| 44 | containers: ContainerStats[]; |
| 45 | system: SystemMetrics | null; |
| 46 | checked_at: string; |
| 47 | } |
| 48 | |
| 49 | /* ── Page ── */ |
| 20 | 50 | |
| 21 | 51 | export default function DashboardPage() { |
| 22 | | const { user, loading: authLoading, logout } = useAuth(); |
| 23 | | const { theme, toggle: toggleTheme } = useTheme(); |
| 52 | const { user, loading: authLoading } = useAuth(); |
| 24 | 53 | const router = useRouter(); |
| 25 | | const [instanceList, setInstanceList] = useState<Instance[]>([]); |
| 26 | | const [repoList, setRepoList] = useState<Repo[]>([]); |
| 27 | | const [orgList, setOrgList] = useState<Org[]>([]); |
| 28 | | const [loaded, setLoaded] = useState(false); |
| 29 | | const [error, setError] = useState(""); |
| 30 | | const [lastCommitTimes, setLastCommitTimes] = useState<Record<number, number>>({}); |
| 31 | 54 | |
| 32 | | // New org form |
| 33 | | const [showNewOrg, setShowNewOrg] = useState(false); |
| 34 | | const [orgName, setOrgName] = useState(""); |
| 35 | | const [orgDisplayName, setOrgDisplayName] = useState(""); |
| 36 | | const [orgCreating, setOrgCreating] = useState(false); |
| 37 | | const [orgError, setOrgError] = useState(""); |
| 55 | const [data, setData] = useState<StatusResponse | null>(null); |
| 56 | const [loaded, setLoaded] = useState(false); |
| 38 | 57 | |
| 39 | 58 | useEffect(() => { |
| 40 | 59 | document.title = "Dashboard"; |
| @@ -46,408 +65,277 @@ |
| 46 | 65 | } |
| 47 | 66 | }, [authLoading, user, router]); |
| 48 | 67 | |
| 68 | const refresh = useCallback(async () => { |
| 69 | if (!user) return; |
| 70 | try { |
| 71 | const res = await fetch("/api/status", { cache: "no-store" }); |
| 72 | const json: StatusResponse = await res.json(); |
| 73 | setData(json); |
| 74 | } catch {} |
| 75 | setLoaded(true); |
| 76 | }, [user]); |
| 77 | |
| 49 | 78 | useEffect(() => { |
| 50 | 79 | if (!user) return; |
| 51 | | setError(""); |
| 52 | | Promise.allSettled([ |
| 53 | | instancesApi.list(), |
| 54 | | reposApi.list(), |
| 55 | | orgsApi.list(), |
| 56 | | ]) |
| 57 | | .then(([instResult, repoResult, orgResult]) => { |
| 58 | | const failures = [instResult, repoResult, orgResult].filter( |
| 59 | | (result): result is PromiseRejectedResult => result.status === "rejected" |
| 60 | | ); |
| 80 | refresh(); |
| 81 | const iv = setInterval(refresh, 30000); |
| 82 | return () => clearInterval(iv); |
| 83 | }, [user, refresh]); |
| 61 | 84 | |
| 62 | | const authFailure = failures.find( |
| 63 | | (result) => |
| 64 | | result.reason instanceof ApiError && result.reason.status === 401 |
| 65 | | ); |
| 66 | | if (authFailure) { |
| 67 | | logout(); |
| 68 | | router.push(`/login?redirect=${encodeURIComponent(window.location.pathname)}`); |
| 69 | | return; |
| 70 | | } |
| 85 | if (authLoading || !user) return null; |
| 71 | 86 | |
| 72 | | setInstanceList( |
| 73 | | instResult.status === "fulfilled" ? instResult.value.instances : [] |
| 74 | | ); |
| 75 | | setRepoList( |
| 76 | | repoResult.status === "fulfilled" ? repoResult.value.repos : [] |
| 77 | | ); |
| 78 | | setOrgList( |
| 79 | | orgResult.status === "fulfilled" ? orgResult.value.orgs : [] |
| 80 | | ); |
| 87 | const sys = data?.system; |
| 88 | const containers = data?.containers ?? []; |
| 89 | const services = data?.services ?? []; |
| 81 | 90 | |
| 82 | | if (failures.length > 0) { |
| 83 | | const messages = failures |
| 84 | | .map((result) => |
| 85 | | result.reason instanceof Error |
| 86 | | ? result.reason.message |
| 87 | | : "Unknown API error" |
| 88 | | ) |
| 89 | | .join(" · "); |
| 90 | | setError(`Some dashboard data failed to load: ${messages}`); |
| 91 | | } |
| 92 | | }) |
| 93 | | .finally(() => setLoaded(true)); |
| 94 | | }, [user, logout, router]); |
| 91 | return ( |
| 92 | <div style={{ maxWidth: 1100, margin: "0 auto", padding: "1.25rem 1rem 2rem" }}> |
| 93 | {/* ── Header ── */} |
| 94 | <div className="flex items-center justify-between" style={{ marginBottom: "1rem" }}> |
| 95 | <span className="text-sm font-medium" style={{ color: "var(--text-primary)" }}>Dashboard</span> |
| 96 | <div className="flex items-center gap-3"> |
| 97 | {data?.checked_at && ( |
| 98 | <span className="text-xs" style={{ color: "var(--text-faint)" }}> |
| 99 | {new Date(data.checked_at).toLocaleTimeString()} |
| 100 | </span> |
| 101 | )} |
| 102 | <button onClick={refresh} className="btn-reset text-xs" style={{ color: "var(--text-muted)" }}> |
| 103 | Refresh |
| 104 | </button> |
| 105 | </div> |
| 106 | </div> |
| 95 | 107 | |
| 96 | | // Fetch last commit time for each repo |
| 97 | | useEffect(() => { |
| 98 | | if (repoList.length === 0) return; |
| 99 | | Promise.all( |
| 100 | | repoList.map(async (repo) => { |
| 101 | | try { |
| 102 | | const data = await reposApi.commits(repo.owner_name, repo.name, "main", { limit: 1 }); |
| 103 | | const latest = data.commits[0]; |
| 104 | | if (latest) return { id: repo.id, timestamp: latest.timestamp }; |
| 105 | | } catch {} |
| 106 | | return null; |
| 107 | | }) |
| 108 | | ).then((results) => { |
| 109 | | const times: Record<number, number> = {}; |
| 110 | | for (const r of results) { |
| 111 | | if (r) times[r.id] = r.timestamp; |
| 112 | | } |
| 113 | | setLastCommitTimes(times); |
| 114 | | }); |
| 115 | | }, [repoList]); |
| 108 | {/* ── System gauges ── */} |
| 109 | <div |
| 110 | style={{ |
| 111 | display: "grid", |
| 112 | gridTemplateColumns: "repeat(4, 1fr)", |
| 113 | gap: "0.625rem", |
| 114 | marginBottom: "0.875rem", |
| 115 | }} |
| 116 | > |
| 117 | <GaugeCard |
| 118 | label="CPU" |
| 119 | value={sys?.cpu_percent ?? null} |
| 120 | detail={sys?.load_avg ? `Load ${sys.load_avg.map((l) => l.toFixed(1)).join(" ")}` : undefined} |
| 121 | loaded={loaded} |
| 122 | /> |
| 123 | <GaugeCard |
| 124 | label="Memory" |
| 125 | value={sys?.mem_percent ?? null} |
| 126 | detail={sys ? `${sys.mem_used_mb} / ${sys.mem_total_mb} MB` : undefined} |
| 127 | loaded={loaded} |
| 128 | /> |
| 129 | <GaugeCard |
| 130 | label="Disk" |
| 131 | value={sys?.disk_percent ?? null} |
| 132 | detail={sys ? `${sys.disk_used_gb} / ${sys.disk_total_gb} GB` : undefined} |
| 133 | loaded={loaded} |
| 134 | /> |
| 135 | <GaugeCard |
| 136 | label="Uptime" |
| 137 | value={null} |
| 138 | displayValue={sys?.uptime || null} |
| 139 | loaded={loaded} |
| 140 | /> |
| 141 | </div> |
| 116 | 142 | |
| 117 | | async function handleCreateOrg(e: React.FormEvent) { |
| 118 | | e.preventDefault(); |
| 119 | | setOrgError(""); |
| 120 | | setOrgCreating(true); |
| 121 | | try { |
| 122 | | const { org } = await orgsApi.create({ |
| 123 | | name: orgName, |
| 124 | | display_name: orgDisplayName || undefined, |
| 125 | | }); |
| 126 | | setOrgList((prev) => [org, ...prev]); |
| 127 | | setOrgName(""); |
| 128 | | setOrgDisplayName(""); |
| 129 | | setShowNewOrg(false); |
| 130 | | } catch (err: unknown) { |
| 131 | | setOrgError( |
| 132 | | err instanceof Error ? err.message : "Failed to create org" |
| 133 | | ); |
| 134 | | } finally { |
| 135 | | setOrgCreating(false); |
| 136 | | } |
| 137 | | } |
| 143 | {/* ── Services + Containers ── */} |
| 144 | <div |
| 145 | style={{ |
| 146 | display: "grid", |
| 147 | gridTemplateColumns: "1fr 1fr", |
| 148 | gap: "0.625rem", |
| 149 | }} |
| 150 | > |
| 151 | <Panel title="Services" count={services.length}> |
| 152 | {!loaded ? ( |
| 153 | <SkeletonRows n={6} /> |
| 154 | ) : services.length === 0 ? ( |
| 155 | <EmptyRow>No service data</EmptyRow> |
| 156 | ) : ( |
| 157 | <div className="flex flex-col"> |
| 158 | {services.map((svc) => ( |
| 159 | <div |
| 160 | key={svc.name} |
| 161 | className="flex items-center justify-between py-1.5 px-2.5" |
| 162 | style={{ borderBottom: "1px solid var(--divide)" }} |
| 163 | > |
| 164 | <div className="flex items-center gap-2"> |
| 165 | <StatusDot status={svc.status} /> |
| 166 | <span className="text-sm" style={{ color: "var(--text-primary)" }}>{svc.name}</span> |
| 167 | </div> |
| 168 | <span className="text-xs font-mono" style={{ color: "var(--text-faint)" }}> |
| 169 | {svc.latency !== null ? `${svc.latency}ms` : svc.detail ?? "—"} |
| 170 | </span> |
| 171 | </div> |
| 172 | ))} |
| 173 | </div> |
| 174 | )} |
| 175 | </Panel> |
| 138 | 176 | |
| 139 | | if (authLoading || !user) return null; |
| 177 | <Panel title="Containers" count={containers.length}> |
| 178 | {!loaded ? ( |
| 179 | <SkeletonRows n={6} /> |
| 180 | ) : containers.length === 0 ? ( |
| 181 | <EmptyRow>No container data</EmptyRow> |
| 182 | ) : ( |
| 183 | <div className="flex flex-col"> |
| 184 | {containers.map((c) => ( |
| 185 | <div |
| 186 | key={c.name} |
| 187 | className="flex items-center justify-between py-1.5 px-2.5" |
| 188 | style={{ borderBottom: "1px solid var(--divide)" }} |
| 189 | > |
| 190 | <div className="flex items-center gap-2 min-w-0"> |
| 191 | <StatusDot status={c.status === "running" ? "operational" : "down"} /> |
| 192 | <span className="text-sm truncate" style={{ color: "var(--text-primary)" }}>{c.name}</span> |
| 193 | <span className="text-xs shrink-0" style={{ color: "var(--text-faint)" }}>{c.uptime}</span> |
| 194 | </div> |
| 195 | <div className="flex items-center gap-3 shrink-0"> |
| 196 | <MiniBar value={c.cpu_percent} max={100} label={`${c.cpu_percent.toFixed(1)}%`} color="var(--accent)" /> |
| 197 | <MiniBar value={c.mem_usage_mb} max={c.mem_limit_mb || 1} label={`${c.mem_usage_mb}M`} color="var(--status-merged-text)" /> |
| 198 | </div> |
| 199 | </div> |
| 200 | ))} |
| 201 | </div> |
| 202 | )} |
| 203 | </Panel> |
| 204 | </div> |
| 205 | </div> |
| 206 | ); |
| 207 | } |
| 208 | |
| 209 | /* ── Gauge card ── */ |
| 140 | 210 | |
| 141 | | const activeInstances = instanceList.filter((i) => i.status === "active"); |
| 142 | | const hasInstance = activeInstances.length > 0; |
| 211 | function GaugeCard({ |
| 212 | label, |
| 213 | value, |
| 214 | displayValue, |
| 215 | detail, |
| 216 | loaded, |
| 217 | }: { |
| 218 | label: string; |
| 219 | value: number | null; |
| 220 | displayValue?: string | null; |
| 221 | detail?: string; |
| 222 | loaded: boolean; |
| 223 | }) { |
| 224 | const pct = value !== null ? Math.min(100, Math.max(0, value)) : null; |
| 225 | const color = |
| 226 | pct === null |
| 227 | ? "var(--text-faint)" |
| 228 | : pct > 85 |
| 229 | ? "var(--status-closed-text)" |
| 230 | : pct > 60 |
| 231 | ? "var(--status-merged-text)" |
| 232 | : "var(--status-open-text)"; |
| 143 | 233 | |
| 144 | 234 | return ( |
| 145 | | <div className="max-w-3xl mx-auto px-4 py-6 flex flex-col gap-8"> |
| 146 | | {/* Greeting */} |
| 147 | | <div className="flex items-center gap-3"> |
| 235 | <div |
| 236 | style={{ |
| 237 | backgroundColor: "var(--bg-card)", |
| 238 | border: "1px solid var(--border-subtle)", |
| 239 | padding: "0.75rem 0.875rem", |
| 240 | position: "relative", |
| 241 | overflow: "hidden", |
| 242 | }} |
| 243 | > |
| 244 | {pct !== null && ( |
| 148 | 245 | <div |
| 149 | | className="shrink-0 flex items-center justify-center text-sm" |
| 150 | 246 | style={{ |
| 151 | | width: 36, |
| 152 | | height: 36, |
| 153 | | borderRadius: "50%", |
| 154 | | backgroundColor: "var(--bg-inset)", |
| 155 | | border: "1px solid var(--border-subtle)", |
| 156 | | color: "var(--text-muted)", |
| 247 | position: "absolute", |
| 248 | left: 0, |
| 249 | bottom: 0, |
| 250 | width: `${pct}%`, |
| 251 | height: 3, |
| 252 | backgroundColor: color, |
| 253 | transition: "width 0.6s ease, background-color 0.3s", |
| 157 | 254 | }} |
| 158 | | > |
| 159 | | {(user.display_name || user.username).charAt(0).toUpperCase()} |
| 160 | | </div> |
| 161 | | <div> |
| 162 | | <div className="text-sm font-medium" style={{ color: "var(--text-primary)" }}> |
| 163 | | {user.display_name || user.username} |
| 255 | /> |
| 256 | )} |
| 257 | <div className="text-xs font-mono" style={{ color: "var(--text-faint)", marginBottom: 3 }}> |
| 258 | {label} |
| 259 | </div> |
| 260 | {!loaded ? ( |
| 261 | <Skeleton width="3rem" height="1.25rem" /> |
| 262 | ) : ( |
| 263 | <> |
| 264 | <div |
| 265 | className="font-mono" |
| 266 | style={{ fontSize: "1.375rem", fontWeight: 500, color: displayValue ? "var(--text-primary)" : color, lineHeight: 1.1 }} |
| 267 | > |
| 268 | {displayValue ?? (pct !== null ? `${pct}%` : "—")} |
| 164 | 269 | </div> |
| 165 | | {loaded ? ( |
| 166 | | <div className="text-xs" style={{ color: "var(--text-faint)" }}> |
| 167 | | {repoList.length} {repoList.length === 1 ? "repository" : "repositories"} |
| 168 | | {orgList.length > 0 && ( |
| 169 | | <> · {orgList.length} {orgList.length === 1 ? "org" : "orgs"}</> |
| 170 | | )} |
| 171 | | {activeInstances.length > 0 && ( |
| 172 | | <> · {activeInstances.length} active {activeInstances.length === 1 ? "instance" : "instances"}</> |
| 173 | | )} |
| 174 | | </div> |
| 175 | | ) : ( |
| 176 | | <Skeleton width="160px" height="0.75rem" /> |
| 270 | {detail && ( |
| 271 | <div className="text-xs" style={{ color: "var(--text-faint)", marginTop: 2 }}>{detail}</div> |
| 177 | 272 | )} |
| 178 | | </div> |
| 179 | | </div> |
| 180 | | |
| 181 | | {error && ( |
| 182 | | <div |
| 183 | | className="text-sm px-3 py-2" |
| 184 | | style={{ color: "var(--status-closed-text)", backgroundColor: "var(--bg-inset)", border: "1px solid var(--border-subtle)" }} |
| 185 | | > |
| 186 | | {error} |
| 187 | | </div> |
| 273 | </> |
| 188 | 274 | )} |
| 275 | </div> |
| 276 | ); |
| 277 | } |
| 189 | 278 | |
| 190 | | {/* Repositories */} |
| 191 | | <div> |
| 192 | | <div className="flex items-center justify-between pb-2" style={{ borderBottom: "1px solid var(--divide)" }}> |
| 193 | | <div className="flex items-center gap-2"> |
| 194 | | <span className="text-sm font-medium" style={{ color: "var(--text-primary)" }}>Repositories</span> |
| 195 | | {loaded && ( |
| 196 | | <span className="text-xs" style={{ color: "var(--text-faint)" }}>{repoList.length}</span> |
| 197 | | )} |
| 198 | | </div> |
| 199 | | <Link |
| 200 | | href="/new" |
| 201 | | className="text-xs hover:underline" |
| 202 | | style={{ color: "var(--accent)", textDecoration: "none" }} |
| 203 | | > |
| 204 | | New repository |
| 205 | | </Link> |
| 206 | | </div> |
| 279 | /* ── Mini bar ── */ |
| 207 | 280 | |
| 208 | | {!loaded ? ( |
| 209 | | <div className="py-3 space-y-1"> |
| 210 | | <Skeleton width="100%" height="2.5rem" /> |
| 211 | | <Skeleton width="100%" height="2.5rem" /> |
| 212 | | </div> |
| 213 | | ) : repoList.length === 0 ? ( |
| 214 | | <div className="py-8 text-center"> |
| 215 | | <p className="text-sm" style={{ color: "var(--text-faint)" }}> |
| 216 | | {hasInstance |
| 217 | | ? "No repositories yet. Create your first repository to start hosting code." |
| 218 | | : "Deploy an instance first, then create repositories."} |
| 219 | | </p> |
| 220 | | <Link |
| 221 | | href={hasInstance ? "/new" : "/deploy"} |
| 222 | | className="text-xs mt-2 inline-block hover:underline" |
| 223 | | style={{ color: "var(--accent)" }} |
| 224 | | > |
| 225 | | {hasInstance ? "New repository" : "Deploy instance"} |
| 226 | | </Link> |
| 227 | | </div> |
| 228 | | ) : ( |
| 229 | | <div> |
| 230 | | {repoList.map((repo) => ( |
| 231 | | <Link |
| 232 | | key={repo.id} |
| 233 | | href={`/${repo.owner_name}/${repo.name}`} |
| 234 | | className="flex items-center justify-between py-2.5 px-1 hover-row" |
| 235 | | style={{ borderBottom: "1px solid var(--divide)", textDecoration: "none", color: "inherit" }} |
| 236 | | > |
| 237 | | <div className="flex items-center gap-1.5 text-sm min-w-0"> |
| 238 | | <span style={{ color: "var(--text-muted)" }}>{repo.owner_name}</span> |
| 239 | | <span style={{ color: "var(--text-faint)" }}>/</span> |
| 240 | | <span style={{ color: "var(--text-primary)" }}>{repo.name}</span> |
| 241 | | {repo.description && ( |
| 242 | | <span className="text-xs truncate ml-2" style={{ color: "var(--text-faint)" }}> |
| 243 | | {repo.description} |
| 244 | | </span> |
| 245 | | )} |
| 246 | | </div> |
| 247 | | <span className="text-xs shrink-0 ml-3" style={{ color: "var(--text-faint)" }}> |
| 248 | | {lastCommitTimes[repo.id] |
| 249 | | ? timeAgo(lastCommitTimes[repo.id]) |
| 250 | | : timeAgoFromDate(repo.created_at)} |
| 251 | | </span> |
| 252 | | </Link> |
| 253 | | ))} |
| 254 | | </div> |
| 255 | | )} |
| 281 | function MiniBar({ value, max, label, color }: { value: number; max: number; label: string; color: string }) { |
| 282 | const pct = max > 0 ? Math.min(100, (value / max) * 100) : 0; |
| 283 | return ( |
| 284 | <div className="flex items-center gap-1.5" style={{ minWidth: 70 }}> |
| 285 | <div style={{ width: 36, height: 6, backgroundColor: "var(--bg-inset)", borderRadius: 3, overflow: "hidden" }}> |
| 286 | <div style={{ width: `${pct}%`, height: "100%", backgroundColor: color, borderRadius: 3, transition: "width 0.4s ease" }} /> |
| 256 | 287 | </div> |
| 288 | <span className="text-xs font-mono" style={{ color: "var(--text-faint)" }}>{label}</span> |
| 289 | </div> |
| 290 | ); |
| 291 | } |
| 257 | 292 | |
| 258 | | {/* Organizations */} |
| 259 | | <div> |
| 260 | | <div className="flex items-center justify-between pb-2" style={{ borderBottom: "1px solid var(--divide)" }}> |
| 261 | | <div className="flex items-center gap-2"> |
| 262 | | <span className="text-sm font-medium" style={{ color: "var(--text-primary)" }}>Organizations</span> |
| 263 | | {loaded && ( |
| 264 | | <span className="text-xs" style={{ color: "var(--text-faint)" }}>{orgList.length}</span> |
| 265 | | )} |
| 266 | | </div> |
| 267 | | <button |
| 268 | | onClick={() => setShowNewOrg((v) => !v)} |
| 269 | | className="btn-reset text-xs hover:underline" |
| 270 | | style={{ color: "var(--text-muted)", font: "inherit", fontSize: "0.75rem" }} |
| 271 | | > |
| 272 | | {showNewOrg ? "Cancel" : "New org"} |
| 273 | | </button> |
| 274 | | </div> |
| 275 | | |
| 276 | | {showNewOrg && ( |
| 277 | | <form |
| 278 | | onSubmit={handleCreateOrg} |
| 279 | | className="py-3 flex flex-col gap-2" |
| 280 | | style={{ borderBottom: "1px solid var(--divide)" }} |
| 281 | | > |
| 282 | | <div className="text-xs" style={{ color: "var(--text-muted)" }}>Create a new organization</div> |
| 283 | | <input |
| 284 | | value={orgName} |
| 285 | | onChange={(e) => setOrgName(e.target.value)} |
| 286 | | placeholder="org-name" |
| 287 | | required |
| 288 | | className="text-sm px-2.5 py-1.5" |
| 289 | | style={{ |
| 290 | | backgroundColor: "var(--bg-input)", |
| 291 | | border: "1px solid var(--border-subtle)", |
| 292 | | color: "var(--text-primary)", |
| 293 | | font: "inherit", |
| 294 | | fontSize: "0.875rem", |
| 295 | | }} |
| 296 | | /> |
| 297 | | <input |
| 298 | | value={orgDisplayName} |
| 299 | | onChange={(e) => setOrgDisplayName(e.target.value)} |
| 300 | | placeholder="Display name (optional)" |
| 301 | | className="text-sm px-2.5 py-1.5" |
| 302 | | style={{ |
| 303 | | backgroundColor: "var(--bg-input)", |
| 304 | | border: "1px solid var(--border-subtle)", |
| 305 | | color: "var(--text-primary)", |
| 306 | | font: "inherit", |
| 307 | | fontSize: "0.875rem", |
| 308 | | }} |
| 309 | | /> |
| 310 | | {orgError && ( |
| 311 | | <div className="text-xs" style={{ color: "var(--status-closed-text)" }}>{orgError}</div> |
| 312 | | )} |
| 313 | | <button |
| 314 | | type="submit" |
| 315 | | disabled={orgCreating} |
| 316 | | className="text-xs self-start px-3 py-1.5" |
| 317 | | style={{ |
| 318 | | backgroundColor: "var(--accent)", |
| 319 | | color: "var(--accent-text)", |
| 320 | | border: "none", |
| 321 | | cursor: orgCreating ? "wait" : "pointer", |
| 322 | | font: "inherit", |
| 323 | | fontSize: "0.75rem", |
| 324 | | opacity: orgCreating ? 0.6 : 1, |
| 325 | | }} |
| 326 | | > |
| 327 | | {orgCreating ? "Creating..." : "Create"} |
| 328 | | </button> |
| 329 | | </form> |
| 330 | | )} |
| 293 | /* ── Panel ── */ |
| 331 | 294 | |
| 332 | | {!loaded ? ( |
| 333 | | <div className="py-3"> |
| 334 | | <Skeleton width="100%" height="2.5rem" /> |
| 335 | | </div> |
| 336 | | ) : orgList.length === 0 ? ( |
| 337 | | <div className="py-8 text-center"> |
| 338 | | <p className="text-sm" style={{ color: "var(--text-faint)" }}> |
| 339 | | No organizations yet. |
| 340 | | </p> |
| 341 | | <button |
| 342 | | onClick={() => setShowNewOrg(true)} |
| 343 | | className="btn-reset text-xs mt-2 hover:underline" |
| 344 | | style={{ color: "var(--accent)", font: "inherit", fontSize: "0.75rem" }} |
| 345 | | > |
| 346 | | Create organization |
| 347 | | </button> |
| 348 | | </div> |
| 349 | | ) : ( |
| 350 | | <div> |
| 351 | | {orgList.map((org) => ( |
| 352 | | <Link |
| 353 | | key={org.id} |
| 354 | | href={`/${org.name}`} |
| 355 | | className="flex items-center py-2.5 px-1 hover-row text-sm" |
| 356 | | style={{ borderBottom: "1px solid var(--divide)", textDecoration: "none", color: "var(--text-primary)" }} |
| 357 | | > |
| 358 | | {org.display_name || org.name} |
| 359 | | </Link> |
| 360 | | ))} |
| 361 | | </div> |
| 295 | function Panel({ title, count, children }: { title: string; count?: number; children: React.ReactNode }) { |
| 296 | return ( |
| 297 | <div |
| 298 | style={{ |
| 299 | backgroundColor: "var(--bg-card)", |
| 300 | border: "1px solid var(--border-subtle)", |
| 301 | display: "flex", |
| 302 | flexDirection: "column", |
| 303 | }} |
| 304 | > |
| 305 | <div className="flex items-center gap-2 px-2.5 py-1.5" style={{ borderBottom: "1px solid var(--divide)" }}> |
| 306 | <span className="text-sm font-medium" style={{ color: "var(--text-primary)" }}>{title}</span> |
| 307 | {count !== undefined && ( |
| 308 | <span className="text-xs" style={{ color: "var(--text-faint)" }}>{count}</span> |
| 362 | 309 | )} |
| 363 | 310 | </div> |
| 311 | <div style={{ flex: 1 }}>{children}</div> |
| 312 | </div> |
| 313 | ); |
| 314 | } |
| 364 | 315 | |
| 365 | | {/* Instances */} |
| 366 | | <div> |
| 367 | | <div className="flex items-center justify-between pb-2" style={{ borderBottom: "1px solid var(--divide)" }}> |
| 368 | | <div className="flex items-center gap-2"> |
| 369 | | <span className="text-sm font-medium" style={{ color: "var(--text-primary)" }}>Instances</span> |
| 370 | | {loaded && ( |
| 371 | | <span className="text-xs" style={{ color: "var(--text-faint)" }}>{instanceList.length}</span> |
| 372 | | )} |
| 373 | | </div> |
| 374 | | <Link |
| 375 | | href="/deploy" |
| 376 | | className="text-xs hover:underline" |
| 377 | | style={{ color: "var(--text-muted)", textDecoration: "none" }} |
| 378 | | > |
| 379 | | Deploy new |
| 380 | | </Link> |
| 381 | | </div> |
| 382 | 316 | |
| 383 | | {!loaded ? ( |
| 384 | | <div className="py-3 space-y-1"> |
| 385 | | <Skeleton width="100%" height="2.5rem" /> |
| 386 | | <Skeleton width="100%" height="2.5rem" /> |
| 387 | | </div> |
| 388 | | ) : instanceList.length === 0 ? ( |
| 389 | | <div className="py-8 text-center"> |
| 390 | | <p className="text-sm" style={{ color: "var(--text-faint)" }}> |
| 391 | | No instances yet. Deploy a Grove instance on any VPS to start hosting repositories. |
| 392 | | </p> |
| 393 | | <Link |
| 394 | | href="/deploy" |
| 395 | | className="text-xs mt-2 inline-block hover:underline" |
| 396 | | style={{ color: "var(--accent)" }} |
| 397 | | > |
| 398 | | Deploy your first instance |
| 399 | | </Link> |
| 400 | | </div> |
| 401 | | ) : ( |
| 402 | | <div> |
| 403 | | {instanceList.map((inst) => ( |
| 404 | | <div |
| 405 | | key={inst.id} |
| 406 | | className="flex items-center justify-between py-2.5 px-1" |
| 407 | | style={{ borderBottom: "1px solid var(--divide)" }} |
| 408 | | > |
| 409 | | <div> |
| 410 | | <div className="text-sm" style={{ color: "var(--text-primary)" }}>{inst.name}</div> |
| 411 | | <div className="text-xs mt-0.5" style={{ color: "var(--text-faint)" }}>{inst.region}</div> |
| 412 | | </div> |
| 413 | | <Badge |
| 414 | | variant={ |
| 415 | | inst.status === "active" |
| 416 | | ? "passed" |
| 417 | | : inst.status === "creating" |
| 418 | | ? "pending" |
| 419 | | : "failed" |
| 420 | | } |
| 421 | | > |
| 422 | | {inst.status} |
| 423 | | </Badge> |
| 424 | | </div> |
| 425 | | ))} |
| 426 | | </div> |
| 427 | | )} |
| 428 | | </div> |
| 317 | /* ── Helpers ── */ |
| 429 | 318 | |
| 430 | | {/* Settings */} |
| 431 | | <div> |
| 432 | | <div className="pb-2" style={{ borderBottom: "1px solid var(--divide)" }}> |
| 433 | | <span className="text-sm font-medium" style={{ color: "var(--text-primary)" }}>Settings</span> |
| 434 | | </div> |
| 435 | | <div className="flex items-center justify-between py-2.5 px-1" style={{ borderBottom: "1px solid var(--divide)" }}> |
| 436 | | <div> |
| 437 | | <div className="text-sm" style={{ color: "var(--text-primary)" }}>Appearance</div> |
| 438 | | <div className="text-xs mt-0.5" style={{ color: "var(--text-faint)" }}> |
| 439 | | Currently using {theme} mode |
| 440 | | </div> |
| 441 | | </div> |
| 442 | | <button |
| 443 | | onClick={toggleTheme} |
| 444 | | className="btn-reset text-xs hover:underline" |
| 445 | | style={{ color: "var(--text-muted)", font: "inherit", fontSize: "0.75rem" }} |
| 446 | | > |
| 447 | | Switch to {theme === "light" ? "dark" : "light"} |
| 448 | | </button> |
| 449 | | </div> |
| 450 | | </div> |
| 319 | function StatusDot({ status }: { status: "operational" | "degraded" | "down" }) { |
| 320 | const color = |
| 321 | status === "operational" ? "var(--status-open-text)" : status === "degraded" ? "var(--status-merged-text)" : "var(--status-closed-text)"; |
| 322 | return ( |
| 323 | <span style={{ width: 7, height: 7, borderRadius: "50%", backgroundColor: color, display: "inline-block", flexShrink: 0 }} /> |
| 324 | ); |
| 325 | } |
| 326 | |
| 327 | function SkeletonRows({ n }: { n: number }) { |
| 328 | return ( |
| 329 | <div className="p-2 space-y-1"> |
| 330 | {Array.from({ length: n }, (_, i) => ( |
| 331 | <Skeleton key={i} width="100%" height="1.75rem" /> |
| 332 | ))} |
| 451 | 333 | </div> |
| 452 | 334 | ); |
| 453 | 335 | } |
| 336 | |
| 337 | function EmptyRow({ children }: { children: React.ReactNode }) { |
| 338 | return ( |
| 339 | <div className="py-4 text-center text-xs" style={{ color: "var(--text-faint)" }}>{children}</div> |
| 340 | ); |
| 341 | } |
| 454 | 342 | |