Files
immich/web/src/lib/modals/UserEditModal.svelte

114 lines
3.3 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { AppRoute } from '$lib/constants';
2025-11-11 07:42:33 -05:00
import { handleUpdateUserAdmin } from '$lib/services/user-admin.service';
import { user as authUser } from '$lib/stores/user.store';
import { userInteraction } from '$lib/stores/user.svelte';
import { ByteUnit, convertFromBytes, convertToBytes } from '$lib/utils/byte-units';
2025-11-11 07:42:33 -05:00
import { type UserAdminResponseDto } from '@immich/sdk';
2025-10-22 15:21:16 -04:00
import {
Button,
Field,
HStack,
Input,
Link,
Modal,
ModalBody,
ModalFooter,
NumberInput,
Switch,
Text,
} from '@immich/ui';
import { mdiAccountEditOutline } from '@mdi/js';
feat(web): translations (#9854) * First test * Added translation using Weblate (French) * Translated using Weblate (German) Currently translated at 100.0% (4 of 4 strings) Translation: immich/web Translate-URL: http://familie-mach.net/projects/immich/web/de/ * Translated using Weblate (French) Currently translated at 100.0% (4 of 4 strings) Translation: immich/web Translate-URL: http://familie-mach.net/projects/immich/web/fr/ * Further testing * Further testing * Translated using Weblate (German) Currently translated at 100.0% (18 of 18 strings) Translation: immich/web Translate-URL: http://familie-mach.net/projects/immich/web/de/ * Further work * Update string file. * More strings * Automatically changed strings * Add automatically translated german file for testing purposes * Fix merge-face-selector component * Make server stats strings uppercase * Fix uppercase string * Fix some strings in jobs-panel * Fix lower and uppercase strings. Add a few additional string. Fix a few unnecessary replacements * Update german test translations * Fix typo in locales file * Change string keys * Extract more strings * Extract and replace some more strings * Update testtranslationfile * Change translation keys * Fix rebase errors * Fix one more rebase error * Remove german translation file * Co-authored-by: Daniel Dietzler <danieldietzler@users.noreply.github.com> * chore: clean up translations * chore: add new line * fix formatting * chore: fixes * fix: loading and tests --------- Co-authored-by: root <root@Blacki> Co-authored-by: admin <admin@example.com> Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Daniel Dietzler <mail@ddietzler.dev>
2024-06-04 21:53:00 +02:00
import { t } from 'svelte-i18n';
interface Props {
user: UserAdminResponseDto;
2025-11-11 07:42:33 -05:00
onClose: () => void;
}
let { user, onClose }: Props = $props();
let isAdmin = $derived(user.isAdmin);
let name = $derived(user.name);
let email = $derived(user.email);
let storageLabel = $derived(user.storageLabel || '');
const previousQuota = user.quotaSizeInBytes;
2025-10-22 15:21:16 -04:00
let quotaSize = $state(
typeof user.quotaSizeInBytes === 'number' ? convertFromBytes(user.quotaSizeInBytes, ByteUnit.GiB) : undefined,
);
const quotaSizeBytes = $derived(typeof quotaSize === 'number' ? convertToBytes(quotaSize, ByteUnit.GiB) : null);
let quotaSizeWarning = $derived(
2025-10-22 15:21:16 -04:00
previousQuota !== quotaSizeBytes &&
!!quotaSizeBytes &&
userInteraction.serverInfo &&
2025-10-22 15:21:16 -04:00
quotaSizeBytes > userInteraction.serverInfo.diskSizeRaw,
);
const onSubmit = async (event: Event) => {
event.preventDefault();
2025-11-11 07:42:33 -05:00
const success = await handleUpdateUserAdmin(user, {
email,
name,
storageLabel,
quotaSizeInBytes: typeof quotaSize === 'number' ? convertToBytes(quotaSize, ByteUnit.GiB) : null,
isAdmin,
});
if (success) {
onClose();
}
};
</script>
<Modal title={$t('edit_user')} size="small" icon={mdiAccountEditOutline} {onClose}>
<ModalBody>
<form onsubmit={onSubmit} autocomplete="off" id="edit-user-form">
2025-10-17 14:38:57 -04:00
<Field label={$t('email')} required>
<Input type="email" bind:value={email} />
</Field>
2025-10-17 14:38:57 -04:00
<Field label={$t('name')} required class="mt-4">
<Input bind:value={name} />
</Field>
2025-10-22 15:21:16 -04:00
<Field label={$t('admin.quota_size_gib')} class="mt-4">
<NumberInput bind:value={quotaSize} min="0" step="1" placeholder={$t('unlimited')} />
2025-10-17 14:38:57 -04:00
{#if quotaSizeWarning}
<Text size="small" color="danger">{$t('errors.quota_higher_than_disk_size')}</Text>
{/if}
2025-10-22 15:21:16 -04:00
</Field>
2025-10-17 14:38:57 -04:00
<Field label={$t('storage_label')} class="mt-4">
<Input bind:value={storageLabel} />
</Field>
2025-10-17 14:38:57 -04:00
<Text size="small" class="mt-2" color="muted">
{$t('admin.note_apply_storage_label_previous_assets')}
2025-12-03 13:39:32 -05:00
<Link href={AppRoute.ADMIN_QUEUES}>
2025-10-17 14:38:57 -04:00
{$t('admin.storage_template_migration_job')}
</Link>
</Text>
{#if user.id !== $authUser.id}
<Field label={$t('admin.admin_user')}>
2025-10-17 14:38:57 -04:00
<Switch bind:checked={isAdmin} class="mt-4" />
</Field>
{/if}
</form>
</ModalBody>
<ModalFooter>
<HStack fullWidth>
<Button shape="round" color="secondary" fullWidth form="edit-user-form" onclick={() => onClose()}
>{$t('cancel')}</Button
>
<Button type="submit" shape="round" fullWidth form="edit-user-form">{$t('confirm')}</Button>
</HStack>
</ModalFooter>
</Modal>