@ampless/admin 0.2.0-alpha.1 → 0.2.0-alpha.11
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/dist/api/index.d.ts +1 -1
- package/dist/chunk-2ITWLRYF.js +38 -0
- package/dist/chunk-4YEBIBFG.js +48 -0
- package/dist/chunk-5OIPGVGG.js +198 -0
- package/dist/chunk-7IJDOT2K.js +1197 -0
- package/dist/chunk-7IR4F7GA.js +6 -0
- package/dist/chunk-BFZODSUT.js +71 -0
- package/dist/chunk-BYLCQYEQ.js +21 -0
- package/dist/chunk-GDQC5X46.js +250 -0
- package/dist/chunk-OFHKZNZS.js +33 -0
- package/dist/{chunk-TJR3ALRJ.js → chunk-OPQ3SAZJ.js} +75 -66
- package/dist/chunk-QVUTNQZH.js +21 -0
- package/dist/chunk-TZWSXAHD.js +32 -0
- package/dist/chunk-UOU7KQLR.js +149 -0
- package/dist/chunk-VXEVLHGL.js +10 -0
- package/dist/chunk-XHWECTED.js +1125 -0
- package/dist/chunk-XXJDT6FF.js +335 -0
- package/dist/chunk-XZQRPXKN.js +41 -0
- package/dist/components/admin-dashboard.d.ts +10 -0
- package/dist/components/admin-dashboard.js +9 -0
- package/dist/components/edit-post-view.d.ts +9 -0
- package/dist/components/edit-post-view.js +14 -0
- package/dist/components/index.d.ts +32 -19
- package/dist/components/index.js +33 -15
- package/dist/components/login-view.d.ts +5 -0
- package/dist/components/login-view.js +9 -0
- package/dist/components/media-view.d.ts +5 -0
- package/dist/components/media-view.js +12 -0
- package/dist/components/new-post-view.d.ts +5 -0
- package/dist/components/new-post-view.js +14 -0
- package/dist/components/posts-list-view.d.ts +5 -0
- package/dist/components/posts-list-view.js +11 -0
- package/dist/components/users-list-view.d.ts +7 -0
- package/dist/components/users-list-view.js +9 -0
- package/dist/{i18n-ByHM_Bho.d.ts → i18n-DzXXcIQQ.d.ts} +110 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -3
- package/dist/lib/theme-actions.d.ts +17 -0
- package/dist/lib/theme-actions.js +7 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/pages/index.d.ts +49 -15
- package/dist/pages/index.js +114 -658
- package/package.json +10 -9
- package/dist/chunk-T2RSMFOI.js +0 -2074
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
useT
|
|
4
|
+
} from "./chunk-OFHKZNZS.js";
|
|
5
|
+
|
|
6
|
+
// src/components/users-list-view.tsx
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
import { generateClient } from "aws-amplify/api";
|
|
9
|
+
import {
|
|
10
|
+
Button,
|
|
11
|
+
Table,
|
|
12
|
+
TableBody,
|
|
13
|
+
TableCell,
|
|
14
|
+
TableHead,
|
|
15
|
+
TableHeader,
|
|
16
|
+
TableRow
|
|
17
|
+
} from "@ampless/runtime/ui";
|
|
18
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
function isAdminRole(value) {
|
|
20
|
+
return value === "admin" || value === "editor" || value === "none";
|
|
21
|
+
}
|
|
22
|
+
function UsersListView({ currentUserId }) {
|
|
23
|
+
const t = useT();
|
|
24
|
+
const [users, setUsers] = useState(null);
|
|
25
|
+
const [loading, setLoading] = useState(true);
|
|
26
|
+
const [loadError, setLoadError] = useState(null);
|
|
27
|
+
const [rows, setRows] = useState({});
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const client = generateClient();
|
|
30
|
+
client.queries.listAdminUsers().then(({ data, errors }) => {
|
|
31
|
+
if (errors && errors.length > 0) {
|
|
32
|
+
const msg = errors[0]?.message ?? "listAdminUsers failed";
|
|
33
|
+
console.error("[users-list-view] listAdminUsers errors:", errors);
|
|
34
|
+
setLoadError(msg);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const list = data ?? [];
|
|
38
|
+
setUsers(list);
|
|
39
|
+
setRows(
|
|
40
|
+
Object.fromEntries(
|
|
41
|
+
list.map((u) => [u.userId, { selected: u.role, saving: false, error: null }])
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
}).catch((err) => {
|
|
45
|
+
console.error("[users-list-view] listAdminUsers threw:", err);
|
|
46
|
+
setLoadError(err instanceof Error ? err.message : String(err));
|
|
47
|
+
}).finally(() => setLoading(false));
|
|
48
|
+
}, []);
|
|
49
|
+
function updateRow(userId, patch) {
|
|
50
|
+
setRows((prev) => ({
|
|
51
|
+
...prev,
|
|
52
|
+
[userId]: { ...prev[userId], ...patch }
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
async function save(userId) {
|
|
56
|
+
const row = rows[userId];
|
|
57
|
+
if (!row) return;
|
|
58
|
+
updateRow(userId, { saving: true, error: null });
|
|
59
|
+
try {
|
|
60
|
+
const client = generateClient();
|
|
61
|
+
const { data, errors } = await client.mutations.setAdminUserRole({
|
|
62
|
+
userId,
|
|
63
|
+
role: row.selected
|
|
64
|
+
});
|
|
65
|
+
if (errors && errors.length > 0) {
|
|
66
|
+
const msg = errors[0]?.message ?? "setAdminUserRole failed";
|
|
67
|
+
console.error("[users-list-view] setAdminUserRole errors:", errors);
|
|
68
|
+
updateRow(userId, { saving: false, error: msg });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (data) {
|
|
72
|
+
setUsers(
|
|
73
|
+
(prev) => (prev ?? []).map((u) => u.userId === userId ? data : u)
|
|
74
|
+
);
|
|
75
|
+
updateRow(userId, { saving: false, selected: data.role, error: null });
|
|
76
|
+
} else {
|
|
77
|
+
updateRow(userId, { saving: false });
|
|
78
|
+
}
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.error("[users-list-view] setAdminUserRole threw:", err);
|
|
81
|
+
updateRow(userId, {
|
|
82
|
+
saving: false,
|
|
83
|
+
error: err instanceof Error ? err.message : String(err)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return /* @__PURE__ */ jsxs("div", { className: "mx-auto max-w-7xl p-4 md:p-8", children: [
|
|
88
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-6 md:mb-8", children: [
|
|
89
|
+
/* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold md:text-3xl", children: t("users.list.title") }),
|
|
90
|
+
/* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: t("users.list.description") })
|
|
91
|
+
] }),
|
|
92
|
+
loading ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("users.list.loading") }) : loadError ? /* @__PURE__ */ jsxs("p", { className: "text-sm text-destructive", children: [
|
|
93
|
+
t("users.list.error"),
|
|
94
|
+
": ",
|
|
95
|
+
loadError
|
|
96
|
+
] }) : !users || users.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("users.list.empty") }) : /* @__PURE__ */ jsx("div", { className: "overflow-x-auto rounded-md border", children: /* @__PURE__ */ jsxs(Table, { children: [
|
|
97
|
+
/* @__PURE__ */ jsx(TableHeader, { children: /* @__PURE__ */ jsxs(TableRow, { children: [
|
|
98
|
+
/* @__PURE__ */ jsx(TableHead, { children: t("users.list.columnEmail") }),
|
|
99
|
+
/* @__PURE__ */ jsx(TableHead, { children: t("users.list.columnRole") }),
|
|
100
|
+
/* @__PURE__ */ jsx(TableHead, { className: "w-[1%] whitespace-nowrap", children: t("users.list.columnActions") })
|
|
101
|
+
] }) }),
|
|
102
|
+
/* @__PURE__ */ jsx(TableBody, { children: users.map((u) => {
|
|
103
|
+
const row = rows[u.userId];
|
|
104
|
+
if (!row) return null;
|
|
105
|
+
const isSelf = u.userId === currentUserId;
|
|
106
|
+
const dirty = row.selected !== u.role;
|
|
107
|
+
return /* @__PURE__ */ jsxs(TableRow, { children: [
|
|
108
|
+
/* @__PURE__ */ jsx(TableCell, { className: "font-medium", children: u.email || u.userId }),
|
|
109
|
+
/* @__PURE__ */ jsxs(TableCell, { children: [
|
|
110
|
+
/* @__PURE__ */ jsxs(
|
|
111
|
+
"select",
|
|
112
|
+
{
|
|
113
|
+
className: "rounded-md border bg-background px-2 py-1.5 text-sm disabled:cursor-not-allowed disabled:opacity-60",
|
|
114
|
+
value: row.selected,
|
|
115
|
+
disabled: isSelf || row.saving,
|
|
116
|
+
onChange: (e) => {
|
|
117
|
+
const next = e.target.value;
|
|
118
|
+
if (isAdminRole(next)) {
|
|
119
|
+
updateRow(u.userId, { selected: next });
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
children: [
|
|
123
|
+
/* @__PURE__ */ jsx("option", { value: "admin", children: t("users.list.roleAdmin") }),
|
|
124
|
+
/* @__PURE__ */ jsx("option", { value: "editor", children: t("users.list.roleEditor") }),
|
|
125
|
+
/* @__PURE__ */ jsx("option", { value: "none", children: t("users.list.roleNone") })
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
),
|
|
129
|
+
isSelf && /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: t("users.list.cannotEditSelf") }),
|
|
130
|
+
row.error && /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-destructive", children: row.error })
|
|
131
|
+
] }),
|
|
132
|
+
/* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(
|
|
133
|
+
Button,
|
|
134
|
+
{
|
|
135
|
+
size: "sm",
|
|
136
|
+
disabled: isSelf || row.saving || !dirty,
|
|
137
|
+
onClick: () => save(u.userId),
|
|
138
|
+
children: row.saving ? t("users.list.saving") : t("users.list.save")
|
|
139
|
+
}
|
|
140
|
+
) })
|
|
141
|
+
] }, u.userId);
|
|
142
|
+
}) })
|
|
143
|
+
] }) })
|
|
144
|
+
] });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export {
|
|
148
|
+
UsersListView
|
|
149
|
+
};
|