idk a lot of changes for the admin stuff
This commit is contained in:
parent
2cbbc00489
commit
5251ca6f99
23 changed files with 576 additions and 15 deletions
|
|
@ -1,15 +1,23 @@
|
|||
import { Navbar as BsNavbar, Button, Container } from "react-bootstrap";
|
||||
// import styles from "./Navbar.module.scss";
|
||||
import Searchbar from "../Searchbar/Searchbar";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import Cookies from "js-cookie";
|
||||
import { GetCurrentUser, type Login } from "../../Lib/Auth";
|
||||
|
||||
const Navbar = () => {
|
||||
const [searchText, setSearchText] = useState<string>("");
|
||||
const [currentUser, setCurrentUser] = useState<Login | undefined>(undefined);
|
||||
const navigate = useNavigate();
|
||||
const session = Cookies.get("session");
|
||||
|
||||
useEffect(() => {
|
||||
GetCurrentUser().then(user => {
|
||||
setCurrentUser(user);
|
||||
});
|
||||
}, [session]);
|
||||
|
||||
function onLogout() {
|
||||
Cookies.remove("session");
|
||||
navigate("/login");
|
||||
|
|
@ -20,8 +28,12 @@ const Navbar = () => {
|
|||
setSearchText("");
|
||||
}
|
||||
|
||||
function onManageUser() {
|
||||
navigate("/user");
|
||||
}
|
||||
|
||||
return (
|
||||
<BsNavbar expand="lg" className={"bg-light "}>
|
||||
<BsNavbar expand="lg" className={"bg-light"} style={{ paddingRight: "10px" }}>
|
||||
<Container>
|
||||
<Link to={"/"} style={{ textDecoration: "none" }}>
|
||||
<BsNavbar.Brand>JellyGlass</BsNavbar.Brand>
|
||||
|
|
@ -33,7 +45,9 @@ const Navbar = () => {
|
|||
</Container>
|
||||
</BsNavbar.Collapse>
|
||||
{session && <Button onClick={onLogout}>Logout</Button>}
|
||||
{session && currentUser?.isAdmin && <Link to={"/admin"} style={{ paddingLeft: "10px" }}><Button>Admin</Button></Link>}
|
||||
</Container>
|
||||
<Button onClick={() => onManageUser()}>Manage User</Button>
|
||||
</BsNavbar>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue