Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Jul 8, 2024
2 parents 632b2d5 + 00ec9a5 commit b6f80ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions frontend/src/lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"email_label": "Email",
"name_label": "Display name",
"password_label": "Change User Password",
"role_label": {
"label": "Role",
"verified_email_required_for_admin": "The user must provide a verified email address to gain administrator access."
},
"update_user": "Update User",
"lock": "Lock User",
"unlock": "Unlock User",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/routes/(authenticated)/admin/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export async function _changeUserAccountByAdmin(input: ChangeUserAccountByAdminI
name
email
isAdmin
emailVerified
}
errors {
__typename
Expand Down
19 changes: 14 additions & 5 deletions frontend/src/routes/(authenticated)/admin/EditUserAccount.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@
export let currUser: LexAuthUser;
export let deleteUser: (user: User) => void;
const schema = z.object({
const schema = z
.object({
email: z.string().email($t('form.invalid_email')).nullish(),
emailVerified: z.boolean(),
name: z.string(),
password: passwordFormRules($t).or(emptyString()).default(''),
score: z.number(),
role: z.enum([UserRole.User, UserRole.Admin]),
});
})
const refinedSchema = schema
.refine((data) => data.role !== UserRole.Admin || (data.email && data.emailVerified), {
message: $t('admin_dashboard.form_modal.role_label.verified_email_required_for_admin'),
path: ['role'],
});
type Schema = typeof schema;
let formModal: FormModal<Schema>;
type RefinedSchema = typeof refinedSchema;
let formModal: FormModal<RefinedSchema>;
$: form = formModal?.form();
export function close(): void {
Expand All @@ -40,7 +49,7 @@
_user = user;
userIsLocked = user.locked;
const role = user.isAdmin ? UserRole.Admin : UserRole.User;
return await formModal.open({ name: user.name, email: user.email ?? null, role }, async () => {
return await formModal.open({ name: user.name, email: user.email ?? null, role, emailVerified: user.emailVerified }, async () => {
const { error, data } = await _changeUserAccountByAdmin({
userId: user.id,
email: $form.email,
Expand Down Expand Up @@ -85,7 +94,7 @@
}
</script>

<FormModal bind:this={formModal} {schema} let:errors>
<FormModal bind:this={formModal} schema={refinedSchema} let:errors>
<span slot="title">
{$t('admin_dashboard.form_modal.title')}
</span>
Expand Down

0 comments on commit b6f80ed

Please sign in to comment.