@byline/admin 2.4.0 → 2.4.2

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.
Files changed (177) hide show
  1. package/dist/abilities.js +5 -24
  2. package/dist/index.js +8 -30
  3. package/dist/lib/assert-admin-actor.js +13 -74
  4. package/dist/lib/create-command.js +6 -16
  5. package/dist/modules/admin-account/commands.js +35 -24
  6. package/dist/modules/admin-account/components/change-password.d.ts +8 -0
  7. package/dist/modules/admin-account/components/change-password.js +192 -0
  8. package/dist/modules/admin-account/components/change-password.module.js +8 -0
  9. package/dist/modules/admin-account/components/change-password_module.css +27 -0
  10. package/dist/modules/admin-account/components/container.d.ts +29 -0
  11. package/dist/modules/admin-account/components/container.js +298 -0
  12. package/dist/modules/admin-account/components/container.module.js +28 -0
  13. package/dist/modules/admin-account/components/container_module.css +106 -0
  14. package/dist/modules/admin-account/components/update.d.ts +8 -0
  15. package/dist/modules/admin-account/components/update.js +207 -0
  16. package/dist/modules/admin-account/components/update.module.js +8 -0
  17. package/dist/modules/admin-account/components/update_module.css +27 -0
  18. package/dist/modules/admin-account/errors.js +14 -45
  19. package/dist/modules/admin-account/index.js +4 -34
  20. package/dist/modules/admin-account/schemas.js +25 -59
  21. package/dist/modules/admin-account/service.js +56 -61
  22. package/dist/modules/admin-permissions/abilities.js +6 -24
  23. package/dist/modules/admin-permissions/commands.js +42 -28
  24. package/dist/modules/admin-permissions/components/inspector.d.ts +4 -0
  25. package/dist/modules/admin-permissions/components/inspector.js +284 -0
  26. package/dist/modules/admin-permissions/components/inspector.module.js +56 -0
  27. package/dist/modules/admin-permissions/components/inspector_module.css +238 -0
  28. package/dist/modules/admin-permissions/dto.js +3 -16
  29. package/dist/modules/admin-permissions/errors.js +14 -27
  30. package/dist/modules/admin-permissions/index.js +6 -26
  31. package/dist/modules/admin-permissions/repository.js +1 -8
  32. package/dist/modules/admin-permissions/schemas.js +33 -70
  33. package/dist/modules/admin-permissions/service.js +88 -92
  34. package/dist/modules/admin-roles/abilities.js +8 -30
  35. package/dist/modules/admin-roles/commands.js +89 -55
  36. package/dist/modules/admin-roles/components/create.d.ts +7 -0
  37. package/dist/modules/admin-roles/components/create.js +177 -0
  38. package/dist/modules/admin-roles/components/create.module.js +8 -0
  39. package/dist/modules/admin-roles/components/create_module.css +27 -0
  40. package/dist/modules/admin-roles/components/permissions.d.ts +10 -0
  41. package/dist/modules/admin-roles/components/permissions.js +303 -0
  42. package/dist/modules/admin-roles/components/permissions.module.js +44 -0
  43. package/dist/modules/admin-roles/components/permissions_module.css +192 -0
  44. package/dist/modules/admin-roles/components/update.d.ts +8 -0
  45. package/dist/modules/admin-roles/components/update.js +166 -0
  46. package/dist/modules/admin-roles/components/update.module.js +8 -0
  47. package/dist/modules/admin-roles/components/update_module.css +27 -0
  48. package/dist/modules/admin-roles/dto.js +3 -16
  49. package/dist/modules/admin-roles/errors.js +16 -40
  50. package/dist/modules/admin-roles/index.js +6 -26
  51. package/dist/modules/admin-roles/repository.js +1 -8
  52. package/dist/modules/admin-roles/schemas.js +41 -71
  53. package/dist/modules/admin-roles/service.js +79 -82
  54. package/dist/modules/admin-users/abilities.js +9 -38
  55. package/dist/modules/admin-users/commands.js +92 -50
  56. package/dist/modules/admin-users/components/create.d.ts +8 -0
  57. package/dist/modules/admin-users/components/create.js +268 -0
  58. package/dist/modules/admin-users/components/create.module.js +10 -0
  59. package/dist/modules/admin-users/components/create_module.css +45 -0
  60. package/dist/modules/admin-users/components/roles.d.ts +11 -0
  61. package/dist/modules/admin-users/components/roles.js +148 -0
  62. package/dist/modules/admin-users/components/roles.module.js +18 -0
  63. package/dist/modules/admin-users/components/roles_module.css +75 -0
  64. package/dist/modules/admin-users/components/set-password.d.ts +8 -0
  65. package/dist/modules/admin-users/components/set-password.js +170 -0
  66. package/dist/modules/admin-users/components/set-password.module.js +9 -0
  67. package/dist/modules/admin-users/components/set-password_module.css +31 -0
  68. package/dist/modules/admin-users/components/update.d.ts +8 -0
  69. package/dist/modules/admin-users/components/update.js +254 -0
  70. package/dist/modules/admin-users/components/update.module.js +9 -0
  71. package/dist/modules/admin-users/components/update_module.css +34 -0
  72. package/dist/modules/admin-users/dto.js +3 -18
  73. package/dist/modules/admin-users/errors.js +17 -43
  74. package/dist/modules/admin-users/index.js +7 -27
  75. package/dist/modules/admin-users/repository.js +1 -8
  76. package/dist/modules/admin-users/schemas.js +44 -75
  77. package/dist/modules/admin-users/seed-super-admin.js +9 -34
  78. package/dist/modules/admin-users/service.js +76 -91
  79. package/dist/modules/auth/components/sign-in-form.d.ts +12 -0
  80. package/dist/modules/auth/components/sign-in-form.js +115 -0
  81. package/dist/modules/auth/components/sign-in-form.module.js +12 -0
  82. package/dist/modules/auth/components/sign-in-form_module.css +41 -0
  83. package/dist/modules/auth/index.js +3 -24
  84. package/dist/modules/auth/jwt-session-provider.js +179 -149
  85. package/dist/modules/auth/password.js +11 -53
  86. package/dist/modules/auth/phc.js +21 -54
  87. package/dist/modules/auth/refresh-tokens-repository.js +1 -8
  88. package/dist/modules/auth/resolve-actor.js +6 -28
  89. package/dist/services/admin-services-context.d.ts +16 -0
  90. package/dist/services/admin-services-context.js +13 -0
  91. package/dist/services/admin-services-types.d.ts +129 -0
  92. package/dist/services/admin-services-types.js +1 -0
  93. package/dist/store.js +1 -8
  94. package/dist/vendor/noble-argon2/_blake.js +277 -45
  95. package/dist/vendor/noble-argon2/_md.js +81 -136
  96. package/dist/vendor/noble-argon2/_u64.js +65 -67
  97. package/dist/vendor/noble-argon2/argon2.js +181 -342
  98. package/dist/vendor/noble-argon2/blake2.js +252 -327
  99. package/dist/vendor/noble-argon2/utils.js +110 -490
  100. package/dist/vendor/noble-argon2/utils.js.LICENSE.txt +1 -0
  101. package/package.json +89 -10
  102. package/src/abilities.ts +32 -0
  103. package/src/declarations.d.ts +4 -0
  104. package/src/index.ts +39 -0
  105. package/src/lib/assert-admin-actor.ts +90 -0
  106. package/src/lib/create-command.ts +109 -0
  107. package/src/modules/admin-account/commands.ts +76 -0
  108. package/src/modules/admin-account/components/change-password.module.css +40 -0
  109. package/src/modules/admin-account/components/change-password.tsx +232 -0
  110. package/src/modules/admin-account/components/container.module.css +158 -0
  111. package/src/modules/admin-account/components/container.tsx +229 -0
  112. package/src/modules/admin-account/components/update.module.css +40 -0
  113. package/src/modules/admin-account/components/update.tsx +263 -0
  114. package/src/modules/admin-account/errors.ts +75 -0
  115. package/src/modules/admin-account/index.ts +60 -0
  116. package/src/modules/admin-account/schemas.ts +84 -0
  117. package/src/modules/admin-account/service.ts +92 -0
  118. package/src/modules/admin-permissions/abilities.ts +46 -0
  119. package/src/modules/admin-permissions/commands.ts +103 -0
  120. package/src/modules/admin-permissions/components/inspector.module.css +326 -0
  121. package/src/modules/admin-permissions/components/inspector.tsx +298 -0
  122. package/src/modules/admin-permissions/dto.ts +28 -0
  123. package/src/modules/admin-permissions/errors.ts +57 -0
  124. package/src/modules/admin-permissions/index.ts +72 -0
  125. package/src/modules/admin-permissions/repository.ts +49 -0
  126. package/src/modules/admin-permissions/schemas.ts +128 -0
  127. package/src/modules/admin-permissions/service.ts +137 -0
  128. package/src/modules/admin-roles/abilities.ts +62 -0
  129. package/src/modules/admin-roles/commands.ts +161 -0
  130. package/src/modules/admin-roles/components/create.module.css +40 -0
  131. package/src/modules/admin-roles/components/create.tsx +218 -0
  132. package/src/modules/admin-roles/components/permissions.module.css +279 -0
  133. package/src/modules/admin-roles/components/permissions.tsx +396 -0
  134. package/src/modules/admin-roles/components/update.module.css +40 -0
  135. package/src/modules/admin-roles/components/update.tsx +218 -0
  136. package/src/modules/admin-roles/dto.ts +30 -0
  137. package/src/modules/admin-roles/errors.ts +76 -0
  138. package/src/modules/admin-roles/index.ts +81 -0
  139. package/src/modules/admin-roles/repository.ts +96 -0
  140. package/src/modules/admin-roles/schemas.ts +139 -0
  141. package/src/modules/admin-roles/service.ts +136 -0
  142. package/src/modules/admin-users/abilities.ts +76 -0
  143. package/src/modules/admin-users/commands.ts +157 -0
  144. package/src/modules/admin-users/components/create.module.css +63 -0
  145. package/src/modules/admin-users/components/create.tsx +323 -0
  146. package/src/modules/admin-users/components/roles.module.css +119 -0
  147. package/src/modules/admin-users/components/roles.tsx +172 -0
  148. package/src/modules/admin-users/components/set-password.module.css +46 -0
  149. package/src/modules/admin-users/components/set-password.tsx +199 -0
  150. package/src/modules/admin-users/components/update.module.css +49 -0
  151. package/src/modules/admin-users/components/update.tsx +328 -0
  152. package/src/modules/admin-users/dto.ts +39 -0
  153. package/src/modules/admin-users/errors.ts +84 -0
  154. package/src/modules/admin-users/index.ts +91 -0
  155. package/src/modules/admin-users/repository.ts +161 -0
  156. package/src/modules/admin-users/schemas.ts +168 -0
  157. package/src/modules/admin-users/seed-super-admin.ts +102 -0
  158. package/src/modules/admin-users/service.ts +166 -0
  159. package/src/modules/auth/components/sign-in-form.module.css +62 -0
  160. package/src/modules/auth/components/sign-in-form.tsx +132 -0
  161. package/src/modules/auth/index.ts +31 -0
  162. package/src/modules/auth/jwt-session-provider.ts +301 -0
  163. package/src/modules/auth/password.ts +94 -0
  164. package/src/modules/auth/phc.ts +121 -0
  165. package/src/modules/auth/refresh-tokens-repository.ts +74 -0
  166. package/src/modules/auth/resolve-actor.ts +42 -0
  167. package/src/services/admin-services-context.tsx +52 -0
  168. package/src/services/admin-services-types.ts +177 -0
  169. package/src/store.ts +32 -0
  170. package/src/vendor/noble-argon2/LICENSE +21 -0
  171. package/src/vendor/noble-argon2/README.md +87 -0
  172. package/src/vendor/noble-argon2/_blake.ts +58 -0
  173. package/src/vendor/noble-argon2/_md.ts +223 -0
  174. package/src/vendor/noble-argon2/_u64.ts +118 -0
  175. package/src/vendor/noble-argon2/argon2.ts +668 -0
  176. package/src/vendor/noble-argon2/blake2.ts +583 -0
  177. package/src/vendor/noble-argon2/utils.ts +849 -0
