2023-02-24 17:22:12 +08:00
|
|
|
import React from "react";
|
|
|
|
import { useSelector, useDispatch } from "react-redux";
|
|
|
|
import { toggle } from "../../Features/Login/LoginSlice";
|
|
|
|
import { Button } from "@mui/material";
|
|
|
|
import styles from "../../styles";
|
2023-02-24 18:59:57 +08:00
|
|
|
import { useNavigate } from "react-router-dom";
|
2023-02-24 17:22:12 +08:00
|
|
|
|
|
|
|
export interface state {
|
|
|
|
logged_in: {
|
|
|
|
value: boolean;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
export interface props {
|
|
|
|
children: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Logout(props: props) {
|
|
|
|
const logged_in = useSelector((state: state) => state.logged_in.value);
|
|
|
|
const dispatch = useDispatch();
|
2023-02-24 18:59:57 +08:00
|
|
|
const navigate = useNavigate();
|
2023-02-24 17:22:12 +08:00
|
|
|
|
2023-02-24 18:59:57 +08:00
|
|
|
async function logout() {
|
2023-02-24 17:22:12 +08:00
|
|
|
await dispatch(toggle());
|
2023-02-24 18:59:57 +08:00
|
|
|
navigate("/");
|
2023-02-24 17:22:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={{ paddingTop: "40vh" }}>
|
|
|
|
<Button
|
2023-02-24 18:59:57 +08:00
|
|
|
onClick={logout}
|
2023-02-24 17:22:12 +08:00
|
|
|
value="Log out"
|
|
|
|
variant="contained"
|
|
|
|
style={styles.logout_button}
|
|
|
|
>
|
|
|
|
{props.children}
|
|
|
|
<p style={styles.text}>Log Out</p>
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|