@byline/admin 2.4.0 → 2.4.1
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/abilities.js +5 -24
- package/dist/index.js +8 -30
- package/dist/lib/assert-admin-actor.js +13 -74
- package/dist/lib/create-command.js +6 -16
- package/dist/modules/admin-account/commands.js +35 -24
- package/dist/modules/admin-account/components/change-password.d.ts +8 -0
- package/dist/modules/admin-account/components/change-password.js +192 -0
- package/dist/modules/admin-account/components/change-password.module.js +8 -0
- package/dist/modules/admin-account/components/change-password_module.css +27 -0
- package/dist/modules/admin-account/components/container.d.ts +29 -0
- package/dist/modules/admin-account/components/container.js +298 -0
- package/dist/modules/admin-account/components/container.module.js +28 -0
- package/dist/modules/admin-account/components/container_module.css +106 -0
- package/dist/modules/admin-account/components/update.d.ts +8 -0
- package/dist/modules/admin-account/components/update.js +207 -0
- package/dist/modules/admin-account/components/update.module.js +8 -0
- package/dist/modules/admin-account/components/update_module.css +27 -0
- package/dist/modules/admin-account/errors.js +14 -45
- package/dist/modules/admin-account/index.js +4 -34
- package/dist/modules/admin-account/schemas.js +25 -59
- package/dist/modules/admin-account/service.js +56 -61
- package/dist/modules/admin-permissions/abilities.js +6 -24
- package/dist/modules/admin-permissions/commands.js +42 -28
- package/dist/modules/admin-permissions/components/inspector.d.ts +4 -0
- package/dist/modules/admin-permissions/components/inspector.js +284 -0
- package/dist/modules/admin-permissions/components/inspector.module.js +56 -0
- package/dist/modules/admin-permissions/components/inspector_module.css +238 -0
- package/dist/modules/admin-permissions/dto.js +3 -16
- package/dist/modules/admin-permissions/errors.js +14 -27
- package/dist/modules/admin-permissions/index.js +6 -26
- package/dist/modules/admin-permissions/repository.js +1 -8
- package/dist/modules/admin-permissions/schemas.js +33 -70
- package/dist/modules/admin-permissions/service.js +88 -92
- package/dist/modules/admin-roles/abilities.js +8 -30
- package/dist/modules/admin-roles/commands.js +89 -55
- package/dist/modules/admin-roles/components/create.d.ts +7 -0
- package/dist/modules/admin-roles/components/create.js +177 -0
- package/dist/modules/admin-roles/components/create.module.js +8 -0
- package/dist/modules/admin-roles/components/create_module.css +27 -0
- package/dist/modules/admin-roles/components/permissions.d.ts +10 -0
- package/dist/modules/admin-roles/components/permissions.js +303 -0
- package/dist/modules/admin-roles/components/permissions.module.js +44 -0
- package/dist/modules/admin-roles/components/permissions_module.css +192 -0
- package/dist/modules/admin-roles/components/update.d.ts +8 -0
- package/dist/modules/admin-roles/components/update.js +166 -0
- package/dist/modules/admin-roles/components/update.module.js +8 -0
- package/dist/modules/admin-roles/components/update_module.css +27 -0
- package/dist/modules/admin-roles/dto.js +3 -16
- package/dist/modules/admin-roles/errors.js +16 -40
- package/dist/modules/admin-roles/index.js +6 -26
- package/dist/modules/admin-roles/repository.js +1 -8
- package/dist/modules/admin-roles/schemas.js +41 -71
- package/dist/modules/admin-roles/service.js +79 -82
- package/dist/modules/admin-users/abilities.js +9 -38
- package/dist/modules/admin-users/commands.js +92 -50
- package/dist/modules/admin-users/components/create.d.ts +8 -0
- package/dist/modules/admin-users/components/create.js +268 -0
- package/dist/modules/admin-users/components/create.module.js +10 -0
- package/dist/modules/admin-users/components/create_module.css +45 -0
- package/dist/modules/admin-users/components/roles.d.ts +11 -0
- package/dist/modules/admin-users/components/roles.js +148 -0
- package/dist/modules/admin-users/components/roles.module.js +18 -0
- package/dist/modules/admin-users/components/roles_module.css +75 -0
- package/dist/modules/admin-users/components/set-password.d.ts +8 -0
- package/dist/modules/admin-users/components/set-password.js +170 -0
- package/dist/modules/admin-users/components/set-password.module.js +9 -0
- package/dist/modules/admin-users/components/set-password_module.css +31 -0
- package/dist/modules/admin-users/components/update.d.ts +8 -0
- package/dist/modules/admin-users/components/update.js +254 -0
- package/dist/modules/admin-users/components/update.module.js +9 -0
- package/dist/modules/admin-users/components/update_module.css +34 -0
- package/dist/modules/admin-users/dto.js +3 -18
- package/dist/modules/admin-users/errors.js +17 -43
- package/dist/modules/admin-users/index.js +7 -27
- package/dist/modules/admin-users/repository.js +1 -8
- package/dist/modules/admin-users/schemas.js +44 -75
- package/dist/modules/admin-users/seed-super-admin.js +9 -34
- package/dist/modules/admin-users/service.js +76 -91
- package/dist/modules/auth/components/sign-in-form.d.ts +12 -0
- package/dist/modules/auth/components/sign-in-form.js +115 -0
- package/dist/modules/auth/components/sign-in-form.module.js +12 -0
- package/dist/modules/auth/components/sign-in-form_module.css +41 -0
- package/dist/modules/auth/index.js +3 -24
- package/dist/modules/auth/jwt-session-provider.js +179 -149
- package/dist/modules/auth/password.js +11 -53
- package/dist/modules/auth/phc.js +21 -54
- package/dist/modules/auth/refresh-tokens-repository.js +1 -8
- package/dist/modules/auth/resolve-actor.js +6 -28
- package/dist/services/admin-services-context.d.ts +16 -0
- package/dist/services/admin-services-context.js +13 -0
- package/dist/services/admin-services-types.d.ts +129 -0
- package/dist/services/admin-services-types.js +1 -0
- package/dist/store.js +1 -8
- package/dist/vendor/noble-argon2/_blake.js +277 -45
- package/dist/vendor/noble-argon2/_md.js +81 -136
- package/dist/vendor/noble-argon2/_u64.js +65 -67
- package/dist/vendor/noble-argon2/argon2.js +181 -342
- package/dist/vendor/noble-argon2/blake2.js +252 -327
- package/dist/vendor/noble-argon2/utils.js +110 -490
- package/dist/vendor/noble-argon2/utils.js.LICENSE.txt +1 -0
- package/package.json +89 -10
- package/src/abilities.ts +32 -0
- package/src/declarations.d.ts +4 -0
- package/src/index.ts +39 -0
- package/src/lib/assert-admin-actor.ts +90 -0
- package/src/lib/create-command.ts +109 -0
- package/src/modules/admin-account/commands.ts +76 -0
- package/src/modules/admin-account/components/change-password.module.css +40 -0
- package/src/modules/admin-account/components/change-password.tsx +232 -0
- package/src/modules/admin-account/components/container.module.css +158 -0
- package/src/modules/admin-account/components/container.tsx +229 -0
- package/src/modules/admin-account/components/update.module.css +40 -0
- package/src/modules/admin-account/components/update.tsx +263 -0
- package/src/modules/admin-account/errors.ts +75 -0
- package/src/modules/admin-account/index.ts +60 -0
- package/src/modules/admin-account/schemas.ts +84 -0
- package/src/modules/admin-account/service.ts +92 -0
- package/src/modules/admin-permissions/abilities.ts +46 -0
- package/src/modules/admin-permissions/commands.ts +103 -0
- package/src/modules/admin-permissions/components/inspector.module.css +326 -0
- package/src/modules/admin-permissions/components/inspector.tsx +298 -0
- package/src/modules/admin-permissions/dto.ts +28 -0
- package/src/modules/admin-permissions/errors.ts +57 -0
- package/src/modules/admin-permissions/index.ts +72 -0
- package/src/modules/admin-permissions/repository.ts +49 -0
- package/src/modules/admin-permissions/schemas.ts +128 -0
- package/src/modules/admin-permissions/service.ts +137 -0
- package/src/modules/admin-roles/abilities.ts +62 -0
- package/src/modules/admin-roles/commands.ts +161 -0
- package/src/modules/admin-roles/components/create.module.css +40 -0
- package/src/modules/admin-roles/components/create.tsx +218 -0
- package/src/modules/admin-roles/components/permissions.module.css +279 -0
- package/src/modules/admin-roles/components/permissions.tsx +396 -0
- package/src/modules/admin-roles/components/update.module.css +40 -0
- package/src/modules/admin-roles/components/update.tsx +218 -0
- package/src/modules/admin-roles/dto.ts +30 -0
- package/src/modules/admin-roles/errors.ts +76 -0
- package/src/modules/admin-roles/index.ts +81 -0
- package/src/modules/admin-roles/repository.ts +96 -0
- package/src/modules/admin-roles/schemas.ts +139 -0
- package/src/modules/admin-roles/service.ts +136 -0
- package/src/modules/admin-users/abilities.ts +76 -0
- package/src/modules/admin-users/commands.ts +157 -0
- package/src/modules/admin-users/components/create.module.css +63 -0
- package/src/modules/admin-users/components/create.tsx +323 -0
- package/src/modules/admin-users/components/roles.module.css +119 -0
- package/src/modules/admin-users/components/roles.tsx +172 -0
- package/src/modules/admin-users/components/set-password.module.css +46 -0
- package/src/modules/admin-users/components/set-password.tsx +199 -0
- package/src/modules/admin-users/components/update.module.css +49 -0
- package/src/modules/admin-users/components/update.tsx +328 -0
- package/src/modules/admin-users/dto.ts +39 -0
- package/src/modules/admin-users/errors.ts +84 -0
- package/src/modules/admin-users/index.ts +91 -0
- package/src/modules/admin-users/repository.ts +161 -0
- package/src/modules/admin-users/schemas.ts +168 -0
- package/src/modules/admin-users/seed-super-admin.ts +102 -0
- package/src/modules/admin-users/service.ts +166 -0
- package/src/modules/auth/components/sign-in-form.module.css +62 -0
- package/src/modules/auth/components/sign-in-form.tsx +132 -0
- package/src/modules/auth/index.ts +31 -0
- package/src/modules/auth/jwt-session-provider.ts +301 -0
- package/src/modules/auth/password.ts +94 -0
- package/src/modules/auth/phc.ts +121 -0
- package/src/modules/auth/refresh-tokens-repository.ts +74 -0
- package/src/modules/auth/resolve-actor.ts +42 -0
- package/src/services/admin-services-context.tsx +52 -0
- package/src/services/admin-services-types.ts +177 -0
- package/src/store.ts +32 -0
- package/src/vendor/noble-argon2/LICENSE +21 -0
- package/src/vendor/noble-argon2/README.md +87 -0
- package/src/vendor/noble-argon2/_blake.ts +58 -0
- package/src/vendor/noble-argon2/_md.ts +223 -0
- package/src/vendor/noble-argon2/_u64.ts +118 -0
- package/src/vendor/noble-argon2/argon2.ts +668 -0
- package/src/vendor/noble-argon2/blake2.ts +583 -0
- package/src/vendor/noble-argon2/utils.ts +849 -0
|
@@ -0,0 +1,268 @@
|
|
|
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 { passwordSchema } from "@byline/core/validation";
|
|
6
|
+
import { Alert, Button, Checkbox, Input, LoaderEllipsis } from "@byline/ui/react";
|
|
7
|
+
import classnames from "classnames";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { useBylineAdminServices } from "../../../services/admin-services-context.js";
|
|
10
|
+
import create_module from "./create.module.js";
|
|
11
|
+
const createAdminUserFormSchema = z.object({
|
|
12
|
+
email: z.email({
|
|
13
|
+
message: 'Enter a valid email address'
|
|
14
|
+
}).min(3).max(254, 'Email must not exceed 254 characters'),
|
|
15
|
+
password: passwordSchema,
|
|
16
|
+
given_name: z.string().max(100, 'Given name must not exceed 100 characters'),
|
|
17
|
+
family_name: z.string().max(100, 'Family name must not exceed 100 characters'),
|
|
18
|
+
username: z.string().max(100, 'Username must not exceed 100 characters'),
|
|
19
|
+
is_super_admin: z.boolean(),
|
|
20
|
+
is_enabled: z.boolean(),
|
|
21
|
+
is_email_verified: z.boolean()
|
|
22
|
+
});
|
|
23
|
+
const initialValues = {
|
|
24
|
+
email: '',
|
|
25
|
+
password: '',
|
|
26
|
+
given_name: '',
|
|
27
|
+
family_name: '',
|
|
28
|
+
username: '',
|
|
29
|
+
is_super_admin: false,
|
|
30
|
+
is_enabled: true,
|
|
31
|
+
is_email_verified: false
|
|
32
|
+
};
|
|
33
|
+
function normaliseText(value) {
|
|
34
|
+
return value.trim().length > 0 ? value : null;
|
|
35
|
+
}
|
|
36
|
+
function CreateAdminUser({ onClose, onSuccess }) {
|
|
37
|
+
const { createAdminUser } = useBylineAdminServices();
|
|
38
|
+
const [formError, setFormError] = useState(null);
|
|
39
|
+
const form = useForm({
|
|
40
|
+
defaultValues: initialValues,
|
|
41
|
+
validationLogic: revalidateLogic({
|
|
42
|
+
mode: 'blur',
|
|
43
|
+
modeAfterSubmission: 'change'
|
|
44
|
+
}),
|
|
45
|
+
validators: {
|
|
46
|
+
onDynamic: createAdminUserFormSchema
|
|
47
|
+
},
|
|
48
|
+
onSubmit: async ({ value })=>{
|
|
49
|
+
setFormError(null);
|
|
50
|
+
try {
|
|
51
|
+
const created = await createAdminUser({
|
|
52
|
+
data: {
|
|
53
|
+
email: value.email,
|
|
54
|
+
password: value.password,
|
|
55
|
+
given_name: normaliseText(value.given_name),
|
|
56
|
+
family_name: normaliseText(value.family_name),
|
|
57
|
+
username: normaliseText(value.username),
|
|
58
|
+
is_super_admin: value.is_super_admin,
|
|
59
|
+
is_enabled: value.is_enabled,
|
|
60
|
+
is_email_verified: value.is_email_verified
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
form.reset(initialValues);
|
|
64
|
+
onSuccess?.(created);
|
|
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
|
+
setFormError('Could not create this admin user. Please try again.');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return /*#__PURE__*/ jsx("div", {
|
|
82
|
+
className: classnames('byline-user-create-wrap', create_module.wrap),
|
|
83
|
+
children: /*#__PURE__*/ jsxs("form", {
|
|
84
|
+
noValidate: true,
|
|
85
|
+
onSubmit: (event)=>{
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
event.stopPropagation();
|
|
88
|
+
form.handleSubmit();
|
|
89
|
+
},
|
|
90
|
+
className: classnames('byline-user-create-form', create_module.form),
|
|
91
|
+
children: [
|
|
92
|
+
formError ? /*#__PURE__*/ jsx(Alert, {
|
|
93
|
+
intent: "danger",
|
|
94
|
+
children: formError
|
|
95
|
+
}) : null,
|
|
96
|
+
/*#__PURE__*/ jsxs("div", {
|
|
97
|
+
className: classnames('byline-user-create-grid', create_module.grid),
|
|
98
|
+
children: [
|
|
99
|
+
/*#__PURE__*/ jsx(form.Field, {
|
|
100
|
+
name: "given_name",
|
|
101
|
+
children: (field)=>/*#__PURE__*/ jsx(Input, {
|
|
102
|
+
label: "Given name",
|
|
103
|
+
id: "new-given-name",
|
|
104
|
+
name: field.name,
|
|
105
|
+
value: field.state.value,
|
|
106
|
+
onBlur: field.handleBlur,
|
|
107
|
+
onChange: (e)=>field.handleChange(e.currentTarget.value),
|
|
108
|
+
error: field.state.meta.errors.length > 0,
|
|
109
|
+
errorText: firstError(field.state.meta.errors),
|
|
110
|
+
autoComplete: "given-name"
|
|
111
|
+
})
|
|
112
|
+
}),
|
|
113
|
+
/*#__PURE__*/ jsx(form.Field, {
|
|
114
|
+
name: "family_name",
|
|
115
|
+
children: (field)=>/*#__PURE__*/ jsx(Input, {
|
|
116
|
+
label: "Family name",
|
|
117
|
+
id: "new-family-name",
|
|
118
|
+
name: field.name,
|
|
119
|
+
value: field.state.value,
|
|
120
|
+
onBlur: field.handleBlur,
|
|
121
|
+
onChange: (e)=>field.handleChange(e.currentTarget.value),
|
|
122
|
+
error: field.state.meta.errors.length > 0,
|
|
123
|
+
errorText: firstError(field.state.meta.errors),
|
|
124
|
+
autoComplete: "family-name"
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
]
|
|
128
|
+
}),
|
|
129
|
+
/*#__PURE__*/ jsx(form.Field, {
|
|
130
|
+
name: "username",
|
|
131
|
+
children: (field)=>/*#__PURE__*/ jsx(Input, {
|
|
132
|
+
label: "Username",
|
|
133
|
+
id: "new-username",
|
|
134
|
+
name: field.name,
|
|
135
|
+
value: field.state.value,
|
|
136
|
+
onBlur: field.handleBlur,
|
|
137
|
+
onChange: (e)=>field.handleChange(e.currentTarget.value),
|
|
138
|
+
error: field.state.meta.errors.length > 0,
|
|
139
|
+
errorText: firstError(field.state.meta.errors),
|
|
140
|
+
helpText: "Optional.",
|
|
141
|
+
autoComplete: "username"
|
|
142
|
+
})
|
|
143
|
+
}),
|
|
144
|
+
/*#__PURE__*/ jsx(form.Field, {
|
|
145
|
+
name: "email",
|
|
146
|
+
children: (field)=>/*#__PURE__*/ jsx(Input, {
|
|
147
|
+
label: "Email",
|
|
148
|
+
id: "new-email",
|
|
149
|
+
name: field.name,
|
|
150
|
+
type: "email",
|
|
151
|
+
value: field.state.value,
|
|
152
|
+
onBlur: field.handleBlur,
|
|
153
|
+
onChange: (e)=>field.handleChange(e.currentTarget.value),
|
|
154
|
+
error: field.state.meta.errors.length > 0,
|
|
155
|
+
errorText: firstError(field.state.meta.errors),
|
|
156
|
+
autoComplete: "email",
|
|
157
|
+
required: true
|
|
158
|
+
})
|
|
159
|
+
}),
|
|
160
|
+
/*#__PURE__*/ jsx(form.Field, {
|
|
161
|
+
name: "password",
|
|
162
|
+
children: (field)=>/*#__PURE__*/ jsx(Input, {
|
|
163
|
+
label: "Initial password",
|
|
164
|
+
id: "new-password",
|
|
165
|
+
name: field.name,
|
|
166
|
+
type: "password",
|
|
167
|
+
value: field.state.value,
|
|
168
|
+
onBlur: field.handleBlur,
|
|
169
|
+
onChange: (e)=>field.handleChange(e.currentTarget.value),
|
|
170
|
+
error: field.state.meta.errors.length > 0,
|
|
171
|
+
errorText: firstError(field.state.meta.errors),
|
|
172
|
+
helpText: "The user can change it from their own account after signing in.",
|
|
173
|
+
autoComplete: "new-password",
|
|
174
|
+
required: true
|
|
175
|
+
})
|
|
176
|
+
}),
|
|
177
|
+
/*#__PURE__*/ jsxs("div", {
|
|
178
|
+
className: classnames('byline-user-create-flags', create_module.flags),
|
|
179
|
+
children: [
|
|
180
|
+
/*#__PURE__*/ jsx(form.Field, {
|
|
181
|
+
name: "is_enabled",
|
|
182
|
+
children: (field)=>/*#__PURE__*/ jsx(Checkbox, {
|
|
183
|
+
id: "new-is-enabled",
|
|
184
|
+
name: field.name,
|
|
185
|
+
label: "Enabled",
|
|
186
|
+
checked: field.state.value,
|
|
187
|
+
onCheckedChange: (checked)=>field.handleChange(true === checked),
|
|
188
|
+
helpText: "Disabled accounts cannot sign in."
|
|
189
|
+
})
|
|
190
|
+
}),
|
|
191
|
+
/*#__PURE__*/ jsx(form.Field, {
|
|
192
|
+
name: "is_email_verified",
|
|
193
|
+
children: (field)=>/*#__PURE__*/ jsx(Checkbox, {
|
|
194
|
+
id: "new-is-email-verified",
|
|
195
|
+
name: field.name,
|
|
196
|
+
label: "Email verified",
|
|
197
|
+
checked: field.state.value,
|
|
198
|
+
onCheckedChange: (checked)=>field.handleChange(true === checked),
|
|
199
|
+
helpText: "Skip the verification flow for this account."
|
|
200
|
+
})
|
|
201
|
+
}),
|
|
202
|
+
/*#__PURE__*/ jsx(form.Field, {
|
|
203
|
+
name: "is_super_admin",
|
|
204
|
+
children: (field)=>/*#__PURE__*/ jsx(Checkbox, {
|
|
205
|
+
id: "new-is-super-admin",
|
|
206
|
+
name: field.name,
|
|
207
|
+
label: "Super admin",
|
|
208
|
+
checked: field.state.value,
|
|
209
|
+
onCheckedChange: (checked)=>field.handleChange(true === checked),
|
|
210
|
+
helpText: "Super admins bypass every ability check — grant with care."
|
|
211
|
+
})
|
|
212
|
+
})
|
|
213
|
+
]
|
|
214
|
+
}),
|
|
215
|
+
/*#__PURE__*/ jsxs("div", {
|
|
216
|
+
className: classnames('byline-user-create-actions', create_module.actions),
|
|
217
|
+
children: [
|
|
218
|
+
/*#__PURE__*/ jsx(Button, {
|
|
219
|
+
type: "button",
|
|
220
|
+
intent: "secondary",
|
|
221
|
+
size: "sm",
|
|
222
|
+
onClick: onClose,
|
|
223
|
+
className: classnames('byline-user-create-action', create_module.action),
|
|
224
|
+
children: "Cancel"
|
|
225
|
+
}),
|
|
226
|
+
/*#__PURE__*/ jsx(form.Subscribe, {
|
|
227
|
+
selector: (state)=>({
|
|
228
|
+
canSubmit: state.canSubmit,
|
|
229
|
+
isSubmitting: state.isSubmitting
|
|
230
|
+
}),
|
|
231
|
+
children: ({ canSubmit, isSubmitting })=>/*#__PURE__*/ jsx(Button, {
|
|
232
|
+
size: "sm",
|
|
233
|
+
intent: "primary",
|
|
234
|
+
type: "submit",
|
|
235
|
+
disabled: !canSubmit || isSubmitting,
|
|
236
|
+
className: classnames('byline-user-create-action', create_module.action),
|
|
237
|
+
children: true === isSubmitting ? /*#__PURE__*/ jsx(LoaderEllipsis, {
|
|
238
|
+
size: 42
|
|
239
|
+
}) : 'Save'
|
|
240
|
+
})
|
|
241
|
+
})
|
|
242
|
+
]
|
|
243
|
+
})
|
|
244
|
+
]
|
|
245
|
+
})
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
function firstError(errors) {
|
|
249
|
+
for (const err of errors){
|
|
250
|
+
if ('string' == typeof err) return err;
|
|
251
|
+
if (err && 'object' == typeof err && 'message' in err) {
|
|
252
|
+
const msg = err.message;
|
|
253
|
+
if ('string' == typeof msg) return msg;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function getErrorCode(err) {
|
|
258
|
+
if (err && 'object' == typeof err) {
|
|
259
|
+
const e = err;
|
|
260
|
+
if ('string' == typeof e.code) return e.code;
|
|
261
|
+
if (e.cause && 'object' == typeof e.cause && 'code' in e.cause) {
|
|
262
|
+
const cause = e.cause;
|
|
263
|
+
if ('string' == typeof cause.code) return cause.code;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
export { CreateAdminUser };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
:is(.wrap-zOIv8P, .byline-user-create-wrap) {
|
|
2
|
+
gap: var(--spacing-8);
|
|
3
|
+
padding: var(--spacing-4);
|
|
4
|
+
margin-top: var(--spacing-4);
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
display: flex;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
:is(.form-LV97FA, .byline-user-create-form) {
|
|
10
|
+
gap: var(--spacing-16);
|
|
11
|
+
padding-top: var(--spacing-8);
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
display: flex;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
:is(.grid-SZGMP9, .byline-user-create-grid) {
|
|
17
|
+
gap: var(--spacing-16);
|
|
18
|
+
grid-template-columns: 1fr;
|
|
19
|
+
display: grid;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@media (min-width: 40rem) {
|
|
23
|
+
:is(.grid-SZGMP9, .byline-user-create-grid) {
|
|
24
|
+
grid-template-columns: 1fr 1fr;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
:is(.flags-OuOEIh, .byline-user-create-flags) {
|
|
29
|
+
gap: var(--spacing-8);
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
display: flex;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
:is(.actions-krs2ow, .byline-user-create-actions) {
|
|
35
|
+
justify-content: flex-end;
|
|
36
|
+
align-items: center;
|
|
37
|
+
gap: var(--spacing-8);
|
|
38
|
+
margin-top: var(--spacing-16);
|
|
39
|
+
display: flex;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
:is(.action-bnHG9_, .byline-user-create-action) {
|
|
43
|
+
min-width: 4rem;
|
|
44
|
+
}
|
|
45
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AdminRoleResponse, UserRolesResponse } from '../../admin-roles/index.js';
|
|
2
|
+
import type { AdminUserResponse } from '../index.js';
|
|
3
|
+
interface UserRolesProps {
|
|
4
|
+
user: AdminUserResponse;
|
|
5
|
+
allRoles: AdminRoleResponse[];
|
|
6
|
+
initialRoleIds: string[];
|
|
7
|
+
onClose?: () => void;
|
|
8
|
+
onSaved?: (response: UserRolesResponse) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function UserRoles({ user, allRoles, initialRoleIds, onClose, onSaved }: UserRolesProps): import("react").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Alert, Button, Checkbox, LoaderEllipsis } from "@byline/ui/react";
|
|
5
|
+
import classnames from "classnames";
|
|
6
|
+
import { useBylineAdminServices } from "../../../services/admin-services-context.js";
|
|
7
|
+
import roles_module from "./roles.module.js";
|
|
8
|
+
function setsEqual(a, b) {
|
|
9
|
+
if (a.size !== b.size) return false;
|
|
10
|
+
for (const item of a)if (!b.has(item)) return false;
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
function UserRoles({ user, allRoles, initialRoleIds, onClose, onSaved }) {
|
|
14
|
+
const { setUserRoles } = useBylineAdminServices();
|
|
15
|
+
const [initialSet, setInitialSet] = useState(()=>new Set(initialRoleIds));
|
|
16
|
+
const [selected, setSelected] = useState(()=>new Set(initialRoleIds));
|
|
17
|
+
const [saving, setSaving] = useState(false);
|
|
18
|
+
const [error, setError] = useState(null);
|
|
19
|
+
const [successMessage, setSuccessMessage] = useState(null);
|
|
20
|
+
const isDirty = !setsEqual(selected, initialSet);
|
|
21
|
+
function handleToggle(roleId, checked) {
|
|
22
|
+
setSelected((current)=>{
|
|
23
|
+
const next = new Set(current);
|
|
24
|
+
if (checked) next.add(roleId);
|
|
25
|
+
else next.delete(roleId);
|
|
26
|
+
return next;
|
|
27
|
+
});
|
|
28
|
+
setSuccessMessage(null);
|
|
29
|
+
}
|
|
30
|
+
async function handleSave() {
|
|
31
|
+
if (saving) return;
|
|
32
|
+
setSaving(true);
|
|
33
|
+
setError(null);
|
|
34
|
+
setSuccessMessage(null);
|
|
35
|
+
try {
|
|
36
|
+
const response = await setUserRoles({
|
|
37
|
+
data: {
|
|
38
|
+
userId: user.id,
|
|
39
|
+
roleIds: Array.from(selected)
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
const storedSet = new Set(response.roles.map((r)=>r.id));
|
|
43
|
+
setInitialSet(storedSet);
|
|
44
|
+
setSelected(new Set(storedSet));
|
|
45
|
+
setSuccessMessage('Saved.');
|
|
46
|
+
onSaved?.(response);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
const code = getErrorCode(err);
|
|
49
|
+
if ('admin.roles.userNotFound' === code) setError('This user no longer exists.');
|
|
50
|
+
else 'admin.roles.notFound' === code ? setError('One or more selected roles no longer exist. Reload the page and try again.') : setError('Could not save roles. Please try again.');
|
|
51
|
+
} finally{
|
|
52
|
+
setSaving(false);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
56
|
+
className: classnames('byline-user-roles-wrap', roles_module.wrap),
|
|
57
|
+
children: [
|
|
58
|
+
error ? /*#__PURE__*/ jsx(Alert, {
|
|
59
|
+
intent: "danger",
|
|
60
|
+
children: error
|
|
61
|
+
}) : null,
|
|
62
|
+
successMessage ? /*#__PURE__*/ jsx(Alert, {
|
|
63
|
+
intent: "success",
|
|
64
|
+
children: successMessage
|
|
65
|
+
}) : null,
|
|
66
|
+
0 === allRoles.length ? /*#__PURE__*/ jsxs("p", {
|
|
67
|
+
className: classnames('muted', 'byline-user-roles-empty', roles_module.empty),
|
|
68
|
+
children: [
|
|
69
|
+
"No roles have been created yet. Create roles in",
|
|
70
|
+
' ',
|
|
71
|
+
/*#__PURE__*/ jsx("span", {
|
|
72
|
+
className: "muted",
|
|
73
|
+
children: "/admin/roles"
|
|
74
|
+
}),
|
|
75
|
+
" first."
|
|
76
|
+
]
|
|
77
|
+
}) : /*#__PURE__*/ jsx("div", {
|
|
78
|
+
className: classnames('byline-user-roles-list', roles_module.list),
|
|
79
|
+
children: allRoles.map((role)=>/*#__PURE__*/ jsxs("div", {
|
|
80
|
+
className: classnames('byline-user-roles-row', roles_module.row),
|
|
81
|
+
children: [
|
|
82
|
+
/*#__PURE__*/ jsx(Checkbox, {
|
|
83
|
+
id: `role-${role.id}`,
|
|
84
|
+
name: `role-${role.id}`,
|
|
85
|
+
checked: selected.has(role.id),
|
|
86
|
+
disabled: saving,
|
|
87
|
+
onCheckedChange: (checked)=>handleToggle(role.id, true === checked),
|
|
88
|
+
containerClasses: classnames('byline-user-roles-checkbox-auto', roles_module["checkbox-auto"]),
|
|
89
|
+
componentClasses: classnames('byline-user-roles-checkbox-auto', roles_module["checkbox-auto"])
|
|
90
|
+
}),
|
|
91
|
+
/*#__PURE__*/ jsxs("label", {
|
|
92
|
+
htmlFor: `role-${role.id}`,
|
|
93
|
+
className: classnames('byline-user-roles-label', roles_module.label),
|
|
94
|
+
children: [
|
|
95
|
+
/*#__PURE__*/ jsxs("div", {
|
|
96
|
+
className: classnames('byline-user-roles-label-head', roles_module["label-head"]),
|
|
97
|
+
children: [
|
|
98
|
+
/*#__PURE__*/ jsx("span", {
|
|
99
|
+
className: classnames('byline-user-roles-name', roles_module.name),
|
|
100
|
+
children: role.name
|
|
101
|
+
}),
|
|
102
|
+
/*#__PURE__*/ jsx("code", {
|
|
103
|
+
className: classnames('byline-user-roles-machine', roles_module.machine),
|
|
104
|
+
children: role.machine_name
|
|
105
|
+
})
|
|
106
|
+
]
|
|
107
|
+
}),
|
|
108
|
+
role.description ? /*#__PURE__*/ jsx("p", {
|
|
109
|
+
className: classnames('muted', "byline-user-roles-description", roles_module.description),
|
|
110
|
+
children: role.description
|
|
111
|
+
}) : null
|
|
112
|
+
]
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
}, role.id))
|
|
116
|
+
}),
|
|
117
|
+
/*#__PURE__*/ jsxs("div", {
|
|
118
|
+
className: classnames('byline-user-roles-actions', roles_module.actions),
|
|
119
|
+
children: [
|
|
120
|
+
/*#__PURE__*/ jsx(Button, {
|
|
121
|
+
type: "button",
|
|
122
|
+
intent: "secondary",
|
|
123
|
+
size: "xs",
|
|
124
|
+
onClick: onClose,
|
|
125
|
+
disabled: saving,
|
|
126
|
+
className: classnames('byline-user-roles-action', roles_module.action),
|
|
127
|
+
children: successMessage ? 'Close' : 'Cancel'
|
|
128
|
+
}),
|
|
129
|
+
/*#__PURE__*/ jsx(Button, {
|
|
130
|
+
type: "button",
|
|
131
|
+
intent: "primary",
|
|
132
|
+
size: "xs",
|
|
133
|
+
onClick: ()=>void handleSave(),
|
|
134
|
+
disabled: saving || !isDirty,
|
|
135
|
+
className: classnames('byline-user-roles-action', roles_module.action),
|
|
136
|
+
children: saving ? /*#__PURE__*/ jsx(LoaderEllipsis, {
|
|
137
|
+
size: 30
|
|
138
|
+
}) : 'Save'
|
|
139
|
+
})
|
|
140
|
+
]
|
|
141
|
+
})
|
|
142
|
+
]
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function getErrorCode(err) {
|
|
146
|
+
return 'string' == typeof err?.code ? err.code : null;
|
|
147
|
+
}
|
|
148
|
+
export { UserRoles };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "./roles_module.css";
|
|
2
|
+
const roles_module = {
|
|
3
|
+
wrap: "wrap-YWdaNF",
|
|
4
|
+
empty: "empty-ZsVXJY",
|
|
5
|
+
list: "list-RsMY7h",
|
|
6
|
+
row: "row-F_1l24",
|
|
7
|
+
label: "label-N6501i",
|
|
8
|
+
"label-head": "label-head-gZregN",
|
|
9
|
+
labelHead: "label-head-gZregN",
|
|
10
|
+
name: "name-hgEsQB",
|
|
11
|
+
machine: "machine-VzeuNO",
|
|
12
|
+
description: "description-xE3mA4",
|
|
13
|
+
actions: "actions-A6I1GP",
|
|
14
|
+
action: "action-etRmtU",
|
|
15
|
+
"checkbox-auto": "checkbox-auto-ioL2ME",
|
|
16
|
+
checkboxAuto: "checkbox-auto-ioL2ME"
|
|
17
|
+
};
|
|
18
|
+
export default roles_module;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
:is(.wrap-YWdaNF, .byline-user-roles-wrap) {
|
|
2
|
+
gap: var(--spacing-12);
|
|
3
|
+
padding: var(--spacing-4);
|
|
4
|
+
margin-top: var(--spacing-4);
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
display: flex;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
:is(.empty-ZsVXJY, .byline-user-roles-empty) {
|
|
10
|
+
margin: 0;
|
|
11
|
+
font-style: italic;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
:is(.list-RsMY7h, .byline-user-roles-list) {
|
|
15
|
+
gap: var(--spacing-4);
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
display: flex;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
:is(.row-F_1l24, .byline-user-roles-row) {
|
|
21
|
+
align-items: flex-start;
|
|
22
|
+
gap: var(--spacing-8);
|
|
23
|
+
padding: var(--spacing-4) 0;
|
|
24
|
+
display: flex;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
:is(.label-N6501i, .byline-user-roles-label) {
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
flex: 1 1 0;
|
|
30
|
+
min-width: 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
:is(.label-head-gZregN, .byline-user-roles-label-head) {
|
|
34
|
+
align-items: center;
|
|
35
|
+
gap: var(--spacing-8);
|
|
36
|
+
display: flex;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
:is(.name-hgEsQB, .byline-user-roles-name) {
|
|
40
|
+
font-size: var(--font-size-sm);
|
|
41
|
+
font-weight: var(--font-weight-medium);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
:is(.machine-VzeuNO, .byline-user-roles-machine) {
|
|
45
|
+
background-color: var(--gray-100);
|
|
46
|
+
font-size: var(--font-size-xs);
|
|
47
|
+
border-radius: var(--border-radius-sm);
|
|
48
|
+
padding: .125rem .375rem;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
:is(.description-xE3mA4, .byline-user-roles-description) {
|
|
52
|
+
font-size: var(--font-size-xs);
|
|
53
|
+
margin-bottom: 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
:is(.actions-A6I1GP, .byline-user-roles-actions) {
|
|
57
|
+
justify-content: flex-end;
|
|
58
|
+
align-items: center;
|
|
59
|
+
gap: var(--spacing-8);
|
|
60
|
+
margin-top: var(--spacing-16);
|
|
61
|
+
display: flex;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
:is(.action-etRmtU, .byline-user-roles-action) {
|
|
65
|
+
min-width: 4rem;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
:is(.checkbox-auto-ioL2ME, .byline-user-roles-checkbox-auto) {
|
|
69
|
+
width: auto !important;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
:is(:is([data-theme="dark"], .dark) .machine-VzeuNO, :is([data-theme="dark"], .dark) .byline-user-roles-machine) {
|
|
73
|
+
background-color: var(--canvas-800);
|
|
74
|
+
}
|
|
75
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AdminUserResponse } from '../index.js';
|
|
2
|
+
interface SetPasswordProps {
|
|
3
|
+
user: AdminUserResponse;
|
|
4
|
+
onClose?: () => void;
|
|
5
|
+
onSuccess?: (user: AdminUserResponse) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function SetPassword({ user, onClose, onSuccess }: SetPasswordProps): import("react").JSX.Element;
|
|
8
|
+
export {};
|