Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show notification and filter users after creating a new user #820

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions frontend/src/lib/components/Users/CreateUser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import PasswordStrengthMeter from '$lib/components/PasswordStrengthMeter.svelte';
import { SubmitButton, FormError, Input, Form, ProtectedForm, isEmail, lexSuperForm, passwordFormRules, DisplayLanguageSelect } from '$lib/forms';
import t, { getLanguageCodeFromNavigator, locale } from '$lib/i18n';
import { type RegisterResponse } from '$lib/user';
import { type LexAuthUser, type RegisterResponse } from '$lib/user';
import { getSearchParamValues } from '$lib/util/query-params';
import { createEventDispatcher, onMount } from 'svelte';
import { usernameRe } from '$lib/user';
Expand All @@ -13,7 +13,9 @@
export let submitButtonText = $t('register.button_register');
export let handleSubmit: (password: string, passwordStrength: number, name: string, email: string, locale: string, turnstileToken: string) => Promise<RegisterResponse>;

const dispatch = createEventDispatcher();
const dispatch = createEventDispatcher<{
submitted: LexAuthUser,
}>();

type RegisterPageQueryParams = {
name: string;
Expand Down Expand Up @@ -46,15 +48,15 @@
$message = $t('turnstile.invalid');
}
if (error.accountExists) {
$errors.email = [$t('register.account_exists')];
$errors.email = [validateAsEmail($form.email) ? $t('register.account_exists_email') : $t('register.account_exists_login')];
}
if (error.invalidInput) {
$errors.email = [validateAsEmail($form.email) ? $t('form.invalid_email') : $t('register.invalid_username')];
}
return;
}
if (user) {
dispatch('submitted');
dispatch('submitted', user);
return;
}
throw new Error('Unknown error, no error from server, but also no user.');
Expand Down
12 changes: 10 additions & 2 deletions frontend/src/lib/components/Users/CreateUserModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
import { Modal } from '$lib/components/modals';
import t from '$lib/i18n';
import { helpLinks } from '$lib/components/help';
import { type RegisterResponse } from '$lib/user';
import { type LexAuthUser, type RegisterResponse } from '$lib/user';
import CreateUser from '$lib/components/Users/CreateUser.svelte';
import Markdown from 'svelte-exmarkdown';
import { NewTabLinkRenderer } from '$lib/components/Markdown';
import Icon from '$lib/icons/Icon.svelte';
import { createEventDispatcher } from 'svelte';

const dispatch = createEventDispatcher<{
submitted: LexAuthUser,
}>();

let createUserModal: Modal;
export let handleSubmit: (password: string, passwordStrength: number, name: string, email: string, locale: string, turnstileToken: string) => Promise<RegisterResponse>;
Expand Down Expand Up @@ -35,7 +40,10 @@
</div>
<h1 class="text-center text-xl">{$t('admin_dashboard.create_user_modal.create_user')}</h1>
<CreateUser {handleSubmit} allowUsernames skipTurnstile
on:submitted={() => createUserModal.submitModal()}
on:submitted={(event) => {
createUserModal.submitModal();
dispatch('submitted', event.detail);
}}
submitButtonText={$t('admin_dashboard.create_user_modal.create_user')}
/>
</Modal>
4 changes: 3 additions & 1 deletion frontend/src/lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"notifications": {
"user_deleted": "{name} has been deleted.",
"user_updated": "{name} has been updated.",
"user_created": "{name} has been created.",
"email_need_verification": "You've requested to change the e-mail address for {name} to {requestedEmail}. The change will only come into effect when the user verifies the new address. They can do so using the link in the e-mail we just sent them."
},
"user_is_locked": "This user is locked. They cannot log in or Send/Receive until an administrator unlocks them.",
Expand Down Expand Up @@ -388,7 +389,8 @@ If you don't see a dialog or already closed it, click the button below:",
},
"register": {
"title": "Register",
"account_exists": "An account with this email already exists",
"account_exists_email": "An account with this email already exists",
"account_exists_login": "An account with this login/username already exists",
"invalid_username": "Invalid login/username. Only letters, numbers, and underscore (_) characters are allowed.",
"button_register": "Register",
"label_email": "Email",
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/routes/(authenticated)/admin/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import { Button } from '$lib/forms';
import { PageBreadcrumb } from '$lib/layout';
import AdminTabs, { type AdminTabId } from './AdminTabs.svelte';
import { createGuestUserByAdmin } from '$lib/user';
import { createGuestUserByAdmin, type LexAuthUser } from '$lib/user';
import CreateUserModal from '$lib/components/Users/CreateUserModal.svelte';
import type { Confidentiality } from '$lib/components/Projects';

Expand Down Expand Up @@ -100,6 +100,11 @@
}
}
}

function onUserCreated(user: LexAuthUser): void {
notifySuccess($t('admin_dashboard.notifications.user_created', { name: user.name }), Duration.Long);
$queryParamValues.userSearch = user.emailOrUsername;
}
</script>

<svelte:head>
Expand Down Expand Up @@ -247,5 +252,5 @@
<EditUserAccount bind:this={formModal} {deleteUser} currUser={data.user} />
<DeleteUserModal bind:this={deleteUserModal} i18nScope="admin_dashboard.form_modal.delete_user" />
<UserModal bind:this={userModal}/>
<CreateUserModal handleSubmit={createGuestUserByAdmin} bind:this={createUserModal}/>
<CreateUserModal handleSubmit={createGuestUserByAdmin} on:submitted={(e) => onUserCreated(e.detail)} bind:this={createUserModal}/>
</main>
Loading