From ffdd504008ec9752dfff714b5c856b45606998f9 Mon Sep 17 00:00:00 2001 From: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Date: Fri, 8 Mar 2024 14:45:41 +0100 Subject: [PATCH] refactor(web): admin and user signup forms (#7739) --- .../forms/admin-registration-form.svelte | 28 ++++-------- .../components/forms/create-user-form.svelte | 44 ++++++++----------- 2 files changed, 28 insertions(+), 44 deletions(-) diff --git a/web/src/lib/components/forms/admin-registration-form.svelte b/web/src/lib/components/forms/admin-registration-form.svelte index 0781ef226b..0481dbf458 100644 --- a/web/src/lib/components/forms/admin-registration-form.svelte +++ b/web/src/lib/components/forms/admin-registration-form.svelte @@ -6,9 +6,12 @@ import Button from '../elements/buttons/button.svelte'; import PasswordField from '../shared-components/password-field.svelte'; - let errorMessage: string; + let email = ''; let password = ''; let confirmPassword = ''; + let name = ''; + + let errorMessage: string; let canRegister = false; $: { @@ -21,25 +24,12 @@ } } - async function registerAdmin(event: SubmitEvent & { currentTarget: HTMLFormElement }) { + async function registerAdmin() { if (canRegister) { errorMessage = ''; - const form = new FormData(event.currentTarget); - - const email = form.get('email'); - const password = form.get('password'); - const name = form.get('name'); - try { - await signUpAdmin({ - signUpDto: { - email: String(email), - password: String(password), - name: String(name), - }, - }); - + await signUpAdmin({ signUpDto: { email, password, name } }); await goto(AppRoute.AUTH_LOGIN); } catch (error) { handleError(error, 'Unable to create admin account'); @@ -52,12 +42,12 @@
- +
- +
@@ -67,7 +57,7 @@
- +
{#if errorMessage} diff --git a/web/src/lib/components/forms/create-user-form.svelte b/web/src/lib/components/forms/create-user-form.svelte index d3b52dbd86..00188ec2eb 100644 --- a/web/src/lib/components/forms/create-user-form.svelte +++ b/web/src/lib/components/forms/create-user-form.svelte @@ -12,15 +12,18 @@ let error: string; let success: string; + let email = ''; let password = ''; let confirmPassword = ''; + let name = ''; let shouldChangePassword = true; let canCreateUser = false; let quotaSize: number | undefined; let isCreatingUser = false; - $: quotaSizeWarning = quotaSize && convertToBytes(Number(quotaSize), 'GiB') > $serverInfo.diskSizeRaw; + $: quotaSizeInBytes = quotaSize ? convertToBytes(quotaSize, 'GiB') : null; + $: quotaSizeWarning = quotaSizeInBytes && quotaSizeInBytes > $serverInfo.diskSizeRaw; $: { if (password !== confirmPassword && confirmPassword.length > 0) { @@ -36,29 +39,19 @@ cancel: void; }>(); - async function registerUser(event: SubmitEvent) { + async function registerUser() { if (canCreateUser && !isCreatingUser) { isCreatingUser = true; - error = ''; - const formElement = event.target as HTMLFormElement; - - const form = new FormData(formElement); - - const email = form.get('email'); - const password = form.get('password'); - const name = form.get('name'); - const quotaSize = form.get('quotaSize'); - try { await createUser({ createUserDto: { - email: String(email), - password: String(password), - shouldChangePassword: Boolean(shouldChangePassword), - name: String(name), - quotaSizeInBytes: quotaSize ? convertToBytes(Number(quotaSize), 'GiB') : null, + email, + password, + shouldChangePassword, + name, + quotaSizeInBytes, }, }); @@ -87,12 +80,12 @@
- +
- +
@@ -109,16 +102,17 @@
- +
- +
{#if error}