| 1 |
import { useState } from 'react' |
| 2 |
import { Navigate } from 'react-router-dom' |
| 3 |
import { logout } from '../lib/allauth' |
| 4 |
import Button from '../components/Button' |
| 5 |
|
| 6 |
export default function Logout () { |
| 7 |
const [response, setResponse] = useState({ fetching: false, content: null }) |
| 8 |
|
| 9 |
function submit () { |
| 10 |
setResponse({ ...response, fetching: true }) |
| 11 |
logout().then((content) => { |
| 12 |
setResponse((r) => { return { ...r, content } }) |
| 13 |
}).catch((e) => { |
| 14 |
console.error(e) |
| 15 |
window.alert(e) |
| 16 |
}).then(() => { |
| 17 |
setResponse((r) => { return { ...r, fetching: false } }) |
| 18 |
}) |
| 19 |
} |
| 20 |
if (response.content) { |
| 21 |
return <Navigate to='/' /> |
| 22 |
} |
| 23 |
return ( |
| 24 |
<div> |
| 25 |
<h1>Logout</h1> |
| 26 |
<p> |
| 27 |
Are you sure you want to logout? |
| 28 |
</p> |
| 29 |
|
| 30 |
<Button disabled={response.fetching} onClick={() => submit()}>Logout</Button> |
| 31 |
</div> |
| 32 |
) |
| 33 |
} |