design: redesign credentials page
This commit is contained in:
1 parent
37b28cf8ab
commit
3ada11ea58
15 files changed
+558
-289
No files matched your search
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { profile, profileData, setUserID } from '$lib/auth.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { ImageInput, Material, removeToast, toast } from 'mono-svelte'
|
||||
@@ -53,110 +52,9 @@
|
||||
loading = false
|
||||
}
|
||||
|
||||
let deletion = {
|
||||
modal: false,
|
||||
password: '',
|
||||
deleteContent: false,
|
||||
}
|
||||
|
||||
async function deleteAccount(level: number) {
|
||||
if (!$profile?.jwt) return
|
||||
switch (level) {
|
||||
case 0: {
|
||||
toast({
|
||||
content: $t('toast.confirmDelete1'),
|
||||
action: () => deleteAccount(1),
|
||||
})
|
||||
return
|
||||
}
|
||||
case 1: {
|
||||
toast({
|
||||
content: $t('toast.confirmDelete2'),
|
||||
action: () => deleteAccount(2),
|
||||
})
|
||||
return
|
||||
}
|
||||
case 2: {
|
||||
toast({
|
||||
content: $t('toast.confirmDelete3'),
|
||||
action: () => deleteAccount(3),
|
||||
})
|
||||
return
|
||||
}
|
||||
case 3: {
|
||||
deletion.modal = true
|
||||
deletion.password = ''
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (!(deletion.password || null)) {
|
||||
toast({
|
||||
content: $t('toast.needPassword'),
|
||||
type: 'warning',
|
||||
})
|
||||
}
|
||||
|
||||
const id = toast({
|
||||
content: $t('toast.deleting'),
|
||||
loading: true,
|
||||
})
|
||||
|
||||
try {
|
||||
await getClient().deleteAccount({
|
||||
password: deletion.password,
|
||||
|
||||
delete_content: deletion.deleteContent,
|
||||
})
|
||||
|
||||
profileData.update((pd) => {
|
||||
pd.profiles.splice(
|
||||
pd.profiles.findIndex((p) => pd.profile == p.id),
|
||||
1
|
||||
)
|
||||
|
||||
return pd
|
||||
})
|
||||
|
||||
setUserID(-1)
|
||||
toast({
|
||||
content: $t('toast.deleted'),
|
||||
})
|
||||
goto('/')
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: 'error',
|
||||
})
|
||||
} finally {
|
||||
removeToast(id)
|
||||
}
|
||||
}
|
||||
|
||||
let loading = false
|
||||
</script>
|
||||
|
||||
{#if deletion.modal}
|
||||
<Modal
|
||||
bind:open={deletion.modal}
|
||||
action="Submit"
|
||||
on:action={() => deleteAccount(4)}
|
||||
>
|
||||
<span slot="title">{$t('form.profile.deleteAccount.label')}</span>
|
||||
<TextInput
|
||||
label={$t('form.password')}
|
||||
type="password"
|
||||
bind:value={deletion.password}
|
||||
/>
|
||||
<Checkbox bind:checked={deletion.deleteContent}>
|
||||
{$t('form.profile.deleteAccount.deleteContent')}
|
||||
<span slot="description">
|
||||
{$t('form.profile.deleteAccount.warning')}
|
||||
</span>
|
||||
</Checkbox>
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
<form class="flex flex-col gap-4 h-full" on:submit|preventDefault={save}>
|
||||
<Header pageHeader>{$t('routes.profile.settings')}</Header>
|
||||
{#if data.my_user?.local_user_view?.local_user && formData}
|
||||
@@ -206,12 +104,4 @@
|
||||
{$t('common.save')}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
on:click={() => deleteAccount(0)}
|
||||
color="danger"
|
||||
size="lg"
|
||||
class="ml-auto"
|
||||
>
|
||||
{$t('form.profile.deleteAccount.label')}
|
||||
</Button>
|
||||
</form>
|
||||
Reference in new issue
Block a user