diff options
| author | Adam Soltys <[email protected]> | 2024-09-17 20:29:53 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-09-17 20:29:53 -0700 |
| commit | f893043b00750ad693fc886eb77184598b9c8317 (patch) | |
| tree | 5994183bb43e824cee9366df3d2d452d077ecb5c /src/routes/(app)/account | |
| parent | b0fe475ac2e6549369d08afdc082968638a2e52c (diff) | |
| download | coinos-ui-f893043b00750ad693fc886eb77184598b9c8317.tar.gz coinos-ui-f893043b00750ad693fc886eb77184598b9c8317.zip | |
account deletion
Diffstat (limited to 'src/routes/(app)/account')
| -rw-r--r-- | src/routes/(app)/account/[id]/+page.server.ts | 8 | ||||
| -rw-r--r-- | src/routes/(app)/account/[id]/+page.svelte | 34 |
2 files changed, 38 insertions, 4 deletions
diff --git a/src/routes/(app)/account/[id]/+page.server.ts b/src/routes/(app)/account/[id]/+page.server.ts index 7d1c503a..35b5517d 100644 --- a/src/routes/(app)/account/[id]/+page.server.ts +++ b/src/routes/(app)/account/[id]/+page.server.ts @@ -1,5 +1,11 @@ import { error, redirect } from "@sveltejs/kit"; -import { auth, post, fd } from "$lib/utils"; +import { auth, get, post, fd } from "$lib/utils"; + + +export let load = async ({ cookies, params }) => { + let account = await get(`/account/${params.id}`, auth(cookies)); + return { account }; +} export const actions = { default: async ({ cookies, params, request }) => { diff --git a/src/routes/(app)/account/[id]/+page.svelte b/src/routes/(app)/account/[id]/+page.svelte index 152e8dfc..df121168 100644 --- a/src/routes/(app)/account/[id]/+page.svelte +++ b/src/routes/(app)/account/[id]/+page.svelte @@ -1,8 +1,22 @@ <script> + import { goto } from "$app/navigation"; + import { fail, focus, post } from "$lib/utils"; import { enhance } from "$app/forms"; import { t } from "$lib/translations"; import Icon from "$comp/Icon.svelte"; - let name; + + export let data; + let { account, user } = data; + let { id, name } = account; + + let del = async () => { + try { + await post("/api/account/delete", { id }); + goto(`/${user.username}`); + } catch (e) { + fail(e.message); + } + }; </script> <div class="space-y-5"> @@ -12,10 +26,24 @@ <form class="space-y-5" method="POST"> <div> <label for="display" class="font-bold mb-1 block">Account name</label> - <input type="text" name="name" bind:value={name} /> + <input use:focus type="text" name="name" bind:value={name} /> </div> - <button type="submit">Save</button> + <div class="space-y-2"> + <button + type="submit" + class="rounded-2xl border py-3 font-bold mx-auto bg-black text-white px-4 w-full" + >Submit</button + > + <button + on:click={del} + type="button" + class="flex gap-2 rounded-2xl border py-3 font-bold mx-auto px-4 w-full justify-center border-red-600 border-2" + > + <Icon icon="trash" style="w-8 my-auto" /> + <div class="my-auto">Delete</div></button + > + </div> </form> </div> </div> |
