astrogators-shared-ui 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +318 -0
- package/dist/components/display/Badge.d.ts +13 -0
- package/dist/components/display/Card.d.ts +17 -0
- package/dist/components/display/Modal.d.ts +16 -0
- package/dist/components/display/index.d.ts +6 -0
- package/dist/components/feedback/Loader.d.ts +12 -0
- package/dist/components/feedback/index.d.ts +2 -0
- package/dist/components/forms/AllyCodeDropdown.d.ts +12 -0
- package/dist/components/forms/Button.d.ts +16 -0
- package/dist/components/forms/Input.d.ts +14 -0
- package/dist/components/forms/Select.d.ts +21 -0
- package/dist/components/forms/index.d.ts +8 -0
- package/dist/components/layout/Container.d.ts +13 -0
- package/dist/components/layout/Footer.d.ts +11 -0
- package/dist/components/layout/TopBar.d.ts +13 -0
- package/dist/components/layout/index.d.ts +6 -0
- package/dist/contexts/AuthContext.d.ts +40 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +769 -0
- package/dist/services/allyCodeStorage.d.ts +16 -0
- package/dist/services/api.d.ts +24 -0
- package/dist/services/auth.d.ts +13 -0
- package/dist/style.css +1 -0
- package/dist/types/api.d.ts +20 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/mod.d.ts +64 -0
- package/dist/types/user.d.ts +85 -0
- package/dist/utils/formatAllyCode.d.ts +8 -0
- package/package.json +50 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,769 @@
|
|
|
1
|
+
var ue = Object.defineProperty;
|
|
2
|
+
var me = (t, e, s) => e in t ? ue(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
|
|
3
|
+
var R = (t, e, s) => me(t, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
+
import { jsx as n, jsxs as h } from "react/jsx-runtime";
|
|
5
|
+
import ne, { createContext as he, useState as $, useCallback as A, useEffect as J, useContext as ge } from "react";
|
|
6
|
+
const pe = "_container_u3o0e_1", fe = "_padding_u3o0e_7", Q = {
|
|
7
|
+
container: pe,
|
|
8
|
+
padding: fe,
|
|
9
|
+
"maxWidth-sm": "_maxWidth-sm_u3o0e_12",
|
|
10
|
+
"maxWidth-md": "_maxWidth-md_u3o0e_16",
|
|
11
|
+
"maxWidth-lg": "_maxWidth-lg_u3o0e_20",
|
|
12
|
+
"maxWidth-xl": "_maxWidth-xl_u3o0e_24",
|
|
13
|
+
"maxWidth-full": "_maxWidth-full_u3o0e_28"
|
|
14
|
+
}, gs = ({
|
|
15
|
+
children: t,
|
|
16
|
+
maxWidth: e = "xl",
|
|
17
|
+
padding: s = !0,
|
|
18
|
+
className: r = ""
|
|
19
|
+
}) => /* @__PURE__ */ n(
|
|
20
|
+
"div",
|
|
21
|
+
{
|
|
22
|
+
className: `${Q.container} ${Q[`maxWidth-${e}`]} ${s ? Q.padding : ""} ${r}`,
|
|
23
|
+
children: t
|
|
24
|
+
}
|
|
25
|
+
), ye = "_topBar_10g3c_1", ve = "_content_10g3c_13", $e = "_left_10g3c_23", we = "_right_10g3c_30", be = "_logo_10g3c_36", B = {
|
|
26
|
+
topBar: ye,
|
|
27
|
+
content: ve,
|
|
28
|
+
left: $e,
|
|
29
|
+
right: we,
|
|
30
|
+
logo: be
|
|
31
|
+
}, ps = ({
|
|
32
|
+
logo: t,
|
|
33
|
+
leftContent: e,
|
|
34
|
+
rightContent: s,
|
|
35
|
+
className: r = ""
|
|
36
|
+
}) => /* @__PURE__ */ n("header", { className: `${B.topBar} ${r}`, children: /* @__PURE__ */ h("div", { className: B.content, children: [
|
|
37
|
+
/* @__PURE__ */ h("div", { className: B.left, children: [
|
|
38
|
+
t && /* @__PURE__ */ n("div", { className: B.logo, children: t }),
|
|
39
|
+
e
|
|
40
|
+
] }),
|
|
41
|
+
/* @__PURE__ */ n("div", { className: B.right, children: s })
|
|
42
|
+
] }) }), Ne = "_footer_zjuj8_1", Se = "_content_zjuj8_7", Ae = "_defaultContent_zjuj8_13", xe = "_copyright_zjuj8_21", Te = "_disclaimer_zjuj8_26", P = {
|
|
43
|
+
footer: Ne,
|
|
44
|
+
content: Se,
|
|
45
|
+
defaultContent: Ae,
|
|
46
|
+
copyright: xe,
|
|
47
|
+
disclaimer: Te
|
|
48
|
+
}, fs = ({ children: t, className: e = "" }) => /* @__PURE__ */ n("footer", { className: `${P.footer} ${e}`, children: /* @__PURE__ */ n("div", { className: P.content, children: t || /* @__PURE__ */ h("div", { className: P.defaultContent, children: [
|
|
49
|
+
/* @__PURE__ */ h("p", { className: P.copyright, children: [
|
|
50
|
+
"© ",
|
|
51
|
+
(/* @__PURE__ */ new Date()).getFullYear(),
|
|
52
|
+
" The Astrogator's Table. All rights reserved."
|
|
53
|
+
] }),
|
|
54
|
+
/* @__PURE__ */ n("p", { className: P.disclaimer, children: "Star Wars: Galaxy of Heroes is a trademark of Electronic Arts Inc." })
|
|
55
|
+
] }) }) }), Ce = "_button_159ms_1", ke = "_sm_159ms_22", Ee = "_md_159ms_28", We = "_lg_159ms_34", Ie = "_primary_159ms_41", Le = "_secondary_159ms_55", qe = "_outline_159ms_69", Re = "_ghost_159ms_80", Be = "_danger_159ms_89", Pe = "_fullWidth_159ms_100", Ue = "_loading_159ms_105", je = "_loadingSpinner_159ms_110", De = "_spinner_159ms_116", Fe = "_spin_159ms_116", ze = "_loadingText_159ms_131", x = {
|
|
56
|
+
button: Ce,
|
|
57
|
+
sm: ke,
|
|
58
|
+
md: Ee,
|
|
59
|
+
lg: We,
|
|
60
|
+
primary: Ie,
|
|
61
|
+
secondary: Le,
|
|
62
|
+
outline: qe,
|
|
63
|
+
ghost: Re,
|
|
64
|
+
danger: Be,
|
|
65
|
+
fullWidth: Pe,
|
|
66
|
+
loading: Ue,
|
|
67
|
+
loadingSpinner: je,
|
|
68
|
+
spinner: De,
|
|
69
|
+
spin: Fe,
|
|
70
|
+
loadingText: ze
|
|
71
|
+
}, z = ({
|
|
72
|
+
children: t,
|
|
73
|
+
variant: e = "primary",
|
|
74
|
+
size: s = "md",
|
|
75
|
+
fullWidth: r = !1,
|
|
76
|
+
loading: d = !1,
|
|
77
|
+
disabled: u = !1,
|
|
78
|
+
className: l = "",
|
|
79
|
+
...i
|
|
80
|
+
}) => /* @__PURE__ */ n(
|
|
81
|
+
"button",
|
|
82
|
+
{
|
|
83
|
+
className: `${x.button} ${x[e]} ${x[s]} ${r ? x.fullWidth : ""} ${d ? x.loading : ""} ${l}`,
|
|
84
|
+
disabled: u || d,
|
|
85
|
+
...i,
|
|
86
|
+
children: d ? /* @__PURE__ */ h("span", { className: x.loadingSpinner, children: [
|
|
87
|
+
/* @__PURE__ */ n("span", { className: x.spinner }),
|
|
88
|
+
/* @__PURE__ */ n("span", { className: x.loadingText, children: t })
|
|
89
|
+
] }) : t
|
|
90
|
+
}
|
|
91
|
+
), Oe = "_inputWrapper_15t4g_1", Me = "_fullWidth_15t4g_7", Je = "_label_15t4g_11", He = "_required_15t4g_20", Ye = "_input_15t4g_1", Ge = "_error_15t4g_55", Ke = "_errorText_15t4g_63", Ve = "_helperText_15t4g_68", T = {
|
|
92
|
+
inputWrapper: Oe,
|
|
93
|
+
fullWidth: Me,
|
|
94
|
+
label: Je,
|
|
95
|
+
required: He,
|
|
96
|
+
input: Ye,
|
|
97
|
+
error: Ge,
|
|
98
|
+
errorText: Ke,
|
|
99
|
+
helperText: Ve
|
|
100
|
+
}, re = ne.forwardRef(
|
|
101
|
+
({
|
|
102
|
+
label: t,
|
|
103
|
+
error: e,
|
|
104
|
+
helperText: s,
|
|
105
|
+
fullWidth: r = !1,
|
|
106
|
+
className: d = "",
|
|
107
|
+
id: u,
|
|
108
|
+
...l
|
|
109
|
+
}, i) => {
|
|
110
|
+
const c = u || `input-${Math.random().toString(36).substr(2, 9)}`, p = !!e;
|
|
111
|
+
return /* @__PURE__ */ h("div", { className: `${T.inputWrapper} ${r ? T.fullWidth : ""} ${d}`, children: [
|
|
112
|
+
t && /* @__PURE__ */ h("label", { htmlFor: c, className: T.label, children: [
|
|
113
|
+
t,
|
|
114
|
+
l.required && /* @__PURE__ */ n("span", { className: T.required, children: "*" })
|
|
115
|
+
] }),
|
|
116
|
+
/* @__PURE__ */ n(
|
|
117
|
+
"input",
|
|
118
|
+
{
|
|
119
|
+
ref: i,
|
|
120
|
+
id: c,
|
|
121
|
+
className: `${T.input} ${p ? T.error : ""}`,
|
|
122
|
+
...l
|
|
123
|
+
}
|
|
124
|
+
),
|
|
125
|
+
e && /* @__PURE__ */ n("span", { className: T.errorText, children: e }),
|
|
126
|
+
s && !e && /* @__PURE__ */ n("span", { className: T.helperText, children: s })
|
|
127
|
+
] });
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
re.displayName = "Input";
|
|
131
|
+
const Qe = "_selectWrapper_ir4bq_1", Xe = "_fullWidth_ir4bq_7", Ze = "_label_ir4bq_11", et = "_required_ir4bq_20", tt = "_selectContainer_ir4bq_24", st = "_select_ir4bq_1", ot = "_error_ir4bq_63", nt = "_arrow_ir4bq_71", rt = "_errorText_ir4bq_81", at = "_helperText_ir4bq_86", w = {
|
|
132
|
+
selectWrapper: Qe,
|
|
133
|
+
fullWidth: Xe,
|
|
134
|
+
label: Ze,
|
|
135
|
+
required: et,
|
|
136
|
+
selectContainer: tt,
|
|
137
|
+
select: st,
|
|
138
|
+
error: ot,
|
|
139
|
+
arrow: nt,
|
|
140
|
+
errorText: rt,
|
|
141
|
+
helperText: at
|
|
142
|
+
}, ae = ne.forwardRef(
|
|
143
|
+
({
|
|
144
|
+
label: t,
|
|
145
|
+
error: e,
|
|
146
|
+
helperText: s,
|
|
147
|
+
options: r,
|
|
148
|
+
placeholder: d,
|
|
149
|
+
fullWidth: u = !1,
|
|
150
|
+
className: l = "",
|
|
151
|
+
id: i,
|
|
152
|
+
...c
|
|
153
|
+
}, p) => {
|
|
154
|
+
const f = i || `select-${Math.random().toString(36).substr(2, 9)}`, I = !!e;
|
|
155
|
+
return /* @__PURE__ */ h("div", { className: `${w.selectWrapper} ${u ? w.fullWidth : ""} ${l}`, children: [
|
|
156
|
+
t && /* @__PURE__ */ h("label", { htmlFor: f, className: w.label, children: [
|
|
157
|
+
t,
|
|
158
|
+
c.required && /* @__PURE__ */ n("span", { className: w.required, children: "*" })
|
|
159
|
+
] }),
|
|
160
|
+
/* @__PURE__ */ h("div", { className: w.selectContainer, children: [
|
|
161
|
+
/* @__PURE__ */ h(
|
|
162
|
+
"select",
|
|
163
|
+
{
|
|
164
|
+
ref: p,
|
|
165
|
+
id: f,
|
|
166
|
+
className: `${w.select} ${I ? w.error : ""}`,
|
|
167
|
+
...c,
|
|
168
|
+
children: [
|
|
169
|
+
d && /* @__PURE__ */ n("option", { value: "", disabled: !0, children: d }),
|
|
170
|
+
r.map((y) => /* @__PURE__ */ n(
|
|
171
|
+
"option",
|
|
172
|
+
{
|
|
173
|
+
value: y.value,
|
|
174
|
+
disabled: y.disabled,
|
|
175
|
+
children: y.label
|
|
176
|
+
},
|
|
177
|
+
y.value
|
|
178
|
+
))
|
|
179
|
+
]
|
|
180
|
+
}
|
|
181
|
+
),
|
|
182
|
+
/* @__PURE__ */ n("span", { className: w.arrow, children: "▼" })
|
|
183
|
+
] }),
|
|
184
|
+
e && /* @__PURE__ */ n("span", { className: w.errorText, children: e }),
|
|
185
|
+
s && !e && /* @__PURE__ */ n("span", { className: w.helperText, children: s })
|
|
186
|
+
] });
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
ae.displayName = "Select";
|
|
190
|
+
const ee = "astrogators_access_token", te = "astrogators_refresh_token", le = () => localStorage.getItem(ee), lt = (t) => {
|
|
191
|
+
localStorage.setItem(ee, t);
|
|
192
|
+
}, ct = () => {
|
|
193
|
+
localStorage.removeItem(ee);
|
|
194
|
+
}, it = () => localStorage.getItem(te), dt = (t) => {
|
|
195
|
+
localStorage.setItem(te, t);
|
|
196
|
+
}, _t = () => {
|
|
197
|
+
localStorage.removeItem(te);
|
|
198
|
+
}, ce = (t, e) => {
|
|
199
|
+
lt(t), dt(e);
|
|
200
|
+
}, Z = () => {
|
|
201
|
+
ct(), _t();
|
|
202
|
+
}, ut = () => !!le();
|
|
203
|
+
class mt {
|
|
204
|
+
constructor(e) {
|
|
205
|
+
R(this, "baseURL");
|
|
206
|
+
R(this, "onUnauthorized");
|
|
207
|
+
R(this, "isRefreshing", !1);
|
|
208
|
+
R(this, "refreshPromise", null);
|
|
209
|
+
this.baseURL = e.baseURL, this.onUnauthorized = e.onUnauthorized;
|
|
210
|
+
}
|
|
211
|
+
async refreshAccessToken() {
|
|
212
|
+
var d;
|
|
213
|
+
const e = it();
|
|
214
|
+
if (!e)
|
|
215
|
+
throw new Error("No refresh token available");
|
|
216
|
+
const s = await fetch(`${this.baseURL}/api/v1/auth/refresh-token`, {
|
|
217
|
+
method: "POST",
|
|
218
|
+
headers: {
|
|
219
|
+
"Content-Type": "application/json"
|
|
220
|
+
},
|
|
221
|
+
body: JSON.stringify({ refresh_token: e })
|
|
222
|
+
});
|
|
223
|
+
if (!s.ok)
|
|
224
|
+
throw Z(), (d = this.onUnauthorized) == null || d.call(this), new Error("Token refresh failed");
|
|
225
|
+
const r = await s.json();
|
|
226
|
+
return ce(r.access_token, e), r.access_token;
|
|
227
|
+
}
|
|
228
|
+
async request(e, s = {}) {
|
|
229
|
+
const r = le(), d = {
|
|
230
|
+
"Content-Type": "application/json",
|
|
231
|
+
...s.headers
|
|
232
|
+
};
|
|
233
|
+
r && (d.Authorization = `Bearer ${r}`);
|
|
234
|
+
const u = `${this.baseURL}${e}`;
|
|
235
|
+
let l = await fetch(u, {
|
|
236
|
+
...s,
|
|
237
|
+
headers: d
|
|
238
|
+
});
|
|
239
|
+
if (l.status === 401 && r) {
|
|
240
|
+
this.isRefreshing || (this.isRefreshing = !0, this.refreshPromise = this.refreshAccessToken().finally(() => {
|
|
241
|
+
this.isRefreshing = !1, this.refreshPromise = null;
|
|
242
|
+
}));
|
|
243
|
+
try {
|
|
244
|
+
const i = await this.refreshPromise;
|
|
245
|
+
d.Authorization = `Bearer ${i}`, l = await fetch(u, {
|
|
246
|
+
...s,
|
|
247
|
+
headers: d
|
|
248
|
+
});
|
|
249
|
+
} catch {
|
|
250
|
+
throw new Error("Authentication failed");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (!l.ok) {
|
|
254
|
+
const i = {
|
|
255
|
+
message: l.statusText,
|
|
256
|
+
status: l.status
|
|
257
|
+
};
|
|
258
|
+
try {
|
|
259
|
+
const c = await l.json();
|
|
260
|
+
if (l.status === 422 && Array.isArray(c.detail)) {
|
|
261
|
+
const p = c.detail.map((f) => f.msg || "Validation error").join(", ");
|
|
262
|
+
i.message = p;
|
|
263
|
+
} else typeof c.detail == "string" ? i.message = c.detail : c.message && (i.message = c.message);
|
|
264
|
+
i.detail = c.detail;
|
|
265
|
+
} catch {
|
|
266
|
+
}
|
|
267
|
+
throw i;
|
|
268
|
+
}
|
|
269
|
+
return l.status === 204 ? {} : l.json();
|
|
270
|
+
}
|
|
271
|
+
async get(e, s) {
|
|
272
|
+
return this.request(e, { ...s, method: "GET" });
|
|
273
|
+
}
|
|
274
|
+
async post(e, s, r) {
|
|
275
|
+
return this.request(e, {
|
|
276
|
+
...r,
|
|
277
|
+
method: "POST",
|
|
278
|
+
body: s ? JSON.stringify(s) : void 0
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
async put(e, s, r) {
|
|
282
|
+
return this.request(e, {
|
|
283
|
+
...r,
|
|
284
|
+
method: "PUT",
|
|
285
|
+
body: s ? JSON.stringify(s) : void 0
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
async patch(e, s, r) {
|
|
289
|
+
return this.request(e, {
|
|
290
|
+
...r,
|
|
291
|
+
method: "PATCH",
|
|
292
|
+
body: s ? JSON.stringify(s) : void 0
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
async delete(e, s) {
|
|
296
|
+
return this.request(e, { ...s, method: "DELETE" });
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
let g;
|
|
300
|
+
const ys = (t) => {
|
|
301
|
+
g = new mt(t);
|
|
302
|
+
}, U = "astrogators_ally_codes", H = "astrogators_selected_ally_code", N = () => {
|
|
303
|
+
try {
|
|
304
|
+
const t = localStorage.getItem(U);
|
|
305
|
+
return t ? JSON.parse(t) : [];
|
|
306
|
+
} catch (t) {
|
|
307
|
+
return console.error("Failed to read ally codes from localStorage:", t), [];
|
|
308
|
+
}
|
|
309
|
+
}, ht = (t) => {
|
|
310
|
+
try {
|
|
311
|
+
const e = N();
|
|
312
|
+
if (e.some((r) => r.ally_code === t.ally_code))
|
|
313
|
+
return;
|
|
314
|
+
e.push(t), localStorage.setItem(U, JSON.stringify(e));
|
|
315
|
+
} catch (e) {
|
|
316
|
+
console.error("Failed to save ally code to localStorage:", e);
|
|
317
|
+
}
|
|
318
|
+
}, gt = (t) => {
|
|
319
|
+
try {
|
|
320
|
+
const s = N().filter((r) => r.ally_code !== t);
|
|
321
|
+
localStorage.setItem(U, JSON.stringify(s));
|
|
322
|
+
} catch (e) {
|
|
323
|
+
console.error("Failed to remove ally code from localStorage:", e);
|
|
324
|
+
}
|
|
325
|
+
}, oe = (t) => {
|
|
326
|
+
try {
|
|
327
|
+
const s = N().map(
|
|
328
|
+
(r) => r.ally_code === t ? { ...r, last_used_at: (/* @__PURE__ */ new Date()).toISOString() } : r
|
|
329
|
+
);
|
|
330
|
+
localStorage.setItem(U, JSON.stringify(s));
|
|
331
|
+
} catch (e) {
|
|
332
|
+
console.error("Failed to update ally code last used:", e);
|
|
333
|
+
}
|
|
334
|
+
}, pt = () => localStorage.getItem(H), ft = (t) => {
|
|
335
|
+
t ? localStorage.setItem(H, t) : localStorage.removeItem(H);
|
|
336
|
+
}, yt = () => {
|
|
337
|
+
localStorage.removeItem(U), localStorage.removeItem(H);
|
|
338
|
+
}, ie = he(void 0), vs = ({ children: t }) => {
|
|
339
|
+
const [e, s] = $(null), [r, d] = $(!0), [u, l] = $([]), [i, c] = $(null), [p, f] = $(!1), [I, y] = $({
|
|
340
|
+
show: !1,
|
|
341
|
+
localStorageCodes: []
|
|
342
|
+
}), k = A(async () => {
|
|
343
|
+
if (!ut()) {
|
|
344
|
+
s(null), d(!1);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
try {
|
|
348
|
+
const o = await g.get("/api/v1/users/me");
|
|
349
|
+
s(o);
|
|
350
|
+
} catch (o) {
|
|
351
|
+
console.error("Failed to fetch user:", o), s(null), Z();
|
|
352
|
+
} finally {
|
|
353
|
+
d(!1);
|
|
354
|
+
}
|
|
355
|
+
}, []);
|
|
356
|
+
J(() => {
|
|
357
|
+
k();
|
|
358
|
+
}, [k]);
|
|
359
|
+
const j = async (o) => {
|
|
360
|
+
try {
|
|
361
|
+
const a = await g.post("/api/v1/auth/login", o);
|
|
362
|
+
ce(a.access_token, a.refresh_token);
|
|
363
|
+
const m = await g.get("/api/v1/users/me");
|
|
364
|
+
s(m);
|
|
365
|
+
} catch (a) {
|
|
366
|
+
throw console.error("Login failed:", a), a;
|
|
367
|
+
}
|
|
368
|
+
}, L = async (o) => {
|
|
369
|
+
try {
|
|
370
|
+
await g.post("/api/v1/auth/register", o);
|
|
371
|
+
} catch (a) {
|
|
372
|
+
throw console.error("Registration failed:", a), a;
|
|
373
|
+
}
|
|
374
|
+
}, D = () => {
|
|
375
|
+
Z(), s(null), l([]), c(null), y({ show: !1, localStorageCodes: [] });
|
|
376
|
+
}, F = async () => {
|
|
377
|
+
await k();
|
|
378
|
+
}, Y = async (o) => {
|
|
379
|
+
try {
|
|
380
|
+
return (await g.post(
|
|
381
|
+
"/api/v1/auth/forgot-password",
|
|
382
|
+
o
|
|
383
|
+
)).message;
|
|
384
|
+
} catch (a) {
|
|
385
|
+
throw console.error("Forgot password failed:", a), a;
|
|
386
|
+
}
|
|
387
|
+
}, G = async (o) => {
|
|
388
|
+
try {
|
|
389
|
+
return (await g.post(
|
|
390
|
+
"/api/v1/auth/reset-password",
|
|
391
|
+
o
|
|
392
|
+
)).message;
|
|
393
|
+
} catch (a) {
|
|
394
|
+
throw console.error("Reset password failed:", a), a;
|
|
395
|
+
}
|
|
396
|
+
}, K = async (o) => {
|
|
397
|
+
try {
|
|
398
|
+
return (await g.post(
|
|
399
|
+
"/api/v1/auth/resend-verification",
|
|
400
|
+
o
|
|
401
|
+
)).message;
|
|
402
|
+
} catch (a) {
|
|
403
|
+
throw console.error("Resend verification failed:", a), a;
|
|
404
|
+
}
|
|
405
|
+
}, E = A(async () => {
|
|
406
|
+
f(!0);
|
|
407
|
+
try {
|
|
408
|
+
if (e) {
|
|
409
|
+
const a = await g.get("/api/v1/users/me/ally-codes");
|
|
410
|
+
l(a.ally_codes);
|
|
411
|
+
const m = N();
|
|
412
|
+
m.length > 0 && y({
|
|
413
|
+
show: !0,
|
|
414
|
+
localStorageCodes: m.map((q) => q.ally_code)
|
|
415
|
+
});
|
|
416
|
+
} else {
|
|
417
|
+
const a = N();
|
|
418
|
+
l(a);
|
|
419
|
+
}
|
|
420
|
+
const o = pt();
|
|
421
|
+
c(o);
|
|
422
|
+
} catch (o) {
|
|
423
|
+
console.error("Failed to fetch ally codes:", o), l([]);
|
|
424
|
+
} finally {
|
|
425
|
+
f(!1);
|
|
426
|
+
}
|
|
427
|
+
}, [e]), _ = A(async (o) => {
|
|
428
|
+
var a;
|
|
429
|
+
if (!/^\d{9}$/.test(o))
|
|
430
|
+
throw new Error("Ally code must be exactly 9 digits");
|
|
431
|
+
if (e) {
|
|
432
|
+
const m = await g.post(
|
|
433
|
+
"/api/v1/users/me/ally-codes",
|
|
434
|
+
{ ally_code: o }
|
|
435
|
+
);
|
|
436
|
+
l((q) => [m, ...q]), u.length === 0 && S(o);
|
|
437
|
+
} else {
|
|
438
|
+
const m = await g.get(`/api/v1/player-data/player/${o}`);
|
|
439
|
+
if (!m)
|
|
440
|
+
throw new Error("Invalid ally code - player not found");
|
|
441
|
+
const q = {
|
|
442
|
+
ally_code: o,
|
|
443
|
+
player_name: ((a = m == null ? void 0 : m.data) == null ? void 0 : a.name) || null,
|
|
444
|
+
last_used_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
445
|
+
};
|
|
446
|
+
ht(q), l(N()), u.length === 0 && S(o);
|
|
447
|
+
}
|
|
448
|
+
}, [e, u.length]), b = A(async (o) => {
|
|
449
|
+
e && typeof o == "number" ? (await g.delete(`/api/v1/users/me/ally-codes/${o}`), l((a) => a.filter((m) => "id" in m && m.id !== o))) : !e && typeof o == "string" && (gt(o), l(N()), i === o && S(null));
|
|
450
|
+
}, [e, i]), S = A((o) => {
|
|
451
|
+
if (c(o), ft(o), o && e) {
|
|
452
|
+
const a = u.find((m) => "ally_code" in m && m.ally_code === o);
|
|
453
|
+
a && "id" in a && se(a.id);
|
|
454
|
+
} else o && !e && oe(o);
|
|
455
|
+
}, [e, u]), se = A(async (o) => {
|
|
456
|
+
e && typeof o == "number" ? (await g.put(`/api/v1/users/me/ally-codes/${o}/use`, {}), await E()) : !e && typeof o == "string" && (oe(o), l(N()));
|
|
457
|
+
}, [e, E]), V = A(() => {
|
|
458
|
+
y({ show: !1, localStorageCodes: [] });
|
|
459
|
+
}, []), de = A(async () => {
|
|
460
|
+
if (!e) return;
|
|
461
|
+
const o = N();
|
|
462
|
+
for (const a of o)
|
|
463
|
+
try {
|
|
464
|
+
await _(a.ally_code);
|
|
465
|
+
} catch (m) {
|
|
466
|
+
console.error(`Failed to migrate ally code ${a.ally_code}:`, m);
|
|
467
|
+
}
|
|
468
|
+
yt(), V();
|
|
469
|
+
}, [e, _, V]);
|
|
470
|
+
J(() => {
|
|
471
|
+
E();
|
|
472
|
+
}, [E]);
|
|
473
|
+
const _e = {
|
|
474
|
+
user: e,
|
|
475
|
+
isAuthenticated: !!e,
|
|
476
|
+
isLoading: r,
|
|
477
|
+
login: j,
|
|
478
|
+
register: L,
|
|
479
|
+
logout: D,
|
|
480
|
+
refreshUser: F,
|
|
481
|
+
forgotPassword: Y,
|
|
482
|
+
resetPassword: G,
|
|
483
|
+
resendVerification: K,
|
|
484
|
+
// Ally code values
|
|
485
|
+
allyCodes: u,
|
|
486
|
+
selectedAllyCode: i,
|
|
487
|
+
isLoadingAllyCodes: p,
|
|
488
|
+
fetchAllyCodes: E,
|
|
489
|
+
addAllyCode: _,
|
|
490
|
+
removeAllyCode: b,
|
|
491
|
+
selectAllyCode: S,
|
|
492
|
+
updateAllyCodeLastUsed: se,
|
|
493
|
+
migrationPrompt: I,
|
|
494
|
+
dismissMigrationPrompt: V,
|
|
495
|
+
migrateLocalStorageCodes: de
|
|
496
|
+
};
|
|
497
|
+
return /* @__PURE__ */ n(ie.Provider, { value: _e, children: t });
|
|
498
|
+
}, vt = () => {
|
|
499
|
+
const t = ge(ie);
|
|
500
|
+
if (t === void 0)
|
|
501
|
+
throw new Error("useAuth must be used within an AuthProvider");
|
|
502
|
+
return t;
|
|
503
|
+
}, O = (t) => !t || t.length !== 9 ? t : `${t.slice(0, 3)}-${t.slice(3, 6)}-${t.slice(6, 9)}`, $s = (t) => t.replace(/-/g, ""), $t = "_allyCodeDropdown_1m0tw_1", wt = "_select_1m0tw_8", bt = "_manageButton_1m0tw_12", Nt = "_managePanel_1m0tw_16", St = "_addSection_1m0tw_37", At = "_addInputGroup_1m0tw_43", xt = "_error_1m0tw_55", Tt = "_success_1m0tw_61", Ct = "_codesList_1m0tw_67", kt = "_codeItem_1m0tw_71", Et = "_doneButton_1m0tw_88", v = {
|
|
504
|
+
allyCodeDropdown: $t,
|
|
505
|
+
select: wt,
|
|
506
|
+
manageButton: bt,
|
|
507
|
+
managePanel: Nt,
|
|
508
|
+
addSection: St,
|
|
509
|
+
addInputGroup: At,
|
|
510
|
+
error: xt,
|
|
511
|
+
success: Tt,
|
|
512
|
+
codesList: Ct,
|
|
513
|
+
codeItem: kt,
|
|
514
|
+
doneButton: Et
|
|
515
|
+
}, ws = ({
|
|
516
|
+
onAllyCodeSelected: t,
|
|
517
|
+
className: e = ""
|
|
518
|
+
}) => {
|
|
519
|
+
const {
|
|
520
|
+
allyCodes: s,
|
|
521
|
+
selectedAllyCode: r,
|
|
522
|
+
selectAllyCode: d,
|
|
523
|
+
removeAllyCode: u,
|
|
524
|
+
addAllyCode: l,
|
|
525
|
+
isLoadingAllyCodes: i
|
|
526
|
+
} = vt(), [c, p] = $(!1), [f, I] = $(""), [y, k] = $(""), [j, L] = $(""), [D, F] = $(!1), Y = s.map((_) => ({
|
|
527
|
+
value: _.ally_code,
|
|
528
|
+
label: _.player_name ? `${_.player_name} (${O(_.ally_code)})` : O(_.ally_code)
|
|
529
|
+
})), G = (_) => {
|
|
530
|
+
const b = _.target.value || null;
|
|
531
|
+
d(b), t == null || t(b);
|
|
532
|
+
}, K = async (_) => {
|
|
533
|
+
const b = s.find((S) => S.ally_code === _);
|
|
534
|
+
if (b) {
|
|
535
|
+
const S = "id" in b ? b.id : b.ally_code;
|
|
536
|
+
await u(S);
|
|
537
|
+
}
|
|
538
|
+
}, E = async () => {
|
|
539
|
+
if (k(""), L(""), !/^\d{9}$/.test(f)) {
|
|
540
|
+
k("Ally code must be exactly 9 digits");
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
F(!0);
|
|
544
|
+
try {
|
|
545
|
+
await l(f), L("Added successfully!"), I(""), setTimeout(() => L(""), 2e3);
|
|
546
|
+
} catch (_) {
|
|
547
|
+
k(_.message || "Failed to add ally code");
|
|
548
|
+
} finally {
|
|
549
|
+
F(!1);
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
return s.length === 0 ? null : /* @__PURE__ */ h("div", { className: `${v.allyCodeDropdown} ${e}`, children: [
|
|
553
|
+
/* @__PURE__ */ n(
|
|
554
|
+
ae,
|
|
555
|
+
{
|
|
556
|
+
options: Y,
|
|
557
|
+
value: r || "",
|
|
558
|
+
onChange: G,
|
|
559
|
+
placeholder: "Select ally code",
|
|
560
|
+
disabled: i,
|
|
561
|
+
className: v.select
|
|
562
|
+
}
|
|
563
|
+
),
|
|
564
|
+
c && /* @__PURE__ */ h("div", { className: v.managePanel, children: [
|
|
565
|
+
/* @__PURE__ */ n("h4", { children: "Manage Ally Codes" }),
|
|
566
|
+
/* @__PURE__ */ h("div", { className: v.addSection, children: [
|
|
567
|
+
/* @__PURE__ */ h("div", { className: v.addInputGroup, children: [
|
|
568
|
+
/* @__PURE__ */ n(
|
|
569
|
+
re,
|
|
570
|
+
{
|
|
571
|
+
type: "text",
|
|
572
|
+
placeholder: "9-digit ally code",
|
|
573
|
+
value: f,
|
|
574
|
+
onChange: (_) => I(_.target.value.replace(/\D/g, "").slice(0, 9)),
|
|
575
|
+
disabled: D
|
|
576
|
+
}
|
|
577
|
+
),
|
|
578
|
+
/* @__PURE__ */ n(
|
|
579
|
+
z,
|
|
580
|
+
{
|
|
581
|
+
variant: "primary",
|
|
582
|
+
size: "sm",
|
|
583
|
+
onClick: E,
|
|
584
|
+
loading: D,
|
|
585
|
+
disabled: f.length !== 9,
|
|
586
|
+
children: "Add"
|
|
587
|
+
}
|
|
588
|
+
)
|
|
589
|
+
] }),
|
|
590
|
+
y && /* @__PURE__ */ n("div", { className: v.error, children: y }),
|
|
591
|
+
j && /* @__PURE__ */ n("div", { className: v.success, children: j })
|
|
592
|
+
] }),
|
|
593
|
+
/* @__PURE__ */ n("div", { className: v.codesList, children: s.map((_) => /* @__PURE__ */ h("div", { className: v.codeItem, children: [
|
|
594
|
+
/* @__PURE__ */ n("span", { children: _.player_name ? `${_.player_name} (${O(_.ally_code)})` : O(_.ally_code) }),
|
|
595
|
+
/* @__PURE__ */ n(
|
|
596
|
+
z,
|
|
597
|
+
{
|
|
598
|
+
variant: "ghost",
|
|
599
|
+
size: "sm",
|
|
600
|
+
onClick: () => K(_.ally_code),
|
|
601
|
+
children: "Remove"
|
|
602
|
+
}
|
|
603
|
+
)
|
|
604
|
+
] }, _.ally_code)) }),
|
|
605
|
+
/* @__PURE__ */ n(
|
|
606
|
+
z,
|
|
607
|
+
{
|
|
608
|
+
variant: "secondary",
|
|
609
|
+
size: "sm",
|
|
610
|
+
onClick: () => p(!1),
|
|
611
|
+
className: v.doneButton,
|
|
612
|
+
children: "Done"
|
|
613
|
+
}
|
|
614
|
+
)
|
|
615
|
+
] }),
|
|
616
|
+
/* @__PURE__ */ n(
|
|
617
|
+
z,
|
|
618
|
+
{
|
|
619
|
+
variant: "ghost",
|
|
620
|
+
size: "sm",
|
|
621
|
+
onClick: () => p(!c),
|
|
622
|
+
className: v.manageButton,
|
|
623
|
+
children: "Manage"
|
|
624
|
+
}
|
|
625
|
+
)
|
|
626
|
+
] });
|
|
627
|
+
}, Wt = "_card_1n0ll_1", It = "_elevated_1n0ll_12", Lt = "_outline_1n0ll_17", qt = "_hoverable_1n0ll_40", M = {
|
|
628
|
+
card: Wt,
|
|
629
|
+
default: "_default_1n0ll_8",
|
|
630
|
+
elevated: It,
|
|
631
|
+
outline: Lt,
|
|
632
|
+
"padding-none": "_padding-none_1n0ll_23",
|
|
633
|
+
"padding-sm": "_padding-sm_1n0ll_27",
|
|
634
|
+
"padding-md": "_padding-md_1n0ll_31",
|
|
635
|
+
"padding-lg": "_padding-lg_1n0ll_35",
|
|
636
|
+
hoverable: qt
|
|
637
|
+
}, bs = ({
|
|
638
|
+
children: t,
|
|
639
|
+
variant: e = "default",
|
|
640
|
+
chamfered: s = !1,
|
|
641
|
+
chamferSize: r = "md",
|
|
642
|
+
padding: d = "md",
|
|
643
|
+
hoverable: u = !1,
|
|
644
|
+
className: l = "",
|
|
645
|
+
onClick: i
|
|
646
|
+
}) => {
|
|
647
|
+
const c = s ? r === "sm" ? "chamfered-box-sm" : r === "lg" ? "chamfered-box-lg" : "chamfered-box" : "";
|
|
648
|
+
return /* @__PURE__ */ n(
|
|
649
|
+
"div",
|
|
650
|
+
{
|
|
651
|
+
className: `${M.card} ${M[e]} ${M[`padding-${d}`]} ${c} ${u ? M.hoverable : ""} ${l}`,
|
|
652
|
+
onClick: i,
|
|
653
|
+
role: i ? "button" : void 0,
|
|
654
|
+
tabIndex: i ? 0 : void 0,
|
|
655
|
+
children: t
|
|
656
|
+
}
|
|
657
|
+
);
|
|
658
|
+
}, Rt = "_badge_rk7t5_1", Bt = "_sm_rk7t5_11", Pt = "_md_rk7t5_16", Ut = "_lg_rk7t5_21", jt = "_primary_rk7t5_32", Dt = "_secondary_rk7t5_37", Ft = "_success_rk7t5_42", zt = "_warning_rk7t5_47", Ot = "_error_rk7t5_52", Mt = "_info_rk7t5_57", X = {
|
|
659
|
+
badge: Rt,
|
|
660
|
+
sm: Bt,
|
|
661
|
+
md: Pt,
|
|
662
|
+
lg: Ut,
|
|
663
|
+
default: "_default_rk7t5_27",
|
|
664
|
+
primary: jt,
|
|
665
|
+
secondary: Dt,
|
|
666
|
+
success: Ft,
|
|
667
|
+
warning: zt,
|
|
668
|
+
error: Ot,
|
|
669
|
+
info: Mt
|
|
670
|
+
}, Ns = ({
|
|
671
|
+
children: t,
|
|
672
|
+
variant: e = "default",
|
|
673
|
+
size: s = "md",
|
|
674
|
+
className: r = ""
|
|
675
|
+
}) => /* @__PURE__ */ n("span", { className: `${X.badge} ${X[e]} ${X[s]} ${r}`, children: t }), Jt = "_overlay_1b3yt_1", Ht = "_fadeIn_1b3yt_1", Yt = "_modal_1b3yt_13", Gt = "_slideUp_1b3yt_1", Kt = "_sm_1b3yt_25", Vt = "_md_1b3yt_30", Qt = "_lg_1b3yt_35", Xt = "_xl_1b3yt_40", Zt = "_header_1b3yt_45", es = "_title_1b3yt_53", ts = "_closeButton_1b3yt_60", ss = "_content_1b3yt_78", W = {
|
|
676
|
+
overlay: Jt,
|
|
677
|
+
fadeIn: Ht,
|
|
678
|
+
modal: Yt,
|
|
679
|
+
slideUp: Gt,
|
|
680
|
+
sm: Kt,
|
|
681
|
+
md: Vt,
|
|
682
|
+
lg: Qt,
|
|
683
|
+
xl: Xt,
|
|
684
|
+
header: Zt,
|
|
685
|
+
title: es,
|
|
686
|
+
closeButton: ts,
|
|
687
|
+
content: ss
|
|
688
|
+
}, Ss = ({
|
|
689
|
+
isOpen: t,
|
|
690
|
+
onClose: e,
|
|
691
|
+
title: s,
|
|
692
|
+
children: r,
|
|
693
|
+
size: d = "md",
|
|
694
|
+
closeOnOverlayClick: u = !0,
|
|
695
|
+
className: l = ""
|
|
696
|
+
}) => {
|
|
697
|
+
if (J(() => (t ? document.body.style.overflow = "hidden" : document.body.style.overflow = "unset", () => {
|
|
698
|
+
document.body.style.overflow = "unset";
|
|
699
|
+
}), [t]), J(() => {
|
|
700
|
+
const c = (p) => {
|
|
701
|
+
p.key === "Escape" && t && e();
|
|
702
|
+
};
|
|
703
|
+
return document.addEventListener("keydown", c), () => document.removeEventListener("keydown", c);
|
|
704
|
+
}, [t, e]), !t) return null;
|
|
705
|
+
const i = (c) => {
|
|
706
|
+
u && c.target === c.currentTarget && e();
|
|
707
|
+
};
|
|
708
|
+
return /* @__PURE__ */ n("div", { className: W.overlay, onClick: i, children: /* @__PURE__ */ h("div", { className: `${W.modal} ${W[d]} ${l}`, role: "dialog", "aria-modal": "true", children: [
|
|
709
|
+
s && /* @__PURE__ */ h("div", { className: W.header, children: [
|
|
710
|
+
/* @__PURE__ */ n("h2", { className: W.title, children: s }),
|
|
711
|
+
/* @__PURE__ */ n("button", { className: W.closeButton, onClick: e, "aria-label": "Close modal", children: "✕" })
|
|
712
|
+
] }),
|
|
713
|
+
/* @__PURE__ */ n("div", { className: W.content, children: r })
|
|
714
|
+
] }) });
|
|
715
|
+
}, os = "_spinner_1uhnh_2", ns = "_spin_1uhnh_2", rs = "_sm_1uhnh_9", as = "_md_1uhnh_15", ls = "_lg_1uhnh_21", cs = "_dots_1uhnh_34", is = "_dot_1uhnh_34", ds = "_bounce_1uhnh_1", _s = "_visuallyHidden_1uhnh_91", C = {
|
|
716
|
+
spinner: os,
|
|
717
|
+
spin: ns,
|
|
718
|
+
sm: rs,
|
|
719
|
+
md: as,
|
|
720
|
+
lg: ls,
|
|
721
|
+
dots: cs,
|
|
722
|
+
dot: is,
|
|
723
|
+
bounce: ds,
|
|
724
|
+
visuallyHidden: _s
|
|
725
|
+
}, As = ({
|
|
726
|
+
size: t = "md",
|
|
727
|
+
variant: e = "spinner",
|
|
728
|
+
className: s = ""
|
|
729
|
+
}) => e === "dots" ? /* @__PURE__ */ h("div", { className: `${C.dots} ${C[t]} ${s}`, children: [
|
|
730
|
+
/* @__PURE__ */ n("span", { className: C.dot }),
|
|
731
|
+
/* @__PURE__ */ n("span", { className: C.dot }),
|
|
732
|
+
/* @__PURE__ */ n("span", { className: C.dot })
|
|
733
|
+
] }) : /* @__PURE__ */ n("div", { className: `${C.spinner} ${C[t]} ${s}`, role: "status", children: /* @__PURE__ */ n("span", { className: C.visuallyHidden, children: "Loading..." }) });
|
|
734
|
+
export {
|
|
735
|
+
ws as AllyCodeDropdown,
|
|
736
|
+
mt as ApiClient,
|
|
737
|
+
vs as AuthProvider,
|
|
738
|
+
Ns as Badge,
|
|
739
|
+
z as Button,
|
|
740
|
+
bs as Card,
|
|
741
|
+
gs as Container,
|
|
742
|
+
fs as Footer,
|
|
743
|
+
re as Input,
|
|
744
|
+
As as Loader,
|
|
745
|
+
Ss as Modal,
|
|
746
|
+
ae as Select,
|
|
747
|
+
ps as TopBar,
|
|
748
|
+
g as apiClient,
|
|
749
|
+
yt as clearAllyCodes,
|
|
750
|
+
Z as clearTokens,
|
|
751
|
+
O as formatAllyCode,
|
|
752
|
+
le as getAccessToken,
|
|
753
|
+
N as getAllyCodesFromStorage,
|
|
754
|
+
it as getRefreshToken,
|
|
755
|
+
pt as getSelectedAllyCode,
|
|
756
|
+
ys as initializeApiClient,
|
|
757
|
+
ut as isAuthenticated,
|
|
758
|
+
ct as removeAccessToken,
|
|
759
|
+
gt as removeAllyCodeFromStorage,
|
|
760
|
+
_t as removeRefreshToken,
|
|
761
|
+
ht as saveAllyCodeToStorage,
|
|
762
|
+
lt as setAccessToken,
|
|
763
|
+
dt as setRefreshToken,
|
|
764
|
+
ft as setSelectedAllyCode,
|
|
765
|
+
ce as setTokens,
|
|
766
|
+
$s as unformatAllyCode,
|
|
767
|
+
oe as updateAllyCodeLastUsed,
|
|
768
|
+
vt as useAuth
|
|
769
|
+
};
|