fixed shit
This commit is contained in:
parent
778bcfd6bd
commit
b6c839d99f
1 changed files with 11 additions and 4 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import { useEffect, useState } from 'preact/hooks';
|
import { useEffect, useState } from 'preact/hooks';
|
||||||
import { api, type User } from '../lib/api';
|
import { api, type User } from '../lib/api';
|
||||||
import React from 'preact/compat';
|
import React from 'preact/compat';
|
||||||
import { getUser } from './Util';
|
import { getUser, saveUser } from './Util';
|
||||||
|
|
||||||
export default function ToggleSubscription() {
|
export default function ToggleSubscription() {
|
||||||
const [subscription, setSubscription] = React.useState<boolean>(false);
|
const [subscription, setSubscription] = React.useState<boolean>(false);
|
||||||
|
|
@ -11,6 +11,7 @@ export default function ToggleSubscription() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
user = getUser()
|
user = getUser()
|
||||||
if (!user) navigation.back()
|
if (!user) navigation.back()
|
||||||
|
else setSubscription(user.subscription)
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleSubscription = async () => {
|
const handleSubscription = async () => {
|
||||||
|
|
@ -20,10 +21,16 @@ export default function ToggleSubscription() {
|
||||||
try {
|
try {
|
||||||
api.toggleSubscription(subscription)
|
api.toggleSubscription(subscription)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Update');
|
setError(err instanceof Error ? err.message : 'Update fehlgeschlagen');
|
||||||
hasError = true
|
hasError = true
|
||||||
|
console.log(hasError);
|
||||||
} finally {
|
} finally {
|
||||||
// if (!hasError) // TODO: snackbar
|
if (!hasError) {
|
||||||
|
if (user) {
|
||||||
|
user = {...user, subscription: false }
|
||||||
|
saveUser(user)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -35,7 +42,7 @@ export default function ToggleSubscription() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div style={{
|
||||||
marginBottom: '16px',
|
marginBottom: '16px'
|
||||||
}}>
|
}}>
|
||||||
<form onSubmit={handleSubscription}>
|
<form onSubmit={handleSubscription}>
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue