Files
archtika/web-app/src/routes/(authenticated)/account/+page.svelte

93 lines
2.0 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { enhance } from "$app/forms";
2024-08-02 15:33:18 +02:00
import Modal from "$lib/components/Modal.svelte";
import SuccessOrError from "$lib/components/SuccessOrError.svelte";
import LoadingSpinner from "$lib/components/LoadingSpinner.svelte";
import type { ActionData, PageServerData } from "./$types";
2024-08-20 19:17:05 +02:00
const { data, form }: { data: PageServerData; form: ActionData } = $props();
let sending = $state(false);
let loadingDelay: number;
</script>
<SuccessOrError success={form?.success} message={form?.message} />
2024-08-01 18:09:35 +02:00
{#if sending}
<LoadingSpinner />
{/if}
2024-08-24 21:43:15 +02:00
<section id="overview">
<h2>
<a href="#overview">Overview</a>
</h2>
2024-08-03 13:49:41 +02:00
<ul>
<li>
<strong>Id:</strong>
{data.user.id}
</li>
<li>
<strong>Username:</strong>
{data.user.username}
</li>
</ul>
</section>
2024-08-24 21:43:15 +02:00
<section id="logout">
<h2>
<a href="#logout">Logout</a>
</h2>
<form
method="POST"
action="?/logout"
use:enhance={() => {
loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => {
await update();
window.clearTimeout(loadingDelay);
sending = false;
};
}}
>
<button type="submit">Logout</button>
</form>
</section>
2024-08-24 21:43:15 +02:00
<section id="delete-account">
<h2>
<a href="#delete-account">Delete account</a>
</h2>
2024-08-02 15:33:18 +02:00
<Modal id="delete-account" text="Delete account">
<h3>Delete account</h3>
2024-08-02 15:33:18 +02:00
<p>
<strong>Caution!</strong>
Deleting your account will irretrievably erase all data.
</p>
<form
method="POST"
action="?/deleteAccount"
use:enhance={() => {
loadingDelay = window.setTimeout(() => (sending = true), 500);
return async ({ update }) => {
await update();
window.clearTimeout(loadingDelay);
window.location.hash = "!";
sending = false;
};
}}
>
2024-08-02 15:33:18 +02:00
<label>
Password:
<input type="password" name="password" required />
</label>
<button type="submit">Delete account</button>
2024-08-02 15:33:18 +02:00
</form>
</Modal>
</section>