mirror of
https://github.com/lemeow125/Ivy-Frontend.git
synced 2024-11-17 06:39:25 +08:00
Added logout button
This commit is contained in:
parent
0a7613bb75
commit
d0b7bcc45f
3 changed files with 51 additions and 1 deletions
37
src/components/Logout/Logout.tsx
Normal file
37
src/components/Logout/Logout.tsx
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import React, { useState } from "react";
|
||||||
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
|
import { toggle } from "../../Features/Login/LoginSlice";
|
||||||
|
import { Button } from "@mui/material";
|
||||||
|
import styles from "../../styles";
|
||||||
|
|
||||||
|
export interface state {
|
||||||
|
logged_in: {
|
||||||
|
value: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export default function Logout() {
|
||||||
|
const logged_in = useSelector((state: state) => state.logged_in.value);
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
async function login() {
|
||||||
|
await dispatch(toggle());
|
||||||
|
await console.log("test " + logged_in);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!logged_in) {
|
||||||
|
return <div></div>;
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<div style={{ paddingTop: 384 }}>
|
||||||
|
<Button
|
||||||
|
onClick={login}
|
||||||
|
value="Log out"
|
||||||
|
variant="contained"
|
||||||
|
style={styles.logout_button}
|
||||||
|
>
|
||||||
|
<p style={styles.text}>Log Out</p>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import styles from "../../styles";
|
import styles from "../../styles";
|
||||||
import SidebarButton from "../SidebarButton/SidebarButton";
|
import SidebarButton from "../SidebarButton/SidebarButton";
|
||||||
import { redirect } from "react-router-dom";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import Logout from "../Logout/Logout";
|
||||||
export interface state {
|
export interface state {
|
||||||
minimized: {
|
minimized: {
|
||||||
value: boolean;
|
value: boolean;
|
||||||
|
@ -18,6 +18,7 @@ export default function Sidebar() {
|
||||||
<SidebarButton onClick={() => navigate("/Products")} name="Products" />
|
<SidebarButton onClick={() => navigate("/Products")} name="Products" />
|
||||||
<SidebarButton onClick={() => navigate("/Inventory")} name="Inventory" />
|
<SidebarButton onClick={() => navigate("/Inventory")} name="Inventory" />
|
||||||
<SidebarButton onClick={() => navigate("/Logs")} name="Logs" />
|
<SidebarButton onClick={() => navigate("/Logs")} name="Logs" />
|
||||||
|
<Logout />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,18 @@ const styles: { [key: string]: React.CSSProperties } = {
|
||||||
padding: 8,
|
padding: 8,
|
||||||
borderRadius: 16,
|
borderRadius: 16,
|
||||||
},
|
},
|
||||||
|
logout_button: {
|
||||||
|
backgroundColor: "#0b2322",
|
||||||
|
width: 256,
|
||||||
|
height: 64,
|
||||||
|
border: "none",
|
||||||
|
padding: 8,
|
||||||
|
borderRadius: 16,
|
||||||
|
borderTopLeftRadius: 32,
|
||||||
|
borderBottomLeftRadius: 32,
|
||||||
|
borderTopRightRadius: 0,
|
||||||
|
borderBottomRightRadius: 0,
|
||||||
|
},
|
||||||
sidebar_button: {
|
sidebar_button: {
|
||||||
backgroundColor: "#0b2322",
|
backgroundColor: "#0b2322",
|
||||||
width: 256,
|
width: 256,
|
||||||
|
|
Loading…
Reference in a new issue