-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.jsx
More file actions
60 lines (58 loc) · 1.97 KB
/
Account.jsx
File metadata and controls
60 lines (58 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React, {useEffect, useState} from 'react';
import axios from 'axios';
import { ScaleButton } from '@telekom/scale-components-react';
function Account() {
const Content = () => {
const [content, setContent] = useState("");
useEffect(() => {
const jsontoken = {
"verify": {
"token": sessionStorage.getItem('token')
}
}
setContent(
<h1>Checking Token...</h1>
)
axios.post('/api/verifylogin', jsontoken)
.then((response) => {
setContent(
<div class="centered">
<h3>Do you want to delete your account?</h3>
<ScaleButton type="button" id="del-btn">Delete Account</ScaleButton>
</div>
)
document.getElementById("del-btn").addEventListener("click", function(){
setContent(
<div class="centered">
<h3>Deleting account...</h3>
</div>
)
axios.post('/api/deleteaccount', jsontoken)
.then((response) => {
alert("Account successfully deleted")
window.location.replace("/");
})
.catch((reason) => {
alert("Something went wrong")
})
}, false);
})
.catch((reason) => {
console.log(reason.response.data)
setContent(
<h1>You need to sign-in first! Redirecting...</h1>
)
setTimeout(() => {
window.location.replace("/login");
}, 1000)
})
}, [])
return content
}
return (
<div class="centered">
<Content/>
</div>
);
}
export default Account;