mirror of
https://github.com/immich-app/immich.git
synced 2025-01-21 00:52:43 -05:00
refactor(web): admin and user signup forms (#7739)
This commit is contained in:
parent
46597aac97
commit
ffdd504008
2 changed files with 28 additions and 44 deletions
|
@ -6,9 +6,12 @@
|
||||||
import Button from '../elements/buttons/button.svelte';
|
import Button from '../elements/buttons/button.svelte';
|
||||||
import PasswordField from '../shared-components/password-field.svelte';
|
import PasswordField from '../shared-components/password-field.svelte';
|
||||||
|
|
||||||
let errorMessage: string;
|
let email = '';
|
||||||
let password = '';
|
let password = '';
|
||||||
let confirmPassword = '';
|
let confirmPassword = '';
|
||||||
|
let name = '';
|
||||||
|
|
||||||
|
let errorMessage: string;
|
||||||
let canRegister = false;
|
let canRegister = false;
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
|
@ -21,25 +24,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function registerAdmin(event: SubmitEvent & { currentTarget: HTMLFormElement }) {
|
async function registerAdmin() {
|
||||||
if (canRegister) {
|
if (canRegister) {
|
||||||
errorMessage = '';
|
errorMessage = '';
|
||||||
|
|
||||||
const form = new FormData(event.currentTarget);
|
|
||||||
|
|
||||||
const email = form.get('email');
|
|
||||||
const password = form.get('password');
|
|
||||||
const name = form.get('name');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await signUpAdmin({
|
await signUpAdmin({ signUpDto: { email, password, name } });
|
||||||
signUpDto: {
|
|
||||||
email: String(email),
|
|
||||||
password: String(password),
|
|
||||||
name: String(name),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await goto(AppRoute.AUTH_LOGIN);
|
await goto(AppRoute.AUTH_LOGIN);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, 'Unable to create admin account');
|
handleError(error, 'Unable to create admin account');
|
||||||
|
@ -52,12 +42,12 @@
|
||||||
<form on:submit|preventDefault={registerAdmin} method="post" class="mt-5 flex flex-col gap-5">
|
<form on:submit|preventDefault={registerAdmin} method="post" class="mt-5 flex flex-col gap-5">
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<label class="immich-form-label" for="email">Admin Email</label>
|
<label class="immich-form-label" for="email">Admin Email</label>
|
||||||
<input class="immich-form-input" id="email" name="email" type="email" autocomplete="email" required />
|
<input class="immich-form-input" id="email" bind:value={email} type="email" autocomplete="email" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<label class="immich-form-label" for="password">Admin Password</label>
|
<label class="immich-form-label" for="password">Admin Password</label>
|
||||||
<PasswordField id="password" name="password" bind:password autocomplete="new-password" />
|
<PasswordField id="password" bind:password autocomplete="new-password" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
|
@ -67,7 +57,7 @@
|
||||||
|
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<label class="immich-form-label" for="name">Name</label>
|
<label class="immich-form-label" for="name">Name</label>
|
||||||
<input class="immich-form-input" id="name" name="name" type="text" autocomplete="name" required />
|
<input class="immich-form-input" id="name" bind:value={name} type="text" autocomplete="name" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if errorMessage}
|
{#if errorMessage}
|
||||||
|
|
|
@ -12,15 +12,18 @@
|
||||||
let error: string;
|
let error: string;
|
||||||
let success: string;
|
let success: string;
|
||||||
|
|
||||||
|
let email = '';
|
||||||
let password = '';
|
let password = '';
|
||||||
let confirmPassword = '';
|
let confirmPassword = '';
|
||||||
|
let name = '';
|
||||||
let shouldChangePassword = true;
|
let shouldChangePassword = true;
|
||||||
|
|
||||||
let canCreateUser = false;
|
let canCreateUser = false;
|
||||||
let quotaSize: number | undefined;
|
let quotaSize: number | undefined;
|
||||||
let isCreatingUser = false;
|
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) {
|
if (password !== confirmPassword && confirmPassword.length > 0) {
|
||||||
|
@ -36,29 +39,19 @@
|
||||||
cancel: void;
|
cancel: void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
async function registerUser(event: SubmitEvent) {
|
async function registerUser() {
|
||||||
if (canCreateUser && !isCreatingUser) {
|
if (canCreateUser && !isCreatingUser) {
|
||||||
isCreatingUser = true;
|
isCreatingUser = true;
|
||||||
|
|
||||||
error = '';
|
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 {
|
try {
|
||||||
await createUser({
|
await createUser({
|
||||||
createUserDto: {
|
createUserDto: {
|
||||||
email: String(email),
|
email,
|
||||||
password: String(password),
|
password,
|
||||||
shouldChangePassword: Boolean(shouldChangePassword),
|
shouldChangePassword,
|
||||||
name: String(name),
|
name,
|
||||||
quotaSizeInBytes: quotaSize ? convertToBytes(Number(quotaSize), 'GiB') : null,
|
quotaSizeInBytes,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -87,12 +80,12 @@
|
||||||
<form on:submit|preventDefault={registerUser} autocomplete="off">
|
<form on:submit|preventDefault={registerUser} autocomplete="off">
|
||||||
<div class="m-4 flex flex-col gap-2">
|
<div class="m-4 flex flex-col gap-2">
|
||||||
<label class="immich-form-label" for="email">Email</label>
|
<label class="immich-form-label" for="email">Email</label>
|
||||||
<input class="immich-form-input" id="email" name="email" type="email" required />
|
<input class="immich-form-input" id="email" bind:value={email} type="email" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="m-4 flex flex-col gap-2">
|
<div class="m-4 flex flex-col gap-2">
|
||||||
<label class="immich-form-label" for="password">Password</label>
|
<label class="immich-form-label" for="password">Password</label>
|
||||||
<PasswordField id="password" name="password" bind:password autocomplete="new-password" />
|
<PasswordField id="password" bind:password autocomplete="new-password" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="m-4 flex flex-col gap-2">
|
<div class="m-4 flex flex-col gap-2">
|
||||||
|
@ -109,16 +102,17 @@
|
||||||
|
|
||||||
<div class="m-4 flex flex-col gap-2">
|
<div class="m-4 flex flex-col gap-2">
|
||||||
<label class="immich-form-label" for="name">Name</label>
|
<label class="immich-form-label" for="name">Name</label>
|
||||||
<input class="immich-form-input" id="name" name="name" type="text" required />
|
<input class="immich-form-input" id="name" bind:value={name} type="text" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="m-4 flex flex-col gap-2">
|
<div class="m-4 flex flex-col gap-2">
|
||||||
<label class="flex items-center gap-2 immich-form-label" for="quotaSize"
|
<label class="flex items-center gap-2 immich-form-label" for="quotaSize">
|
||||||
>Quota Size (GiB) {#if quotaSizeWarning}
|
Quota Size (GiB)
|
||||||
|
{#if quotaSizeWarning}
|
||||||
<p class="text-red-400 text-sm">You set a quota higher than the disk size</p>
|
<p class="text-red-400 text-sm">You set a quota higher than the disk size</p>
|
||||||
{/if}</label
|
{/if}
|
||||||
>
|
</label>
|
||||||
<input class="immich-form-input" id="quotaSize" name="quotaSize" type="number" min="0" bind:value={quotaSize} />
|
<input class="immich-form-input" id="quotaSize" type="number" min="0" bind:value={quotaSize} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if error}
|
{#if error}
|
||||||
|
|
Loading…
Add table
Reference in a new issue