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