2022-08-12 14:25:19 -05:00
|
|
|
<script lang="ts">
|
2023-10-25 09:48:25 -04:00
|
|
|
import Icon from '$lib/components/elements/icon.svelte';
|
2024-02-13 17:07:37 -05:00
|
|
|
import ConfirmDialogue from '$lib/components/shared-components/confirm-dialogue.svelte';
|
2023-12-12 03:35:57 +01:00
|
|
|
import { AppRoute } from '$lib/constants';
|
2024-01-30 18:21:45 +01:00
|
|
|
import { serverInfo } from '$lib/stores/server-info.store';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { convertFromBytes, convertToBytes } from '$lib/utils/byte-converter';
|
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
|
|
|
import { updateUser, type UserResponseDto } from '@immich/sdk';
|
|
|
|
import { mdiAccountEditOutline, mdiClose } from '@mdi/js';
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
import Button from '../elements/buttons/button.svelte';
|
|
|
|
import CircleIconButton from '../elements/buttons/circle-icon-button.svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
export let user: UserResponseDto;
|
|
|
|
export let canResetPassword = true;
|
|
|
|
|
|
|
|
let error: string;
|
|
|
|
let success: string;
|
|
|
|
let isShowResetPasswordConfirmation = false;
|
2024-01-30 18:21:45 +01:00
|
|
|
let quotaSize = user.quotaSizeInBytes ? convertFromBytes(user.quotaSizeInBytes, 'GiB') : null;
|
|
|
|
|
|
|
|
const previousQutoa = user.quotaSizeInBytes;
|
|
|
|
|
|
|
|
$: quotaSizeWarning =
|
|
|
|
previousQutoa !== convertToBytes(Number(quotaSize), 'GiB') &&
|
|
|
|
!!quotaSize &&
|
|
|
|
convertToBytes(Number(quotaSize), 'GiB') > $serverInfo.diskSizeRaw;
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2023-12-14 17:55:15 +01:00
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
close: void;
|
|
|
|
resetPasswordSuccess: void;
|
|
|
|
editSuccess: void;
|
|
|
|
}>();
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
const editUser = async () => {
|
|
|
|
try {
|
2024-02-29 19:35:37 +01:00
|
|
|
const { id, email, name, storageLabel } = user;
|
2024-02-13 17:07:37 -05:00
|
|
|
await updateUser({
|
2023-07-01 00:50:47 -04:00
|
|
|
updateUserDto: {
|
|
|
|
id,
|
|
|
|
email,
|
2023-11-11 20:03:32 -05:00
|
|
|
name,
|
2023-07-01 00:50:47 -04:00
|
|
|
storageLabel: storageLabel || '',
|
2024-01-12 18:43:36 -06:00
|
|
|
quotaSizeInBytes: quotaSize ? convertToBytes(Number(quotaSize), 'GiB') : null,
|
2023-07-01 00:50:47 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
dispatch('editSuccess');
|
2023-07-01 00:50:47 -04:00
|
|
|
} catch (error) {
|
|
|
|
handleError(error, 'Unable to update user');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const resetPassword = async () => {
|
|
|
|
try {
|
|
|
|
const defaultPassword = 'password';
|
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
await updateUser({
|
2023-07-01 00:50:47 -04:00
|
|
|
updateUserDto: {
|
|
|
|
id: user.id,
|
|
|
|
password: defaultPassword,
|
|
|
|
shouldChangePassword: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
dispatch('resetPasswordSuccess');
|
2024-02-02 04:18:00 +01:00
|
|
|
} catch (error) {
|
2024-02-13 17:07:37 -05:00
|
|
|
handleError(error, 'Unable to reset password');
|
2023-07-01 00:50:47 -04:00
|
|
|
} finally {
|
|
|
|
isShowResetPasswordConfirmation = false;
|
|
|
|
}
|
|
|
|
};
|
2022-08-12 14:25:19 -05:00
|
|
|
</script>
|
|
|
|
|
2022-10-26 11:10:48 -05:00
|
|
|
<div
|
2023-12-14 17:55:15 +01:00
|
|
|
class="relative max-h-screen w-[500px] max-w-[95vw] overflow-y-auto rounded-3xl border bg-immich-bg p-4 py-8 shadow-sm dark:border-immich-dark-gray dark:bg-immich-dark-gray dark:text-immich-dark-fg"
|
2022-10-26 11:10:48 -05:00
|
|
|
>
|
2023-12-14 17:55:15 +01:00
|
|
|
<div class="absolute top-0 right-0 px-2 py-2 h-fit">
|
|
|
|
<CircleIconButton icon={mdiClose} on:click={() => dispatch('close')} />
|
|
|
|
</div>
|
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div
|
2023-07-18 13:19:39 -05:00
|
|
|
class="flex flex-col place-content-center place-items-center gap-4 px-4 text-immich-primary dark:text-immich-dark-primary"
|
2023-07-01 00:50:47 -04:00
|
|
|
>
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={mdiAccountEditOutline} size="4em" />
|
2023-07-18 13:19:39 -05:00
|
|
|
<h1 class="text-2xl font-medium text-immich-primary dark:text-immich-dark-primary">Edit user</h1>
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<form on:submit|preventDefault={editUser} autocomplete="off">
|
|
|
|
<div class="m-4 flex flex-col gap-2">
|
|
|
|
<label class="immich-form-label" for="email">Email</label>
|
|
|
|
<input class="immich-form-input" id="email" name="email" type="email" bind:value={user.email} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="m-4 flex flex-col gap-2">
|
2023-11-11 20:03:32 -05:00
|
|
|
<label class="immich-form-label" for="name">Name</label>
|
|
|
|
<input class="immich-form-input" id="name" name="name" type="text" required bind:value={user.name} />
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
|
|
|
|
2024-01-12 18:43:36 -06:00
|
|
|
<div class="m-4 flex flex-col gap-2">
|
2024-01-30 18:21:45 +01:00
|
|
|
<label class="flex items-center gap-2 immich-form-label" for="quotaSize"
|
|
|
|
>Quota Size (GiB) {#if quotaSizeWarning}
|
|
|
|
<p class="text-red-400 text-sm">You set a quota higher than the disk size</p>
|
|
|
|
{/if}</label
|
|
|
|
>
|
2024-01-12 18:43:36 -06:00
|
|
|
<input class="immich-form-input" id="quotaSize" name="quotaSize" type="number" min="0" bind:value={quotaSize} />
|
2024-01-15 09:04:29 -06:00
|
|
|
<p>Note: Enter 0 for unlimited quota</p>
|
2024-01-12 18:43:36 -06:00
|
|
|
</div>
|
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="m-4 flex flex-col gap-2">
|
|
|
|
<label class="immich-form-label" for="storage-label">Storage Label</label>
|
|
|
|
<input
|
|
|
|
class="immich-form-input"
|
|
|
|
id="storage-label"
|
|
|
|
name="storage-label"
|
|
|
|
type="text"
|
|
|
|
bind:value={user.storageLabel}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Note: To apply the Storage Label to previously uploaded assets, run the
|
2023-12-12 03:35:57 +01:00
|
|
|
<a href={AppRoute.ADMIN_JOBS} class="text-immich-primary dark:text-immich-dark-primary">
|
2023-07-01 00:50:47 -04:00
|
|
|
Storage Migration Job</a
|
|
|
|
>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{#if error}
|
2023-07-18 13:19:39 -05:00
|
|
|
<p class="ml-4 text-sm text-red-400">{error}</p>
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
{#if success}
|
2023-07-18 13:19:39 -05:00
|
|
|
<p class="ml-4 text-sm text-immich-primary">{success}</p>
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
2023-07-18 13:19:39 -05:00
|
|
|
<div class="mt-8 flex w-full gap-4 px-4">
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if canResetPassword}
|
|
|
|
<Button color="light-red" fullwidth on:click={() => (isShowResetPasswordConfirmation = true)}
|
|
|
|
>Reset password</Button
|
|
|
|
>
|
|
|
|
{/if}
|
|
|
|
<Button type="submit" fullwidth>Confirm</Button>
|
|
|
|
</div>
|
|
|
|
</form>
|
2022-08-12 14:25:19 -05:00
|
|
|
</div>
|
2023-06-30 21:53:16 +02:00
|
|
|
|
|
|
|
{#if isShowResetPasswordConfirmation}
|
2023-07-01 00:50:47 -04:00
|
|
|
<ConfirmDialogue
|
|
|
|
title="Reset Password"
|
|
|
|
confirmText="Reset"
|
|
|
|
on:confirm={resetPassword}
|
|
|
|
on:cancel={() => (isShowResetPasswordConfirmation = false)}
|
|
|
|
>
|
|
|
|
<svelte:fragment slot="prompt">
|
|
|
|
<p>
|
2023-11-11 20:03:32 -05:00
|
|
|
Are you sure you want to reset <b>{user.name}</b>'s password?
|
2023-07-01 00:50:47 -04:00
|
|
|
</p>
|
|
|
|
</svelte:fragment>
|
|
|
|
</ConfirmDialogue>
|
2023-06-30 21:53:16 +02:00
|
|
|
{/if}
|