1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
// SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com>
// 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<LoadState>({ 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 (
<div className="dashboard-state dashboard-loading">
<div className="dashboard-state-preferences">
<PreferenceControls locale={locale} labels={navigation} />
</div>
<p>{dashboard.loading}</p>
</div>
);
}
if (state.kind === "error") {
return (
<div className="dashboard-state dashboard-error">
<div className="dashboard-state-preferences">
<PreferenceControls locale={locale} labels={navigation} />
</div>
<p role="alert">{state.message}</p>
</div>
);
}
const { account } = state;
return (
<div className="dashboard-layout">
<aside className="dashboard-sidebar">
<div className="account-avatar" aria-hidden="true">
{account.accountName.slice(0, 2).toUpperCase()}
</div>
<strong>{account.accountName}</strong>
<span>{account.email}</span>
<nav aria-label={dashboard.navigation}>
<a className="active" href="#overview">
{dashboard.overview}
</a>
<a href="#security">{dashboard.security}</a>
<a href="#services">{dashboard.services}</a>
</nav>
<div className="dashboard-sidebar-preferences">
<PreferenceControls locale={locale} labels={navigation} />
</div>
<button className="text-button" type="button" onClick={signOut}>
{dashboard.signOut}
</button>
</aside>
<main className="dashboard-content">
<header className="dashboard-heading" id="overview">
<p className="eyebrow">{dashboard.eyebrow}</p>
<h1>
{dashboard.welcome}, {account.accountName}.
</h1>
<p>{dashboard.description}</p>
</header>
<div className="dashboard-grid">
<section className="dashboard-card">
<span className="card-kicker">{dashboard.profile}</span>
<h2>{dashboard.identity}</h2>
<dl className="detail-list">
<div>
<dt>{dashboard.accountName}</dt>
<dd>{account.accountName}</dd>
</div>
<div>
<dt>{dashboard.publisherName}</dt>
<dd>{account.accountName}</dd>
</div>
<div>
<dt>{dashboard.email}</dt>
<dd>{account.email}</dd>
</div>
<div>
<dt>{dashboard.created}</dt>
<dd>
{new Date(account.createdAt).toLocaleDateString(locale)}
</dd>
</div>
</dl>
</section>
<section className="dashboard-card" id="security">
<span className="card-kicker">{dashboard.security}</span>
<h2>{dashboard.passwordSessions}</h2>
<p>{dashboard.securityDescription}</p>
<button className="button button-secondary" type="button">
{dashboard.changePassword}
</button>
</section>
<section className="dashboard-card dashboard-card-wide" id="services">
<span className="card-kicker">{dashboard.services}</span>
<h2>{dashboard.products}</h2>
<div className="service-row">
<div>
<strong>ViGet Package Registry</strong>
<span>
{dashboard.publisherPrefix}: {account.accountName} (
{dashboard.sameAccount})
</span>
</div>
<span className="status-badge status-planned">
{dashboard.planned}
</span>
</div>
<div className="service-row">
<div>
<strong>Tala</strong>
<span>{dashboard.profileDescription}</span>
</div>
<span className="status-badge status-planned">
{dashboard.planned}
</span>
</div>
</section>
</div>
</main>
</div>
);
}
|