user screen
This commit is contained in:
parent
f8738c5bef
commit
a8f6b6560f
8 changed files with 84 additions and 33 deletions
|
|
@ -111,11 +111,11 @@ def change_subscription(
|
|||
current_user: User = Depends(get_current_user),
|
||||
session: Session = Depends(get_session)
|
||||
):
|
||||
print(subscription)
|
||||
print(current_user)
|
||||
|
||||
current_user.subscription = subscription
|
||||
session.add(current_user)
|
||||
session.commit()
|
||||
session.refresh(current_user)
|
||||
|
||||
|
||||
# TODO:
|
||||
|
|
|
|||
|
|
@ -1,33 +1,73 @@
|
|||
import { useState } from 'preact/hooks';
|
||||
import type { JSX } from 'preact';
|
||||
import { api, AUTH_TOKEN_KEY } from '../lib/api';
|
||||
import { useState } from "preact/hooks";
|
||||
import { api } from "../lib/api";
|
||||
import { logout } from "./Util";
|
||||
import type { JSX } from "preact/jsx-runtime";
|
||||
import { navigate } from "astro/virtual-modules/transitions-router.js";
|
||||
|
||||
export default function DeleteUser() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
|
||||
const handleClick = async (e: JSX.TargetedEvent<HTMLButtonElement>) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
setError('');
|
||||
let hasError = false
|
||||
|
||||
try {
|
||||
const jwt = await api.deleteUser()
|
||||
await api.deleteUser()
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Löschen hat nicht geklappt');
|
||||
hasError = true
|
||||
} finally {
|
||||
setLoading(false);
|
||||
localStorage.removeItem(AUTH_TOKEN_KEY);
|
||||
if (!hasError) {
|
||||
logout()
|
||||
navigate("/")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2>Delete user</h2>
|
||||
<button onClick={e => handleClick(e)} disabled={loading}>
|
||||
<button onClick={() => setShowModal(true)} className="back-btn">
|
||||
Löschen
|
||||
</button>
|
||||
{error && <p style={{ color: 'red' }}>{error}</p>}
|
||||
|
||||
{showModal && (
|
||||
<div style={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
zIndex: 1000
|
||||
}}>
|
||||
<div class="rounded" style={{
|
||||
backgroundColor: 'white',
|
||||
padding: '30px',
|
||||
textAlign: 'left',
|
||||
maxWidth: '500px'
|
||||
}}>
|
||||
<h2>Nutzerkonto löschen</h2>
|
||||
<p>Möchtest du dein Nutzerkonto wirklich löschen?</p>
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between'
|
||||
}}>
|
||||
<button class="back-btn" onClick={() => setShowModal(false)}>
|
||||
Abbrechen
|
||||
</button>
|
||||
<button class="submit-btn" onClick={handleClick}>Ja, löschen</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export default function RegisterForm() {
|
|||
return (
|
||||
<div>
|
||||
<form onSubmit={(e) => { e.preventDefault(); handleRegistration(); }} style="display: flex; flex-direction: column;" >
|
||||
<div class="input-block">
|
||||
<div>
|
||||
<label>Nutzername: </label>
|
||||
<input
|
||||
type="name"
|
||||
|
|
|
|||
|
|
@ -32,11 +32,14 @@ export default function ToggleSubscription() {
|
|||
return (
|
||||
<div>
|
||||
<form onSubmit={handleSubscription}>
|
||||
<div>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={subscription}
|
||||
onChange={e => { setSubscription(e.currentTarget.checked) }}
|
||||
/>
|
||||
<label> E-Mail Benachrichtigungen erhalten</label>
|
||||
</div>
|
||||
{error && <p style={{ color: 'red' }}>{error}</p>}
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { useEffect, useState } from "preact/hooks"
|
||||
import { useEffect } from "preact/hooks"
|
||||
import { checkJWTValidity, getUser } from "./Util"
|
||||
import React from "preact/compat";
|
||||
import type { User } from "../lib/api";
|
||||
|
||||
export default function UserAction() {
|
||||
const [user, setUser] = React.useState<User>({ 'email': '', 'name': '', 'subscription': true });
|
||||
const [user, setUser] = React.useState<User>();
|
||||
|
||||
let text = "⚓︎ Login"
|
||||
let link = "/login"
|
||||
|
|
@ -15,7 +15,6 @@ export default function UserAction() {
|
|||
if (user) setUser(user)
|
||||
}, [])
|
||||
|
||||
|
||||
if (user) {
|
||||
text = `⚓︎ ${user.name}`
|
||||
link = "/user"
|
||||
|
|
|
|||
|
|
@ -13,9 +13,11 @@ export default function UserDetails() {
|
|||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div style="display: flex; flex-direction: column; gap: 16px">
|
||||
<span >Nutzername: {user?.name}</span>
|
||||
<span>E-Mail Adresse: {user?.email}</span>
|
||||
<span style={{
|
||||
margin: '0 0 16px 0'
|
||||
}}>E-Mail Adresse: {user?.email}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
---
|
||||
import DeleteUser from "../islands/DeleteUser";
|
||||
import ToggleSubscription from "../islands/ToggleSubscription";
|
||||
import UserDetails from "../islands/UserDetails";
|
||||
import Form from "../layouts/Form.astro";
|
||||
|
|
@ -7,11 +8,12 @@ import Form from "../layouts/Form.astro";
|
|||
|
||||
<Form
|
||||
title="Moin moin!"
|
||||
subtitle=""
|
||||
text="Hier kannst du dein Konto verwalten."
|
||||
subtitle="Hier kannst du dein Konto verwalten."
|
||||
text=""
|
||||
buttonText="Speichern"
|
||||
eventString="submit-toggle-subscription"
|
||||
>
|
||||
<UserDetails client:load />
|
||||
<ToggleSubscription client:load />
|
||||
<DeleteUser client:load />
|
||||
</Form>
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
* {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
box-sizing: border-box;
|
||||
color: var(--primary-text);
|
||||
}
|
||||
|
||||
main {
|
||||
|
|
@ -59,6 +60,10 @@ body {
|
|||
padding: 12px 12px 12px 0;
|
||||
}
|
||||
|
||||
.back-btn:hover {
|
||||
color: black;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
color: white;
|
||||
border: none;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue