// SPDX-FileCopyrightText: 2026 Progmasoft // SPDX-License-Identifier: AGPL-3.0-or-later WITH AdditionRef-Progmasoft-Patent-Grant-1.1 "use client"; import { useEffect, useState } from "react"; import { getMessages, type Locale } from "@/lib/localization"; import { PreferenceControls } from "./PreferenceControls"; interface AccountSummary { accountName: string; email: string; createdAt: string; } interface DashboardClientProps { locale: Locale; routeAccountName: string; } type LoadState = | { kind: "loading" } | { kind: "error"; message: string } | { kind: "ready"; account: AccountSummary }; export function DashboardClient({ locale, routeAccountName, }: DashboardClientProps) { const { dashboard, navigation } = getMessages(locale); const [state, setState] = useState({ kind: "loading" }); useEffect(() => { const controller = new AbortController(); async function loadAccount() { try { const response = await fetch("/api/v1/accounts/me", { credentials: "include", signal: controller.signal, }); if (response.status === 401) { window.location.replace( `/login?returnTo=/${encodeURIComponent(routeAccountName)}/dashboard`, ); return; } if (!response.ok) { setState({ kind: "error", message: dashboard.loadFailed, }); return; } const account = (await response.json()) as AccountSummary; if (account.accountName !== routeAccountName) { window.location.replace( `/${encodeURIComponent(account.accountName)}/dashboard`, ); return; } setState({ kind: "ready", account }); } catch (error) { if (!(error instanceof DOMException && error.name === "AbortError")) { setState({ kind: "error", message: dashboard.unreachable, }); } } } void loadAccount(); return () => controller.abort(); }, [dashboard.loadFailed, dashboard.unreachable, routeAccountName]); async function signOut() { await fetch("/api/v1/accounts/logout", { method: "POST", credentials: "include", }); window.location.replace("/login"); } if (state.kind === "loading") { return (

{dashboard.loading}

); } if (state.kind === "error") { return (

{state.message}

); } const { account } = state; return (

{dashboard.eyebrow}

{dashboard.welcome}, {account.accountName}.

{dashboard.description}

{dashboard.profile}

{dashboard.identity}

{dashboard.accountName}
{account.accountName}
{dashboard.publisherName}
{account.accountName}
{dashboard.email}
{account.email}
{dashboard.created}
{new Date(account.createdAt).toLocaleDateString(locale)}
{dashboard.security}

{dashboard.passwordSessions}

{dashboard.securityDescription}

{dashboard.services}

{dashboard.products}

ViGet Package Registry {dashboard.publisherPrefix}: {account.accountName} ( {dashboard.sameAccount})
{dashboard.planned}
Tala {dashboard.profileDescription}
{dashboard.planned}
); }