2022-12-09 15:51:42 -05:00
|
|
|
<script lang="ts">
|
2024-02-13 17:07:37 -05:00
|
|
|
import { page } from '$app/stores';
|
2023-07-01 00:50:47 -04:00
|
|
|
import DeleteConfirmDialog from '$lib/components/admin-page/delete-confirm-dialoge.svelte';
|
|
|
|
|
import RestoreDialogue from '$lib/components/admin-page/restore-dialoge.svelte';
|
|
|
|
|
import Button from '$lib/components/elements/buttons/button.svelte';
|
2024-02-13 17:07:37 -05:00
|
|
|
import Icon from '$lib/components/elements/icon.svelte';
|
|
|
|
|
import CreateUserForm from '$lib/components/forms/create-user-form.svelte';
|
|
|
|
|
import EditUserForm from '$lib/components/forms/edit-user-form.svelte';
|
2023-10-13 11:02:28 -04:00
|
|
|
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
|
2024-02-13 17:07:37 -05:00
|
|
|
import FullScreenModal from '$lib/components/shared-components/full-screen-modal.svelte';
|
|
|
|
|
import { locale } from '$lib/stores/preferences.store';
|
2023-12-12 17:35:28 +01:00
|
|
|
import { user } from '$lib/stores/user.store';
|
2024-01-15 09:04:29 -06:00
|
|
|
import { asByteUnitString } from '$lib/utils/byte-units';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { getAllUsers, type UserResponseDto } from '@immich/sdk';
|
2024-02-29 19:35:37 +01:00
|
|
|
import { mdiClose, mdiDeleteRestore, mdiPencilOutline, mdiTrashCanOutline } from '@mdi/js';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import type { PageData } from './$types';
|
2023-05-21 23:18:10 -04:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
export let data: PageData;
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let allUsers: UserResponseDto[] = [];
|
|
|
|
|
let shouldShowEditUserForm = false;
|
|
|
|
|
let shouldShowCreateUserForm = false;
|
|
|
|
|
let shouldShowInfoPanel = false;
|
|
|
|
|
let shouldShowDeleteConfirmDialog = false;
|
|
|
|
|
let shouldShowRestoreDialog = false;
|
|
|
|
|
let selectedUser: UserResponseDto;
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
onMount(() => {
|
|
|
|
|
allUsers = $page.data.allUsers;
|
|
|
|
|
});
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const isDeleted = (user: UserResponseDto): boolean => {
|
2024-02-02 04:18:00 +01:00
|
|
|
return user.deletedAt != undefined;
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const deleteDateFormat: Intl.DateTimeFormatOptions = {
|
|
|
|
|
month: 'long',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const getDeleteDate = (user: UserResponseDto): string => {
|
2024-02-02 04:18:00 +01:00
|
|
|
let deletedAt = new Date(user.deletedAt ?? Date.now());
|
2023-07-01 00:50:47 -04:00
|
|
|
deletedAt.setDate(deletedAt.getDate() + 7);
|
|
|
|
|
return deletedAt.toLocaleString($locale, deleteDateFormat);
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const onUserCreated = async () => {
|
2024-02-13 17:07:37 -05:00
|
|
|
allUsers = await getAllUsers({ isAll: false });
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldShowCreateUserForm = false;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-02-27 08:37:37 -08:00
|
|
|
const editUserHandler = (user: UserResponseDto) => {
|
2023-07-01 00:50:47 -04:00
|
|
|
selectedUser = user;
|
|
|
|
|
shouldShowEditUserForm = true;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const onEditUserSuccess = async () => {
|
2024-02-13 17:07:37 -05:00
|
|
|
allUsers = await getAllUsers({ isAll: false });
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldShowEditUserForm = false;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const onEditPasswordSuccess = async () => {
|
2024-02-13 17:07:37 -05:00
|
|
|
allUsers = await getAllUsers({ isAll: false });
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldShowEditUserForm = false;
|
|
|
|
|
shouldShowInfoPanel = true;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-02-27 08:37:37 -08:00
|
|
|
const deleteUserHandler = (user: UserResponseDto) => {
|
2023-07-01 00:50:47 -04:00
|
|
|
selectedUser = user;
|
|
|
|
|
shouldShowDeleteConfirmDialog = true;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const onUserDeleteSuccess = async () => {
|
2024-02-13 17:07:37 -05:00
|
|
|
allUsers = await getAllUsers({ isAll: false });
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldShowDeleteConfirmDialog = false;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const onUserDeleteFail = async () => {
|
2024-02-13 17:07:37 -05:00
|
|
|
allUsers = await getAllUsers({ isAll: false });
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldShowDeleteConfirmDialog = false;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-02-27 08:37:37 -08:00
|
|
|
const restoreUserHandler = (user: UserResponseDto) => {
|
2023-07-01 00:50:47 -04:00
|
|
|
selectedUser = user;
|
|
|
|
|
shouldShowRestoreDialog = true;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const onUserRestoreSuccess = async () => {
|
2024-02-13 17:07:37 -05:00
|
|
|
allUsers = await getAllUsers({ isAll: false });
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldShowRestoreDialog = false;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const onUserRestoreFail = async () => {
|
|
|
|
|
// show fail dialog
|
2024-02-13 17:07:37 -05:00
|
|
|
allUsers = await getAllUsers({ isAll: false });
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldShowRestoreDialog = false;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
</script>
|
|
|
|
|
|
2023-12-12 17:35:28 +01:00
|
|
|
<UserPageLayout title={data.meta.title} admin>
|
2023-10-13 11:02:28 -04:00
|
|
|
<section id="setting-content" class="flex place-content-center sm:mx-4">
|
2023-12-14 17:55:15 +01:00
|
|
|
<section class="w-full pb-28 lg:w-[850px]">
|
2023-10-13 11:02:28 -04:00
|
|
|
{#if shouldShowCreateUserForm}
|
2024-03-07 04:18:53 +01:00
|
|
|
<FullScreenModal onClose={() => (shouldShowCreateUserForm = false)}>
|
2023-12-15 03:54:21 +01:00
|
|
|
<CreateUserForm on:submit={onUserCreated} on:cancel={() => (shouldShowCreateUserForm = false)} />
|
2023-10-13 11:02:28 -04:00
|
|
|
</FullScreenModal>
|
|
|
|
|
{/if}
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-10-13 11:02:28 -04:00
|
|
|
{#if shouldShowEditUserForm}
|
2024-03-07 04:18:53 +01:00
|
|
|
<FullScreenModal onClose={() => (shouldShowEditUserForm = false)}>
|
2023-10-13 11:02:28 -04:00
|
|
|
<EditUserForm
|
|
|
|
|
user={selectedUser}
|
2023-12-12 17:35:28 +01:00
|
|
|
canResetPassword={selectedUser?.id !== $user.id}
|
2023-12-14 17:55:15 +01:00
|
|
|
on:editSuccess={onEditUserSuccess}
|
2023-12-15 03:54:21 +01:00
|
|
|
on:resetPasswordSuccess={onEditPasswordSuccess}
|
2023-12-14 17:55:15 +01:00
|
|
|
on:close={() => (shouldShowEditUserForm = false)}
|
2023-10-13 11:02:28 -04:00
|
|
|
/>
|
|
|
|
|
</FullScreenModal>
|
|
|
|
|
{/if}
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-10-13 11:02:28 -04:00
|
|
|
{#if shouldShowDeleteConfirmDialog}
|
|
|
|
|
<DeleteConfirmDialog
|
|
|
|
|
user={selectedUser}
|
2024-01-19 22:22:00 +01:00
|
|
|
on:success={onUserDeleteSuccess}
|
2023-12-15 03:54:21 +01:00
|
|
|
on:fail={onUserDeleteFail}
|
2023-10-13 11:02:28 -04:00
|
|
|
on:cancel={() => (shouldShowDeleteConfirmDialog = false)}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-10-13 11:02:28 -04:00
|
|
|
{#if shouldShowRestoreDialog}
|
|
|
|
|
<RestoreDialogue
|
|
|
|
|
user={selectedUser}
|
2023-12-15 03:54:21 +01:00
|
|
|
on:success={onUserRestoreSuccess}
|
|
|
|
|
on:fail={onUserRestoreFail}
|
2023-10-13 11:02:28 -04:00
|
|
|
on:cancel={() => (shouldShowRestoreDialog = false)}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-10-13 11:02:28 -04:00
|
|
|
{#if shouldShowInfoPanel}
|
2024-03-07 04:18:53 +01:00
|
|
|
<FullScreenModal onClose={() => (shouldShowInfoPanel = false)}>
|
2024-03-08 14:05:15 -05:00
|
|
|
<div
|
|
|
|
|
class="w-[500px] max-w-[95vw] rounded-3xl bg-immich-bg p-8 text-immich-fg shadow-sm dark:bg-immich-dark-gray dark:text-immich-dark-fg"
|
|
|
|
|
>
|
|
|
|
|
<h1 class="mb-4 text-2xl font-medium text-immich-primary dark:text-immich-dark-primary">
|
|
|
|
|
Password reset success
|
|
|
|
|
</h1>
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-10-13 11:02:28 -04:00
|
|
|
<p>
|
|
|
|
|
The user's password has been reset to the default <code
|
2024-03-08 14:05:15 -05:00
|
|
|
class="rounded-md bg-gray-200 px-2 py-1 font-bold text-immich-primary dark:text-immich-dark-primary dark:bg-gray-700"
|
|
|
|
|
>password</code
|
2023-10-13 11:02:28 -04:00
|
|
|
>
|
|
|
|
|
<br />
|
2024-03-08 14:05:15 -05:00
|
|
|
<br />
|
2023-10-13 11:02:28 -04:00
|
|
|
Please inform the user, and they will need to change the password at the next log-on.
|
|
|
|
|
</p>
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-10-13 11:02:28 -04:00
|
|
|
<div class="mt-6 flex w-full">
|
|
|
|
|
<Button fullwidth on:click={() => (shouldShowInfoPanel = false)}>Done</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</FullScreenModal>
|
|
|
|
|
{/if}
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-12-14 17:55:15 +01:00
|
|
|
<table class="my-5 w-full text-left">
|
2023-10-13 11:02:28 -04:00
|
|
|
<thead
|
|
|
|
|
class="mb-4 flex h-12 w-full rounded-md border bg-gray-50 text-immich-primary dark:border-immich-dark-gray dark:bg-immich-dark-gray dark:text-immich-dark-primary"
|
|
|
|
|
>
|
|
|
|
|
<tr class="flex w-full place-items-center">
|
2023-12-14 17:55:15 +01:00
|
|
|
<th class="w-8/12 sm:w-5/12 lg:w-6/12 xl:w-4/12 2xl:w-5/12 text-center text-sm font-medium">Email</th>
|
|
|
|
|
<th class="hidden sm:block w-3/12 text-center text-sm font-medium">Name</th>
|
2024-01-15 09:04:29 -06:00
|
|
|
<th class="hidden xl:block w-3/12 2xl:w-2/12 text-center text-sm font-medium">Has quota</th>
|
2023-12-14 17:55:15 +01:00
|
|
|
<th class="w-4/12 lg:w-3/12 xl:w-2/12 text-center text-sm font-medium">Action</th>
|
2023-07-01 00:50:47 -04:00
|
|
|
</tr>
|
2023-10-13 11:02:28 -04:00
|
|
|
</thead>
|
|
|
|
|
<tbody class="block max-h-[320px] w-full overflow-y-auto rounded-md border dark:border-immich-dark-gray">
|
|
|
|
|
{#if allUsers}
|
2024-02-02 04:18:00 +01:00
|
|
|
{#each allUsers as immichUser, index}
|
2023-10-13 11:02:28 -04:00
|
|
|
<tr
|
2023-12-14 17:55:15 +01:00
|
|
|
class="flex h-[80px] overflow-hidden w-full place-items-center text-center dark:text-immich-dark-fg {isDeleted(
|
|
|
|
|
immichUser,
|
|
|
|
|
)
|
|
|
|
|
? 'bg-red-300 dark:bg-red-900'
|
2024-02-02 04:18:00 +01:00
|
|
|
: index % 2 == 0
|
2023-12-14 17:55:15 +01:00
|
|
|
? 'bg-immich-gray dark:bg-immich-dark-gray/75'
|
|
|
|
|
: 'bg-immich-bg dark:bg-immich-dark-gray/50'}"
|
2023-10-13 11:02:28 -04:00
|
|
|
>
|
2023-12-14 17:55:15 +01:00
|
|
|
<td class="w-8/12 sm:w-5/12 lg:w-6/12 xl:w-4/12 2xl:w-5/12 text-ellipsis break-all px-2 text-sm"
|
|
|
|
|
>{immichUser.email}</td
|
|
|
|
|
>
|
|
|
|
|
<td class="hidden sm:block w-3/12 text-ellipsis break-all px-2 text-sm">{immichUser.name}</td>
|
2024-01-15 09:04:29 -06:00
|
|
|
<td class="hidden xl:block w-3/12 2xl:w-2/12 text-ellipsis break-all px-2 text-sm">
|
|
|
|
|
<div class="container mx-auto flex flex-wrap justify-center">
|
|
|
|
|
{#if immichUser.quotaSizeInBytes && immichUser.quotaSizeInBytes > 0}
|
|
|
|
|
{asByteUnitString(immichUser.quotaSizeInBytes, $locale)}
|
|
|
|
|
{:else}
|
|
|
|
|
<Icon path={mdiClose} size="16" />
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
2024-01-20 00:49:14 +01:00
|
|
|
<td class="w-4/12 lg:w-3/12 xl:w-2/12 text-ellipsis break-all text-sm">
|
2023-12-12 17:35:28 +01:00
|
|
|
{#if !isDeleted(immichUser)}
|
2023-10-13 11:02:28 -04:00
|
|
|
<button
|
2023-12-12 17:35:28 +01:00
|
|
|
on:click={() => editUserHandler(immichUser)}
|
2023-12-14 17:55:15 +01:00
|
|
|
class="rounded-full bg-immich-primary p-2 sm:p-3 text-gray-100 transition-all duration-150 hover:bg-immich-primary/75 dark:bg-immich-dark-primary dark:text-gray-700 max-sm:mb-1"
|
2023-10-13 11:02:28 -04:00
|
|
|
>
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={mdiPencilOutline} size="16" />
|
2023-10-13 11:02:28 -04:00
|
|
|
</button>
|
2023-12-12 17:35:28 +01:00
|
|
|
{#if immichUser.id !== $user.id}
|
2023-10-13 11:02:28 -04:00
|
|
|
<button
|
2023-12-12 17:35:28 +01:00
|
|
|
on:click={() => deleteUserHandler(immichUser)}
|
2023-12-14 17:55:15 +01:00
|
|
|
class="rounded-full bg-immich-primary p-2 sm:p-3 text-gray-100 transition-all duration-150 hover:bg-immich-primary/75 dark:bg-immich-dark-primary dark:text-gray-700"
|
2023-10-13 11:02:28 -04:00
|
|
|
>
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={mdiTrashCanOutline} size="16" />
|
2023-10-13 11:02:28 -04:00
|
|
|
</button>
|
|
|
|
|
{/if}
|
|
|
|
|
{/if}
|
2023-12-12 17:35:28 +01:00
|
|
|
{#if isDeleted(immichUser)}
|
2023-10-13 11:02:28 -04:00
|
|
|
<button
|
2023-12-12 17:35:28 +01:00
|
|
|
on:click={() => restoreUserHandler(immichUser)}
|
2023-10-13 11:02:28 -04:00
|
|
|
class="rounded-full bg-immich-primary p-3 text-gray-100 transition-all duration-150 hover:bg-immich-primary/75 dark:bg-immich-dark-primary dark:text-gray-700"
|
2023-12-14 17:55:15 +01:00
|
|
|
title="scheduled removal on {getDeleteDate(immichUser)}"
|
2023-10-13 11:02:28 -04:00
|
|
|
>
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={mdiDeleteRestore} size="16" />
|
2023-10-13 11:02:28 -04:00
|
|
|
</button>
|
|
|
|
|
{/if}
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
{/each}
|
|
|
|
|
{/if}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
2023-04-17 18:18:49 +02:00
|
|
|
|
2023-10-13 11:02:28 -04:00
|
|
|
<Button size="sm" on:click={() => (shouldShowCreateUserForm = true)}>Create user</Button>
|
|
|
|
|
</section>
|
|
|
|
|
</section>
|
|
|
|
|
</UserPageLayout>
|