2023-02-24 17:22:12 +08:00
|
|
|
import React from "react";
|
2023-03-02 20:42:11 +08:00
|
|
|
import { useDispatch } from "react-redux";
|
2023-03-06 13:06:43 +08:00
|
|
|
import { toggle_login } from "../../Features/Redux/Slices/Login/LoginSlice";
|
2023-02-24 17:22:12 +08:00
|
|
|
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 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-03-06 00:56:21 +08:00
|
|
|
await dispatch(toggle_login());
|
2023-03-06 14:28:18 +08:00
|
|
|
localStorage.removeItem("token");
|
2023-02-24 18:59:57 +08:00
|
|
|
navigate("/");
|
2023-02-24 17:22:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-03-07 18:00:49 +08:00
|
|
|
<div>
|
2023-02-24 17:22:12 +08:00
|
|
|
<Button
|
2023-02-24 18:59:57 +08:00
|
|
|
onClick={logout}
|
2023-02-24 17:22:12 +08:00
|
|
|
value="Log out"
|
|
|
|
variant="contained"
|
2023-03-07 18:00:49 +08:00
|
|
|
style={styles.sidebar_button}
|
2023-02-24 17:22:12 +08:00
|
|
|
>
|
|
|
|
{props.children}
|
2023-03-05 23:48:49 +08:00
|
|
|
<p style={{ ...styles.text_white, ...styles.text_S }}>Log Out</p>
|
2023-02-24 17:22:12 +08:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|