2022-11-07 16:53:47 -05:00
|
|
|
<script lang="ts">
|
2024-06-21 22:08:36 +02:00
|
|
|
import FormatMessage from '$lib/components/i18n/format-message.svelte';
|
2024-05-28 09:10:43 +07:00
|
|
|
import ConfirmDialog from '$lib/components/shared-components/dialog/confirm-dialog.svelte';
|
2024-03-08 17:49:39 -05:00
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
2024-05-26 18:15:52 -04:00
|
|
|
import { restoreUserAdmin, type UserResponseDto } from '@immich/sdk';
|
2024-06-22 18:08:56 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2022-11-07 16:53:47 -05:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
user: UserResponseDto;
|
|
|
|
|
onSuccess: () => void;
|
|
|
|
|
onFail: () => void;
|
|
|
|
|
onCancel: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let { user, onSuccess, onFail, onCancel }: Props = $props();
|
2022-11-07 16:53:47 -05:00
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
const handleRestoreUser = async () => {
|
2024-03-08 17:49:39 -05:00
|
|
|
try {
|
2024-05-26 18:15:52 -04:00
|
|
|
const { deletedAt } = await restoreUserAdmin({ id: user.id });
|
2024-03-08 17:49:39 -05:00
|
|
|
if (deletedAt == undefined) {
|
2024-09-19 18:20:09 -04:00
|
|
|
onSuccess();
|
2024-03-08 17:49:39 -05:00
|
|
|
} else {
|
2024-09-19 18:20:09 -04:00
|
|
|
onFail();
|
2024-03-08 17:49:39 -05:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2024-06-04 21:53:00 +02:00
|
|
|
handleError(error, $t('errors.unable_to_restore_user'));
|
2024-09-19 18:20:09 -04:00
|
|
|
onFail();
|
2023-11-28 15:16:27 -05:00
|
|
|
}
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
2022-11-07 16:53:47 -05:00
|
|
|
</script>
|
|
|
|
|
|
2024-05-28 09:10:43 +07:00
|
|
|
<ConfirmDialog
|
2024-06-04 21:53:00 +02:00
|
|
|
title={$t('restore_user')}
|
|
|
|
|
confirmText={$t('continue')}
|
2025-03-14 09:37:56 -04:00
|
|
|
confirmColor="success"
|
2025-05-02 19:34:53 +02:00
|
|
|
onClose={(confirmed) => (confirmed ? handleRestoreUser() : onCancel())}
|
2024-02-13 17:07:37 -05:00
|
|
|
>
|
2024-11-14 08:43:25 -06:00
|
|
|
{#snippet promptSnippet()}
|
2024-06-21 22:08:36 +02:00
|
|
|
<p>
|
2024-11-14 08:43:25 -06:00
|
|
|
<FormatMessage key="admin.user_restore_description" values={{ user: user.name }}>
|
|
|
|
|
{#snippet children({ message })}
|
|
|
|
|
<b>{message}</b>
|
|
|
|
|
{/snippet}
|
2024-06-21 22:08:36 +02:00
|
|
|
</FormatMessage>
|
|
|
|
|
</p>
|
2024-11-14 08:43:25 -06:00
|
|
|
{/snippet}
|
2024-05-28 09:10:43 +07:00
|
|
|
</ConfirmDialog>
|