refactor: user settings (#25166)

This commit is contained in:
Jason Rasmussen 2026-01-09 17:11:07 -05:00 committed by GitHub
parent 1e4af9731d
commit 76241a7b2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 120 additions and 167 deletions

View file

@ -1,10 +1,6 @@
<script lang="ts"> <script lang="ts">
import SettingInputField from '$lib/components/shared-components/settings/setting-input-field.svelte'; import { handleChangePassword } from '$lib/services/user.service';
import SettingSwitch from '$lib/components/shared-components/settings/setting-switch.svelte'; import { Button, Field, PasswordInput, Switch } from '@immich/ui';
import { SettingInputFieldType } from '$lib/constants';
import { handleError } from '$lib/utils/handle-error';
import { changePassword } from '@immich/sdk';
import { Button, toastManager } from '@immich/ui';
import { t } from 'svelte-i18n'; import { t } from 'svelte-i18n';
import { fade } from 'svelte/transition'; import { fade } from 'svelte/transition';
@ -13,67 +9,43 @@
let confirmPassword = $state(''); let confirmPassword = $state('');
let invalidateSessions = $state(false); let invalidateSessions = $state(false);
const handleChangePassword = async () => { const onsubmit = async (event: Event) => {
try { event.preventDefault();
await changePassword({ changePasswordDto: { password, newPassword, invalidateSessions } }); const success = await handleChangePassword({ password, newPassword, invalidateSessions });
if (success) {
toastManager.success($t('updated_password'));
password = ''; password = '';
newPassword = ''; newPassword = '';
confirmPassword = ''; confirmPassword = '';
} catch (error) {
console.error('Error [user-profile] [changePassword]', error);
handleError(error, $t('errors.unable_to_change_password'));
} }
}; };
const onsubmit = (event: Event) => {
event.preventDefault();
};
</script> </script>
<section class="my-4"> <section class="my-4">
<div in:fade={{ duration: 500 }}> <div in:fade={{ duration: 500 }}>
<form autocomplete="off" {onsubmit}> <form autocomplete="off" {onsubmit}>
<div class="ms-4 mt-4 flex flex-col gap-4"> <div class="ms-4 mt-4 flex flex-col gap-4">
<SettingInputField <Field label={$t('password')} required>
inputType={SettingInputFieldType.PASSWORD} <PasswordInput bind:value={password} autocomplete="current-password" />
label={$t('password')} </Field>
bind:value={password}
required={true}
passwordAutocomplete="current-password"
/>
<SettingInputField <Field label={$t('new_password')} required>
inputType={SettingInputFieldType.PASSWORD} <PasswordInput bind:value={newPassword} autocomplete="new-password" />
label={$t('new_password')} </Field>
bind:value={newPassword}
required={true}
passwordAutocomplete="new-password"
/>
<SettingInputField <Field label={$t('confirm_password')} required>
inputType={SettingInputFieldType.PASSWORD} <PasswordInput bind:value={confirmPassword} autocomplete="new-password" />
label={$t('confirm_password')} </Field>
bind:value={confirmPassword}
required={true}
passwordAutocomplete="new-password"
/>
<SettingSwitch <Field label={$t('log_out_all_devices')} description={$t('change_password_form_log_out_description')} required>
title={$t('log_out_all_devices')} <Switch bind:checked={invalidateSessions} />
subtitle={$t('change_password_form_log_out_description')} </Field>
bind:checked={invalidateSessions}
/>
<div class="flex justify-end"> <div class="flex justify-end">
<Button <Button
shape="round" shape="round"
type="submit" type="submit"
size="small" size="small"
disabled={!(password && newPassword && newPassword === confirmPassword)} disabled={!(password && newPassword && newPassword === confirmPassword)}>{$t('save')}</Button
onclick={() => handleChangePassword()}>{$t('save')}</Button
> >
</div> </div>
</div> </div>

View file

@ -1,13 +1,10 @@
<script lang="ts"> <script lang="ts">
import SettingAccordion from '$lib/components/shared-components/settings/setting-accordion.svelte'; import SettingAccordion from '$lib/components/shared-components/settings/setting-accordion.svelte';
import SettingInputField from '$lib/components/shared-components/settings/setting-input-field.svelte';
import SettingSelect from '$lib/components/shared-components/settings/setting-select.svelte'; import SettingSelect from '$lib/components/shared-components/settings/setting-select.svelte';
import SettingSwitch from '$lib/components/shared-components/settings/setting-switch.svelte';
import { SettingInputFieldType } from '$lib/constants';
import { preferences } from '$lib/stores/user.store'; import { preferences } from '$lib/stores/user.store';
import { handleError } from '$lib/utils/handle-error'; import { handleError } from '$lib/utils/handle-error';
import { AssetOrder, updateMyPreferences } from '@immich/sdk'; import { AssetOrder, updateMyPreferences } from '@immich/sdk';
import { Button, toastManager } from '@immich/ui'; import { Button, Field, NumberInput, Switch, toastManager } from '@immich/ui';
import { t } from 'svelte-i18n'; import { t } from 'svelte-i18n';
import { fade } from 'svelte/transition'; import { fade } from 'svelte/transition';
@ -73,7 +70,7 @@
<form autocomplete="off" {onsubmit}> <form autocomplete="off" {onsubmit}>
<div class="ms-4 mt-4 flex flex-col"> <div class="ms-4 mt-4 flex flex-col">
<SettingAccordion key="albums" title={$t('albums')} subtitle={$t('albums_feature_description')}> <SettingAccordion key="albums" title={$t('albums')} subtitle={$t('albums_feature_description')}>
<div class="ms-4 mt-6"> <div class="ms-4 mt-6 flex flex-col gap-4">
<SettingSelect <SettingSelect
label={$t('albums_default_sort_order')} label={$t('albums_default_sort_order')}
desc={$t('albums_default_sort_order_description')} desc={$t('albums_default_sort_order_description')}
@ -87,94 +84,86 @@
</SettingAccordion> </SettingAccordion>
<SettingAccordion key="folders" title={$t('folders')} subtitle={$t('folders_feature_description')}> <SettingAccordion key="folders" title={$t('folders')} subtitle={$t('folders_feature_description')}>
<div class="ms-4 mt-6"> <div class="ms-4 mt-6 flex flex-col gap-4">
<SettingSwitch title={$t('enable')} bind:checked={foldersEnabled} /> <Field label={$t('enable')}>
</div> <Switch bind:checked={foldersEnabled} />
</Field>
{#if foldersEnabled} {#if foldersEnabled}
<div class="ms-4 mt-6"> <Field label={$t('sidebar')} description={$t('sidebar_display_description')}>
<SettingSwitch <Switch bind:checked={foldersSidebar} />
title={$t('sidebar')} </Field>
subtitle={$t('sidebar_display_description')} {/if}
bind:checked={foldersSidebar} </div>
/>
</div>
{/if}
</SettingAccordion> </SettingAccordion>
<SettingAccordion key="memories" title={$t('time_based_memories')} subtitle={$t('photos_from_previous_years')}> <SettingAccordion key="memories" title={$t('time_based_memories')} subtitle={$t('photos_from_previous_years')}>
<div class="ms-4 mt-6"> <div class="ms-4 mt-6 flex flex-col gap-4">
<SettingSwitch title={$t('enable')} bind:checked={memoriesEnabled} /> <Field label={$t('enable')}>
</div> <Switch bind:checked={memoriesEnabled} />
<div class="ms-4 mt-6"> </Field>
<SettingInputField
inputType={SettingInputFieldType.NUMBER} <Field label={$t('duration')} description={$t('time_based_memories_duration')}>
label={$t('duration')} <NumberInput bind:value={memoriesDuration} />
description={$t('time_based_memories_duration')} </Field>
bind:value={memoriesDuration}
/>
</div> </div>
</SettingAccordion> </SettingAccordion>
<SettingAccordion key="people" title={$t('people')} subtitle={$t('people_feature_description')}> <SettingAccordion key="people" title={$t('people')} subtitle={$t('people_feature_description')}>
<div class="ms-4 mt-6"> <div class="ms-4 mt-6 flex flex-col gap-4">
<SettingSwitch title={$t('enable')} bind:checked={peopleEnabled} /> <Field label={$t('enable')}>
</div> <Switch bind:checked={peopleEnabled} />
</Field>
{#if peopleEnabled} {#if peopleEnabled}
<div class="ms-4 mt-6"> <Field label={$t('sidebar')} description={$t('sidebar_display_description')}>
<SettingSwitch <Switch bind:checked={peopleSidebar} />
title={$t('sidebar')} </Field>
subtitle={$t('sidebar_display_description')} {/if}
bind:checked={peopleSidebar} </div>
/>
</div>
{/if}
</SettingAccordion> </SettingAccordion>
<SettingAccordion key="rating" title={$t('rating')} subtitle={$t('rating_description')}> <SettingAccordion key="rating" title={$t('rating')} subtitle={$t('rating_description')}>
<div class="ms-4 mt-6"> <div class="ms-4 mt-6 flex flex-col gap-4">
<SettingSwitch title={$t('enable')} bind:checked={ratingsEnabled} /> <Field label={$t('enable')}>
<Switch bind:checked={ratingsEnabled} />
</Field>
</div> </div>
</SettingAccordion> </SettingAccordion>
<SettingAccordion key="shared-links" title={$t('shared_links')} subtitle={$t('shared_links_description')}> <SettingAccordion key="shared-links" title={$t('shared_links')} subtitle={$t('shared_links_description')}>
<div class="ms-4 mt-6"> <div class="ms-4 mt-6 flex flex-col gap-4">
<SettingSwitch title={$t('enable')} bind:checked={sharedLinksEnabled} /> <Field label={$t('enable')}>
<Switch bind:checked={sharedLinksEnabled} />
</Field>
{#if sharedLinksEnabled}
<Field label={$t('sidebar')} description={$t('sidebar_display_description')}>
<Switch bind:checked={sharedLinkSidebar} />
</Field>
{/if}
</div> </div>
{#if sharedLinksEnabled}
<div class="ms-4 mt-6">
<SettingSwitch
title={$t('sidebar')}
subtitle={$t('sidebar_display_description')}
bind:checked={sharedLinkSidebar}
/>
</div>
{/if}
</SettingAccordion> </SettingAccordion>
<SettingAccordion key="tags" title={$t('tags')} subtitle={$t('tag_feature_description')}> <SettingAccordion key="tags" title={$t('tags')} subtitle={$t('tag_feature_description')}>
<div class="ms-4 mt-6"> <div class="ms-4 mt-6 flex flex-col gap-4">
<SettingSwitch title={$t('enable')} bind:checked={tagsEnabled} /> <Field label={$t('enable')}>
<Switch bind:checked={tagsEnabled} />
</Field>
{#if tagsEnabled}
<Field label={$t('sidebar')} description={$t('sidebar_display_description')}>
<Switch bind:checked={tagsSidebar} />
</Field>
{/if}
</div> </div>
{#if tagsEnabled}
<div class="ms-4 mt-6">
<SettingSwitch
title={$t('sidebar')}
subtitle={$t('sidebar_display_description')}
bind:checked={tagsSidebar}
/>
</div>
{/if}
</SettingAccordion> </SettingAccordion>
<SettingAccordion key="cast" title={$t('cast')} subtitle={$t('cast_description')}> <SettingAccordion key="cast" title={$t('cast')} subtitle={$t('cast_description')}>
<div class="ms-4 mt-6"> <div class="ms-4 mt-6 flex flex-col gap-4">
<SettingSwitch <Field label={$t('gcast_enabled')} description={$t('gcast_enabled_description')}>
title={$t('gcast_enabled')} <Switch bind:checked={gCastEnabled} />
subtitle={$t('gcast_enabled_description')} </Field>
bind:checked={gCastEnabled}
/>
</div> </div>
</SettingAccordion> </SettingAccordion>

View file

@ -1,9 +1,8 @@
<script lang="ts"> <script lang="ts">
import SettingSwitch from '$lib/components/shared-components/settings/setting-switch.svelte';
import { preferences } from '$lib/stores/user.store'; import { preferences } from '$lib/stores/user.store';
import { handleError } from '$lib/utils/handle-error'; import { handleError } from '$lib/utils/handle-error';
import { updateMyPreferences } from '@immich/sdk'; import { updateMyPreferences } from '@immich/sdk';
import { Button, toastManager } from '@immich/ui'; import { Button, Field, Switch, toastManager } from '@immich/ui';
import { t } from 'svelte-i18n'; import { t } from 'svelte-i18n';
import { fade } from 'svelte/transition'; import { fade } from 'svelte/transition';
@ -36,38 +35,29 @@
const onsubmit = (event: Event) => { const onsubmit = (event: Event) => {
event.preventDefault(); event.preventDefault();
}; };
const disabled = $derived(!emailNotificationsEnabled);
</script> </script>
<section class="my-4"> <section class="my-4">
<div in:fade={{ duration: 500 }}> <div in:fade={{ duration: 500 }}>
<form autocomplete="off" {onsubmit}> <form autocomplete="off" {onsubmit}>
<div class="ms-4 mt-4 flex flex-col gap-4"> <div class="ms-4 mt-4 flex flex-col gap-4">
<div class="ms-4"> <Field label={$t('enable')} description={$t('notification_toggle_setting_description')}>
<SettingSwitch <Switch bind:checked={emailNotificationsEnabled} />
title={$t('notification_toggle_setting_description')} </Field>
bind:checked={emailNotificationsEnabled}
/>
</div>
<div class="ms-4">
<SettingSwitch
title={$t('album_added')}
subtitle={$t('album_added_notification_setting_description')}
bind:checked={albumInviteNotificationEnabled}
disabled={!emailNotificationsEnabled}
/>
</div>
<div class="ms-4">
<SettingSwitch
title={$t('album_updated')}
subtitle={$t('album_updated_setting_description')}
bind:checked={albumUpdateNotificationEnabled}
disabled={!emailNotificationsEnabled}
/>
</div>
<div class="flex justify-end"> <Field label={$t('album_added')} description={$t('album_added_notification_setting_description')} {disabled}>
<Button shape="round" type="submit" size="small" onclick={() => handleSave()}>{$t('save')}</Button> <Switch bind:checked={albumInviteNotificationEnabled} />
</div> </Field>
<Field label={$t('album_updated')} description={$t('album_updated_setting_description')} {disabled}>
<Switch bind:checked={albumUpdateNotificationEnabled} />
</Field>
</div>
<div class="flex justify-end mt-4">
<Button shape="round" type="submit" size="small" onclick={() => handleSave()}>{$t('save')}</Button>
</div> </div>
</form> </form>
</div> </div>

View file

@ -1,10 +1,8 @@
<script lang="ts"> <script lang="ts">
import SettingInputField from '$lib/components/shared-components/settings/setting-input-field.svelte';
import { SettingInputFieldType } from '$lib/constants';
import { user } from '$lib/stores/user.store'; import { user } from '$lib/stores/user.store';
import { handleError } from '$lib/utils/handle-error'; import { handleError } from '$lib/utils/handle-error';
import { updateMyUser } from '@immich/sdk'; import { updateMyUser } from '@immich/sdk';
import { Button, toastManager } from '@immich/ui'; import { Button, Field, Input, toastManager } from '@immich/ui';
import { cloneDeep } from 'lodash-es'; import { cloneDeep } from 'lodash-es';
import { t } from 'svelte-i18n'; import { t } from 'svelte-i18n';
import { createBubbler, preventDefault } from 'svelte/legacy'; import { createBubbler, preventDefault } from 'svelte/legacy';
@ -36,29 +34,21 @@
<div in:fade={{ duration: 500 }}> <div in:fade={{ duration: 500 }}>
<form autocomplete="off" onsubmit={preventDefault(bubble('submit'))}> <form autocomplete="off" onsubmit={preventDefault(bubble('submit'))}>
<div class="ms-4 mt-4 flex flex-col gap-4"> <div class="ms-4 mt-4 flex flex-col gap-4">
<SettingInputField <Field label={$t('user_id')} disabled>
inputType={SettingInputFieldType.TEXT} <Input bind:value={editedUser.id} />
label={$t('user_id')} </Field>
bind:value={editedUser.id}
disabled={true}
/>
<SettingInputField inputType={SettingInputFieldType.EMAIL} label={$t('email')} bind:value={editedUser.email} /> <Field label={$t('email')} required>
<Input type="email" bind:value={editedUser.email} />
</Field>
<SettingInputField <Field label={$t('name')} required>
inputType={SettingInputFieldType.TEXT} <Input bind:value={editedUser.name} />
label={$t('name')} </Field>
bind:value={editedUser.name}
required={true}
/>
<SettingInputField <Field label={$t('storage_label')} disabled>
inputType={SettingInputFieldType.TEXT} <Input value={editedUser.storageLabel || ''} />
label={$t('storage_label')} </Field>
disabled={true}
value={editedUser.storageLabel || ''}
required={false}
/>
<div class="flex justify-end"> <div class="flex justify-end">
<Button shape="round" type="submit" size="small" onclick={() => handleSaveProfile()}>{$t('save')}</Button> <Button shape="round" type="submit" size="small" onclick={() => handleSaveProfile()}>{$t('save')}</Button>

View file

@ -1,7 +1,7 @@
import { eventManager } from '$lib/managers/event-manager.svelte'; import { eventManager } from '$lib/managers/event-manager.svelte';
import { handleError } from '$lib/utils/handle-error'; import { handleError } from '$lib/utils/handle-error';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { resetPinCode, type PinCodeResetDto } from '@immich/sdk'; import { changePassword, resetPinCode, type ChangePasswordDto, type PinCodeResetDto } from '@immich/sdk';
import { toastManager } from '@immich/ui'; import { toastManager } from '@immich/ui';
export const handleResetPinCode = async (dto: PinCodeResetDto) => { export const handleResetPinCode = async (dto: PinCodeResetDto) => {
@ -16,3 +16,15 @@ export const handleResetPinCode = async (dto: PinCodeResetDto) => {
handleError(error, $t('errors.failed_to_reset_pin_code')); handleError(error, $t('errors.failed_to_reset_pin_code'));
} }
}; };
export const handleChangePassword = async (dto: ChangePasswordDto) => {
const $t = await getFormatter();
try {
await changePassword({ changePasswordDto: dto });
toastManager.success($t('updated_password'));
return true;
} catch (error) {
handleError(error, $t('errors.unable_to_change_password'));
}
};