@@ -0,0 +1,298 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { Button, CloseIcon, Drawer, EditIcon, IconButton, LocalDateTime } from "@byline/ui/react";
5
+ import classnames from "classnames";
6
+ import { ChangeAccountPassword } from "./change-password.js";
7
+ import container_module from "./container.module.js";
8
+ import { UpdateAccount } from "./update.js";
9
+ const panels = {
10
+ update: {
11
+ title: 'Profile',
12
+ component: UpdateAccount
13
+ },
14
+ change_password: {
15
+ title: 'Change Password',
16
+ component: ChangeAccountPassword
17
+ },
18
+ empty: {
19
+ title: '',
20
+ component: ()=>null
21
+ }
22
+ };
23
+ function ContainerSection({ title, onEdit, children }) {
24
+ return /*#__PURE__*/ jsxs("div", {
25
+ className: classnames('byline-account-section', container_module.section),
26
+ children: [
27
+ /*#__PURE__*/ jsxs("div", {
28
+ className: classnames('byline-account-section-head', container_module["section-head"]),
29
+ children: [
30
+ /*#__PURE__*/ jsx("h2", {
31
+ children: title
32
+ }),
33
+ onEdit ? /*#__PURE__*/ jsx(IconButton, {
34
+ variant: "text",
35
+ onClick: onEdit,
36
+ "aria-label": `Edit ${title}`,
37
+ children: /*#__PURE__*/ jsx(EditIcon, {
38
+ width: "20px",
39
+ height: "20px"
40
+ })
41
+ }) : null
42
+ ]
43
+ }),
44
+ /*#__PURE__*/ jsx("div", {
45
+ children: children
46
+ })
47
+ ]
48
+ });
49
+ }
50
+ function AccountSelfContainer({ account }) {
51
+ const [currentAccount, setCurrentAccount] = useState(account);
52
+ const [current, setCurrent] = useState('empty');
53
+ const [isDrawerOpen, setIsDrawerOpen] = useState(false);
54
+ const openDrawer = (key)=>()=>{
55
+ setCurrent(key);
56
+ setIsDrawerOpen(true);
57
+ };
58
+ const closeDrawer = ()=>{
59
+ setCurrent('empty');
60
+ setIsDrawerOpen(false);
61
+ };
62
+ const handleSuccess = (updated)=>{
63
+ setCurrentAccount(updated);
64
+ };
65
+ const Panel = panels[current].component;
66
+ return /*#__PURE__*/ jsxs(Fragment, {
67
+ children: [
68
+ /*#__PURE__*/ jsxs("div", {
69
+ className: classnames('byline-account-grid', container_module.grid),
70
+ children: [
71
+ /*#__PURE__*/ jsx("div", {
72
+ className: classnames('byline-account-column', container_module.column),
73
+ children: /*#__PURE__*/ jsxs(ContainerSection, {
74
+ title: "Profile",
75
+ onEdit: openDrawer('update'),
76
+ children: [
77
+ /*#__PURE__*/ jsxs("p", {
78
+ className: classnames('byline-account-line', container_module.line),
79
+ children: [
80
+ /*#__PURE__*/ jsx("span", {
81
+ className: "muted",
82
+ children: "Email:"
83
+ }),
84
+ " ",
85
+ currentAccount.email
86
+ ]
87
+ }),
88
+ /*#__PURE__*/ jsxs("p", {
89
+ className: classnames('byline-account-line', container_module.line),
90
+ children: [
91
+ /*#__PURE__*/ jsx("span", {
92
+ className: "muted",
93
+ children: "Given name:"
94
+ }),
95
+ ' ',
96
+ currentAccount.given_name ?? /*#__PURE__*/ jsx("span", {
97
+ className: classnames('muted', 'byline-account-not-set', container_module["not-set"]),
98
+ children: "Not set"
99
+ })
100
+ ]
101
+ }),
102
+ /*#__PURE__*/ jsxs("p", {
103
+ className: classnames('byline-account-line', container_module.line),
104
+ children: [
105
+ /*#__PURE__*/ jsx("span", {
106
+ className: "muted",
107
+ children: "Family name:"
108
+ }),
109
+ ' ',
110
+ currentAccount.family_name ?? /*#__PURE__*/ jsx("span", {
111
+ className: classnames('muted', 'byline-account-not-set', container_module["not-set"]),
112
+ children: "Not set"
113
+ })
114
+ ]
115
+ }),
116
+ /*#__PURE__*/ jsxs("p", {
117
+ className: classnames('byline-account-cta-line', container_module["cta-line"]),
118
+ children: [
119
+ /*#__PURE__*/ jsx("span", {
120
+ className: "muted",
121
+ children: "Username:"
122
+ }),
123
+ ' ',
124
+ currentAccount.username ?? /*#__PURE__*/ jsx("span", {
125
+ className: classnames('muted', 'byline-account-not-set', container_module["not-set"]),
126
+ children: "Not set"
127
+ })
128
+ ]
129
+ }),
130
+ /*#__PURE__*/ jsx(Button, {
131
+ size: "sm",
132
+ onClick: openDrawer('update'),
133
+ children: "Edit Profile"
134
+ }),
135
+ /*#__PURE__*/ jsxs("div", {
136
+ className: classnames('muted', 'byline-account-meta', container_module.meta),
137
+ children: [
138
+ /*#__PURE__*/ jsxs("p", {
139
+ children: [
140
+ /*#__PURE__*/ jsx("span", {
141
+ className: "font-bold",
142
+ children: "Created:\xa0"
143
+ }),
144
+ /*#__PURE__*/ jsx(LocalDateTime, {
145
+ value: currentAccount.created_at
146
+ })
147
+ ]
148
+ }),
149
+ /*#__PURE__*/ jsxs("p", {
150
+ children: [
151
+ /*#__PURE__*/ jsx("span", {
152
+ className: "font-bold",
153
+ children: "Updated:\xa0"
154
+ }),
155
+ /*#__PURE__*/ jsx(LocalDateTime, {
156
+ value: currentAccount.updated_at
157
+ })
158
+ ]
159
+ }),
160
+ /*#__PURE__*/ jsxs("p", {
161
+ className: classnames('byline-account-line', container_module.line),
162
+ children: [
163
+ /*#__PURE__*/ jsx("span", {
164
+ className: "font-bold",
165
+ children: "Last login:\xa0"
166
+ }),
167
+ /*#__PURE__*/ jsx(LocalDateTime, {
168
+ value: currentAccount.last_login,
169
+ fallback: "Never"
170
+ })
171
+ ]
172
+ })
173
+ ]
174
+ })
175
+ ]
176
+ })
177
+ }),
178
+ /*#__PURE__*/ jsxs("div", {
179
+ className: classnames('byline-account-column', container_module.column),
180
+ children: [
181
+ /*#__PURE__*/ jsxs(ContainerSection, {
182
+ title: "Password",
183
+ onEdit: openDrawer('change_password'),
184
+ children: [
185
+ /*#__PURE__*/ jsx("p", {
186
+ className: classnames('byline-account-cta-line', container_module["cta-line"]),
187
+ children: "Change the password used to sign in to the admin. You'll need to enter your current password to confirm the change."
188
+ }),
189
+ /*#__PURE__*/ jsx(Button, {
190
+ size: "sm",
191
+ onClick: openDrawer('change_password'),
192
+ children: "Change Password"
193
+ })
194
+ ]
195
+ }),
196
+ /*#__PURE__*/ jsxs(ContainerSection, {
197
+ title: "Account Status",
198
+ children: [
199
+ /*#__PURE__*/ jsxs("p", {
200
+ className: classnames('byline-account-line', container_module.line),
201
+ children: [
202
+ /*#__PURE__*/ jsx("span", {
203
+ className: "muted",
204
+ children: "Super admin:"
205
+ }),
206
+ ' ',
207
+ currentAccount.is_super_admin ? 'Yes' : 'No'
208
+ ]
209
+ }),
210
+ /*#__PURE__*/ jsxs("p", {
211
+ className: classnames('byline-account-line', container_module.line),
212
+ children: [
213
+ /*#__PURE__*/ jsx("span", {
214
+ className: "muted",
215
+ children: "Email verified:"
216
+ }),
217
+ ' ',
218
+ currentAccount.is_email_verified ? 'Yes' : 'No'
219
+ ]
220
+ }),
221
+ /*#__PURE__*/ jsxs("p", {
222
+ className: classnames('byline-account-line', container_module.line),
223
+ children: [
224
+ /*#__PURE__*/ jsx("span", {
225
+ className: "muted",
226
+ children: "Status:"
227
+ }),
228
+ ' ',
229
+ /*#__PURE__*/ jsx("span", {
230
+ className: currentAccount.is_enabled ? classnames('byline-account-status-on', container_module["status-on"]) : classnames('byline-account-status-off', container_module["status-off"]),
231
+ children: currentAccount.is_enabled ? 'Enabled' : 'Disabled'
232
+ })
233
+ ]
234
+ }),
235
+ /*#__PURE__*/ jsx("p", {
236
+ className: classnames('muted', 'byline-account-status-help', container_module["status-help"]),
237
+ children: "These flags are managed by an admin with the appropriate permissions and are not self-editable."
238
+ })
239
+ ]
240
+ })
241
+ ]
242
+ })
243
+ ]
244
+ }),
245
+ /*#__PURE__*/ jsx(Drawer, {
246
+ id: "admin-account-drawer",
247
+ closeOnOverlayClick: false,
248
+ width: "medium",
249
+ topOffset: "46px",
250
+ isOpen: isDrawerOpen,
251
+ onDismiss: closeDrawer,
252
+ className: classnames('byline-account-drawer', container_module.drawer),
253
+ children: /*#__PURE__*/ jsxs(Drawer.Container, {
254
+ "aria-hidden": !isDrawerOpen,
255
+ className: classnames('byline-account-drawer-body', container_module["drawer-body"]),
256
+ children: [
257
+ /*#__PURE__*/ jsxs(Drawer.TopActions, {
258
+ children: [
259
+ /*#__PURE__*/ jsx("button", {
260
+ type: "button",
261
+ tabIndex: 0,
262
+ className: classnames('byline-account-drawer-skip', container_module["drawer-skip"]),
263
+ children: "no action"
264
+ }),
265
+ /*#__PURE__*/ jsx(IconButton, {
266
+ "aria-label": "Close",
267
+ size: "sm",
268
+ onClick: closeDrawer,
269
+ children: /*#__PURE__*/ jsx(CloseIcon, {
270
+ width: "14px",
271
+ height: "14px",
272
+ svgClassName: "white-icon stroke-white"
273
+ })
274
+ })
275
+ ]
276
+ }),
277
+ /*#__PURE__*/ jsx(Drawer.Header, {
278
+ children: /*#__PURE__*/ jsx("h2", {
279
+ children: panels[current].title
280
+ })
281
+ }),
282
+ /*#__PURE__*/ jsx(Drawer.Content, {
283
+ children: /*#__PURE__*/ jsx("div", {
284
+ className: classnames('byline-account-drawer-scroll', container_module["drawer-scroll"]),
285
+ children: /*#__PURE__*/ jsx(Panel, {
286
+ account: currentAccount,
287
+ onClose: closeDrawer,
288
+ onSuccess: handleSuccess
289
+ })
290
+ })
291
+ })
292
+ ]
293
+ })
294
+ })
295
+ ]
296
+ });
297
+ }
298
+ export { AccountSelfContainer };
@@ -0,0 +1,28 @@
1
+ import "./container_module.css";
2
+ const container_module = {
3
+ grid: "grid-TDIPZJ",
4
+ column: "column-RGIay3",
5
+ section: "section-iYQnMb",
6
+ "section-head": "section-head-O3uWgR",
7
+ sectionHead: "section-head-O3uWgR",
8
+ line: "line-Yue0Yc",
9
+ "cta-line": "cta-line-JwOIoW",
10
+ ctaLine: "cta-line-JwOIoW",
11
+ meta: "meta-CLvEpZ",
12
+ "status-on": "status-on-_9iyL2",
13
+ statusOn: "status-on-_9iyL2",
14
+ "status-off": "status-off-WJAcBy",
15
+ statusOff: "status-off-WJAcBy",
16
+ "status-help": "status-help-GVOlMV",
17
+ statusHelp: "status-help-GVOlMV",
18
+ "not-set": "not-set-Ek2yXe",
19
+ notSet: "not-set-Ek2yXe",
20
+ drawer: "drawer-dDlpic",
21
+ "drawer-body": "drawer-body-eVTFVC",
22
+ drawerBody: "drawer-body-eVTFVC",
23
+ "drawer-scroll": "drawer-scroll-T9DAB_",
24
+ drawerScroll: "drawer-scroll-T9DAB_",
25
+ "drawer-skip": "drawer-skip-neMrNH",
26
+ drawerSkip: "drawer-skip-neMrNH"
27
+ };
28
+ export default container_module;
@@ -0,0 +1,106 @@
1
+ :is(.grid-TDIPZJ, .byline-account-grid) {
2
+ gap: var(--spacing-16);
3
+ margin-bottom: var(--spacing-48);
4
+ flex-direction: column;
5
+ display: flex;
6
+ }
7
+
8
+ @media (min-width: 40rem) {
9
+ :is(.grid-TDIPZJ, .byline-account-grid) {
10
+ grid-template-columns: 1fr 1fr;
11
+ display: grid;
12
+ }
13
+ }
14
+
15
+ :is(.column-RGIay3, .byline-account-column) {
16
+ gap: var(--spacing-16);
17
+ margin-bottom: var(--spacing-16);
18
+ flex-direction: column;
19
+ display: flex;
20
+ }
21
+
22
+ :is(.section-iYQnMb, .byline-account-section) {
23
+ padding: var(--spacing-16);
24
+ border: var(--border-width-thin) var(--border-style-solid) var(--gray-100);
25
+ background-color: var(--canvas-25);
26
+ border-radius: var(--border-radius-sm);
27
+ }
28
+
29
+ :is(.section-head-O3uWgR, .byline-account-section-head) {
30
+ margin-bottom: var(--spacing-8);
31
+ justify-content: space-between;
32
+ align-items: center;
33
+ display: flex;
34
+ }
35
+
36
+ :is(.line-Yue0Yc, .byline-account-line) {
37
+ margin-bottom: 0;
38
+ }
39
+
40
+ :is(.cta-line-JwOIoW, .byline-account-cta-line) {
41
+ margin-bottom: var(--spacing-12);
42
+ }
43
+
44
+ :is(.meta-CLvEpZ, .byline-account-meta) {
45
+ margin-top: var(--spacing-16);
46
+ font-size: var(--font-size-xs);
47
+ }
48
+
49
+ :is(.status-on-_9iyL2, .byline-account-status-on) {
50
+ color: var(--green-600);
51
+ }
52
+
53
+ :is(.status-off-WJAcBy, .byline-account-status-off) {
54
+ color: var(--red-600);
55
+ }
56
+
57
+ :is(.status-help-GVOlMV, .byline-account-status-help) {
58
+ margin-top: var(--spacing-12);
59
+ font-size: var(--font-size-xs);
60
+ margin-bottom: 0;
61
+ }
62
+
63
+ :is(.not-set-Ek2yXe, .byline-account-not-set) {
64
+ font-style: italic;
65
+ }
66
+
67
+ @media (min-width: 48rem) {
68
+ :is(.drawer-dDlpic, .byline-account-drawer) {
69
+ width: 500px;
70
+ }
71
+ }
72
+
73
+ :is(.drawer-body-eVTFVC, .byline-account-drawer-body) {
74
+ padding: var(--spacing-8);
75
+ }
76
+
77
+ :is(.drawer-scroll-T9DAB_, .byline-account-drawer-scroll) {
78
+ max-height: calc(100vh - 160px);
79
+ overflow-y: auto;
80
+ }
81
+
82
+ :is(.drawer-skip-neMrNH, .byline-account-drawer-skip) {
83
+ clip: rect(0, 0, 0, 0);
84
+ white-space: nowrap;
85
+ border: 0;
86
+ width: 1px;
87
+ height: 1px;
88
+ margin: -1px;
89
+ padding: 0;
90
+ position: absolute;
91
+ overflow: hidden;
92
+ }
93
+
94
+ :is(:is([data-theme="dark"], .dark) .section-iYQnMb, :is([data-theme="dark"], .dark) .byline-account-section) {
95
+ border-color: var(--gray-700);
96
+ background-color: var(--canvas-800);
97
+ }
98
+
99
+ :is(:is([data-theme="dark"], .dark) .status-on-_9iyL2, :is([data-theme="dark"], .dark) .byline-account-status-on) {
100
+ color: var(--green-400);
101
+ }
102
+
103
+ :is(:is([data-theme="dark"], .dark) .status-off-WJAcBy, :is([data-theme="dark"], .dark) .byline-account-status-off) {
104
+ color: var(--red-400);
105
+ }
106
+
@@ -0,0 +1,8 @@
1
+ import type { AccountResponse } from '../index.js';
2
+ interface UpdateAccountProps {
3
+ account: AccountResponse;
4
+ onClose?: () => void;
5
+ onSuccess?: (account: AccountResponse) => void;
6
+ }
7
+ export declare function UpdateAccount({ account, onClose, onSuccess }: UpdateAccountProps): import("react").JSX.Element;
8
+ export {};
@@ -0,0 +1,207 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { revalidateLogic, useForm } from "@tanstack/react-form-start";
5
+ import { Alert, Button, Input, LoaderEllipsis } from "@byline/ui/react";
6
+ import classnames from "classnames";
7
+ import { z } from "zod";
8
+ import { useBylineAdminServices } from "../../../services/admin-services-context.js";
9
+ import update_module from "./update.module.js";
10
+ const updateAccountSchema = z.object({
11
+ given_name: z.string().max(100, 'Given name must not exceed 100 characters'),
12
+ family_name: z.string().max(100, 'Family name must not exceed 100 characters'),
13
+ username: z.string().max(100, 'Username must not exceed 100 characters'),
14
+ email: z.email({
15
+ message: 'Enter a valid email address'
16
+ }).min(3).max(254, 'Email must not exceed 254 characters')
17
+ });
18
+ function defaultsFrom(account) {
19
+ return {
20
+ given_name: account.given_name ?? '',
21
+ family_name: account.family_name ?? '',
22
+ username: account.username ?? '',
23
+ email: account.email
24
+ };
25
+ }
26
+ function buildPatch(values, account) {
27
+ const patch = {};
28
+ const normaliseText = (value)=>value.trim().length > 0 ? value : null;
29
+ const nextGiven = normaliseText(values.given_name);
30
+ const nextFamily = normaliseText(values.family_name);
31
+ const nextUsername = normaliseText(values.username);
32
+ if (nextGiven !== account.given_name) patch.given_name = nextGiven;
33
+ if (nextFamily !== account.family_name) patch.family_name = nextFamily;
34
+ if (nextUsername !== account.username) patch.username = nextUsername;
35
+ if (values.email !== account.email) patch.email = values.email;
36
+ return patch;
37
+ }
38
+ function UpdateAccount({ account, onClose, onSuccess }) {
39
+ const { updateAccount } = useBylineAdminServices();
40
+ const [formError, setFormError] = useState(null);
41
+ const [successMessage, setSuccessMessage] = useState(null);
42
+ const form = useForm({
43
+ defaultValues: defaultsFrom(account),
44
+ validationLogic: revalidateLogic({
45
+ mode: 'blur',
46
+ modeAfterSubmission: 'change'
47
+ }),
48
+ validators: {
49
+ onDynamic: updateAccountSchema
50
+ },
51
+ onSubmit: async ({ value })=>{
52
+ setFormError(null);
53
+ setSuccessMessage(null);
54
+ const patch = buildPatch(value, account);
55
+ if (0 === Object.keys(patch).length) return void setSuccessMessage('No changes to save.');
56
+ try {
57
+ const updated = await updateAccount({
58
+ data: {
59
+ vid: account.vid,
60
+ patch
61
+ }
62
+ });
63
+ setSuccessMessage('Saved.');
64
+ onSuccess?.(updated);
65
+ } catch (err) {
66
+ const code = getErrorCode(err);
67
+ if ('admin.users.emailInUse' === code) return void form.setFieldMeta('email', (meta)=>({
68
+ ...meta,
69
+ errorMap: {
70
+ ...meta.errorMap,
71
+ onServer: 'This email is already in use.'
72
+ },
73
+ errors: [
74
+ 'This email is already in use.'
75
+ ]
76
+ }));
77
+ if ('admin.users.versionConflict' === code) return void setFormError('Your account has been modified elsewhere since you opened this form. Reload to refresh and try again.');
78
+ if ('admin.account.notFound' === code) return void setFormError('Your admin account could not be found. Please sign in again.');
79
+ setFormError('Could not save changes. Please try again.');
80
+ }
81
+ }
82
+ });
83
+ return /*#__PURE__*/ jsx("div", {
84
+ className: classnames('byline-account-update-wrap', update_module.wrap),
85
+ children: /*#__PURE__*/ jsxs("form", {
86
+ noValidate: true,
87
+ onSubmit: (event)=>{
88
+ event.preventDefault();
89
+ event.stopPropagation();
90
+ form.handleSubmit();
91
+ },
92
+ className: classnames('byline-account-update-form', update_module.form),
93
+ children: [
94
+ formError ? /*#__PURE__*/ jsx(Alert, {
95
+ intent: "danger",
96
+ children: formError
97
+ }) : null,
98
+ successMessage ? /*#__PURE__*/ jsx(Alert, {
99
+ intent: "success",
100
+ children: successMessage
101
+ }) : null,
102
+ /*#__PURE__*/ jsx(form.Field, {
103
+ name: "given_name",
104
+ children: (field)=>/*#__PURE__*/ jsx(Input, {
105
+ label: "Given name",
106
+ id: "given_name",
107
+ name: field.name,
108
+ value: field.state.value,
109
+ onBlur: field.handleBlur,
110
+ onChange: (e)=>field.handleChange(e.currentTarget.value),
111
+ error: field.state.meta.errors.length > 0,
112
+ errorText: firstError(field.state.meta.errors),
113
+ autoComplete: "given-name"
114
+ })
115
+ }),
116
+ /*#__PURE__*/ jsx(form.Field, {
117
+ name: "family_name",
118
+ children: (field)=>/*#__PURE__*/ jsx(Input, {
119
+ label: "Family name",
120
+ id: "family_name",
121
+ name: field.name,
122
+ value: field.state.value,
123
+ onBlur: field.handleBlur,
124
+ onChange: (e)=>field.handleChange(e.currentTarget.value),
125
+ error: field.state.meta.errors.length > 0,
126
+ errorText: firstError(field.state.meta.errors),
127
+ autoComplete: "family-name"
128
+ })
129
+ }),
130
+ /*#__PURE__*/ jsx(form.Field, {
131
+ name: "username",
132
+ children: (field)=>/*#__PURE__*/ jsx(Input, {
133
+ label: "Username",
134
+ id: "username",
135
+ name: field.name,
136
+ value: field.state.value,
137
+ onBlur: field.handleBlur,
138
+ onChange: (e)=>field.handleChange(e.currentTarget.value),
139
+ error: field.state.meta.errors.length > 0,
140
+ errorText: firstError(field.state.meta.errors),
141
+ helpText: "Optional. Leave blank to clear.",
142
+ autoComplete: "username"
143
+ })
144
+ }),
145
+ /*#__PURE__*/ jsx(form.Field, {
146
+ name: "email",
147
+ children: (field)=>/*#__PURE__*/ jsx(Input, {
148
+ label: "Email",
149
+ id: "email",
150
+ name: field.name,
151
+ type: "email",
152
+ value: field.state.value,
153
+ onBlur: field.handleBlur,
154
+ onChange: (e)=>field.handleChange(e.currentTarget.value),
155
+ error: field.state.meta.errors.length > 0,
156
+ errorText: firstError(field.state.meta.errors),
157
+ autoComplete: "email",
158
+ required: true
159
+ })
160
+ }),
161
+ /*#__PURE__*/ jsxs("div", {
162
+ className: classnames('byline-account-update-actions', update_module.actions),
163
+ children: [
164
+ /*#__PURE__*/ jsx(Button, {
165
+ type: "button",
166
+ intent: "secondary",
167
+ size: "sm",
168
+ onClick: onClose,
169
+ className: classnames('byline-account-update-action', update_module.action),
170
+ children: successMessage ? 'Close' : 'Cancel'
171
+ }),
172
+ /*#__PURE__*/ jsx(form.Subscribe, {
173
+ selector: (state)=>({
174
+ canSubmit: state.canSubmit,
175
+ isSubmitting: state.isSubmitting,
176
+ isDirty: state.isDirty
177
+ }),
178
+ children: ({ canSubmit, isSubmitting })=>/*#__PURE__*/ jsx(Button, {
179
+ size: "sm",
180
+ intent: "primary",
181
+ type: "submit",
182
+ disabled: !canSubmit || isSubmitting,
183
+ className: classnames('byline-account-update-action', update_module.action),
184
+ children: true === isSubmitting ? /*#__PURE__*/ jsx(LoaderEllipsis, {
185
+ size: 42
186
+ }) : 'Save'
187
+ })
188
+ })
189
+ ]
190
+ })
191
+ ]
192
+ })
193
+ });
194
+ }
195
+ function firstError(errors) {
196
+ for (const err of errors){
197
+ if ('string' == typeof err) return err;
198
+ if (err && 'object' == typeof err && 'message' in err) {
199
+ const msg = err.message;
200
+ if ('string' == typeof msg) return msg;
201
+ }
202
+ }
203
+ }
204
+ function getErrorCode(err) {
205
+ return 'string' == typeof err?.code ? err.code : null;
206
+ }
207
+ export { UpdateAccount };
@@ -0,0 +1,8 @@
1
+ import "./update_module.css";
2
+ const update_module = {
3
+ wrap: "wrap-d0Vkmj",
4
+ form: "form-VjOmD9",
5
+ actions: "actions-QYTC9w",
6
+ action: "action-Qs2VUY"
7
+ };
8
+ export default update_module;