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

122 lines
3.6 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { AppRoute } from '$lib/constants';
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';
import { handleError } from '$lib/utils/handle-error';
import { updateUserAdmin, 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;
onClose: (data?: UserAdminResponseDto) => 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 handleEditUser = async () => {
try {
const newUser = await updateUserAdmin({
id: user.id,
userAdminUpdateDto: {
email,
name,
storageLabel,
2025-10-22 15:21:16 -04:00
quotaSizeInBytes: typeof quotaSize === 'number' ? convertToBytes(quotaSize, ByteUnit.GiB) : null,
isAdmin,
},
});
onClose(newUser);
} catch (error) {
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
handleError(error, $t('errors.unable_to_update_user'));
}
};
const onSubmit = async (event: Event) => {
event.preventDefault();
await handleEditUser();
};
</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')}
<Link href={AppRoute.ADMIN_JOBS}>
{$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>