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),
|
current_user: User = Depends(get_current_user),
|
||||||
session: Session = Depends(get_session)
|
session: Session = Depends(get_session)
|
||||||
):
|
):
|
||||||
print(subscription)
|
|
||||||
print(current_user)
|
|
||||||
current_user.subscription = subscription
|
current_user.subscription = subscription
|
||||||
session.add(current_user)
|
session.add(current_user)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
session.refresh(current_user)
|
||||||
|
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,73 @@
|
||||||
import { useState } from 'preact/hooks';
|
import { useState } from "preact/hooks";
|
||||||
import type { JSX } from 'preact';
|
import { api } from "../lib/api";
|
||||||
import { api, AUTH_TOKEN_KEY } 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() {
|
export default function DeleteUser() {
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
|
const [showModal, setShowModal] = useState(false);
|
||||||
|
|
||||||
const handleClick = async (e: JSX.TargetedEvent<HTMLButtonElement>) => {
|
const handleClick = async (e: JSX.TargetedEvent<HTMLButtonElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setLoading(true);
|
|
||||||
setError('');
|
setError('');
|
||||||
|
let hasError = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const jwt = await api.deleteUser()
|
await api.deleteUser()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Löschen hat nicht geklappt');
|
setError(err instanceof Error ? err.message : 'Löschen hat nicht geklappt');
|
||||||
|
hasError = true
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
if (!hasError) {
|
||||||
localStorage.removeItem(AUTH_TOKEN_KEY);
|
logout()
|
||||||
|
navigate("/")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2>Delete user</h2>
|
<button onClick={() => setShowModal(true)} className="back-btn">
|
||||||
<button onClick={e => handleClick(e)} disabled={loading}>
|
|
||||||
Löschen
|
Löschen
|
||||||
</button>
|
</button>
|
||||||
{error && <p style={{ color: 'red' }}>{error}</p>}
|
{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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ export default function RegisterForm() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<form onSubmit={(e) => { e.preventDefault(); handleRegistration(); }} style="display: flex; flex-direction: column;" >
|
<form onSubmit={(e) => { e.preventDefault(); handleRegistration(); }} style="display: flex; flex-direction: column;" >
|
||||||
<div class="input-block">
|
<div>
|
||||||
<label>Nutzername: </label>
|
<label>Nutzername: </label>
|
||||||
<input
|
<input
|
||||||
type="name"
|
type="name"
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,14 @@ export default function ToggleSubscription() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<form onSubmit={handleSubscription}>
|
<form onSubmit={handleSubscription}>
|
||||||
|
<div>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={subscription}
|
checked={subscription}
|
||||||
onChange={e => { setSubscription(e.currentTarget.checked) }}
|
onChange={e => { setSubscription(e.currentTarget.checked) }}
|
||||||
/>
|
/>
|
||||||
|
<label> E-Mail Benachrichtigungen erhalten</label>
|
||||||
|
</div>
|
||||||
{error && <p style={{ color: 'red' }}>{error}</p>}
|
{error && <p style={{ color: 'red' }}>{error}</p>}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { useEffect, useState } from "preact/hooks"
|
import { useEffect } from "preact/hooks"
|
||||||
import { checkJWTValidity, getUser } from "./Util"
|
import { checkJWTValidity, getUser } from "./Util"
|
||||||
import React from "preact/compat";
|
import React from "preact/compat";
|
||||||
import type { User } from "../lib/api";
|
import type { User } from "../lib/api";
|
||||||
|
|
||||||
export default function UserAction() {
|
export default function UserAction() {
|
||||||
const [user, setUser] = React.useState<User>({ 'email': '', 'name': '', 'subscription': true });
|
const [user, setUser] = React.useState<User>();
|
||||||
|
|
||||||
let text = "⚓︎ Login"
|
let text = "⚓︎ Login"
|
||||||
let link = "/login"
|
let link = "/login"
|
||||||
|
|
@ -15,7 +15,6 @@ export default function UserAction() {
|
||||||
if (user) setUser(user)
|
if (user) setUser(user)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
text = `⚓︎ ${user.name}`
|
text = `⚓︎ ${user.name}`
|
||||||
link = "/user"
|
link = "/user"
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,11 @@ export default function UserDetails() {
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div style="display: flex; flex-direction: column; gap: 16px">
|
||||||
<span >Nutzername: {user?.name}</span>
|
<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>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
---
|
---
|
||||||
|
import DeleteUser from "../islands/DeleteUser";
|
||||||
import ToggleSubscription from "../islands/ToggleSubscription";
|
import ToggleSubscription from "../islands/ToggleSubscription";
|
||||||
import UserDetails from "../islands/UserDetails";
|
import UserDetails from "../islands/UserDetails";
|
||||||
import Form from "../layouts/Form.astro";
|
import Form from "../layouts/Form.astro";
|
||||||
|
|
@ -7,11 +8,12 @@ import Form from "../layouts/Form.astro";
|
||||||
|
|
||||||
<Form
|
<Form
|
||||||
title="Moin moin!"
|
title="Moin moin!"
|
||||||
subtitle=""
|
subtitle="Hier kannst du dein Konto verwalten."
|
||||||
text="Hier kannst du dein Konto verwalten."
|
text=""
|
||||||
buttonText="Speichern"
|
buttonText="Speichern"
|
||||||
eventString="submit-toggle-subscription"
|
eventString="submit-toggle-subscription"
|
||||||
>
|
>
|
||||||
<UserDetails client:load />
|
<UserDetails client:load />
|
||||||
<ToggleSubscription client:load />
|
<ToggleSubscription client:load />
|
||||||
|
<DeleteUser client:load />
|
||||||
</Form>
|
</Form>
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
* {
|
* {
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
color: var(--primary-text);
|
||||||
}
|
}
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
@ -59,6 +60,10 @@ body {
|
||||||
padding: 12px 12px 12px 0;
|
padding: 12px 12px 12px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.back-btn:hover {
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
.submit-btn {
|
.submit-btn {
|
||||||
color: white;
|
color: white;
|
||||||
border: none;
|
border: none;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue