From f77a00528e15af92620e9dc1d7ccdf4142bdb0db Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 19 Sep 2023 15:02:15 -0700 Subject: [PATCH] Add admin insights page --- devblog/devblog/ClientApp/src/App.tsx | 4 +- .../src/components/DeleteAccount.tsx | 34 +++++---- .../devblog/ClientApp/src/components/Nav.tsx | 7 ++ .../ClientApp/src/components/styles/Nav.css | 13 +++- .../devblog/ClientApp/src/pages/AddPost.tsx | 36 +++++----- .../devblog/ClientApp/src/pages/Insights.tsx | 71 +++++++++++++++++++ .../devblog/ClientApp/src/pages/SignOut.tsx | 2 +- .../ClientApp/src/pages/styles/AddPost.css | 42 ++++++----- .../ClientApp/src/pages/styles/Insights.css | 21 ++++++ .../devblog/Controllers/AccountsController.cs | 51 ++++++++++++- 10 files changed, 225 insertions(+), 56 deletions(-) create mode 100644 devblog/devblog/ClientApp/src/pages/Insights.tsx create mode 100644 devblog/devblog/ClientApp/src/pages/styles/Insights.css diff --git a/devblog/devblog/ClientApp/src/App.tsx b/devblog/devblog/ClientApp/src/App.tsx index 1b2e69f5..ac18f8cc 100644 --- a/devblog/devblog/ClientApp/src/App.tsx +++ b/devblog/devblog/ClientApp/src/App.tsx @@ -7,8 +7,9 @@ import Home from './pages/Home'; import SignIn from './pages/SignIn'; import Posts from './pages/Posts'; import SignUp from './pages/SignUp'; -import "./global.css"; import About from './pages/About'; +import Insights from './pages/Insights'; +import "./global.css"; const App = () => { return ( @@ -19,6 +20,7 @@ const App = () => { } /> } /> } /> + } /> } /> } /> } /> diff --git a/devblog/devblog/ClientApp/src/components/DeleteAccount.tsx b/devblog/devblog/ClientApp/src/components/DeleteAccount.tsx index 9daf84be..fc851877 100644 --- a/devblog/devblog/ClientApp/src/components/DeleteAccount.tsx +++ b/devblog/devblog/ClientApp/src/components/DeleteAccount.tsx @@ -11,21 +11,25 @@ const DeleteAccount = () => { }, []); const handleDelete = async () => { - await fetch(`api/accounts/${userName}`, { - method: "DELETE", - headers: { - "Content-Type": "application/json", - "Authorization": `Bearer ${localStorage.getItem("token")}` - } - }).then(async () => { - await fetch(`api/accounts/signout`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - }).then(() => { - localStorage.clear(); - window.location.reload(); - }); - }) + const shouldDelete = window.confirm("Are you sure?"); + + if (shouldDelete) { + await fetch(`api/accounts/${userName}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${localStorage.getItem("token")}` + } + }).then(async () => { + await fetch(`api/accounts/signout`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + }).then(() => { + localStorage.clear(); + window.location.reload(); + }); + }) + } }; return <>{loggedIn && } diff --git a/devblog/devblog/ClientApp/src/components/Nav.tsx b/devblog/devblog/ClientApp/src/components/Nav.tsx index c3367353..21f99efd 100644 --- a/devblog/devblog/ClientApp/src/components/Nav.tsx +++ b/devblog/devblog/ClientApp/src/components/Nav.tsx @@ -3,6 +3,7 @@ import { Link, useLocation } from "react-router-dom"; import SignOut from "../pages/SignOut"; import { MdMenu } from "react-icons/md"; import { IsLoggedIn } from "../components/AuthenticationService"; +import { GetIsAdmin } from "./AuthenticationService"; import "./styles/Nav.css"; const Nav = () => { @@ -10,8 +11,11 @@ const Nav = () => { const [userName, setUsername] = useState(""); const [isMenuClicked, setIsMenuClicked] = useState(false) const [display, setDisplay] = useState("none") + const [isAdmin, setIsAdmin] = useState(false); const location = useLocation(); + useEffect(() => setIsAdmin(GetIsAdmin), []); + const isActive = (path: string) => { return location.pathname === path ? "active" : "non-active"; }; @@ -52,6 +56,7 @@ const Nav = () => { Home Posts About + {isAdmin && Insights} {loggedIn ? ( @@ -74,6 +79,8 @@ const Nav = () => { Home Posts About + {isAdmin && Insights} + {loggedIn && } {!loggedIn && diff --git a/devblog/devblog/ClientApp/src/components/styles/Nav.css b/devblog/devblog/ClientApp/src/components/styles/Nav.css index 5cb95b13..8d84b830 100644 --- a/devblog/devblog/ClientApp/src/components/styles/Nav.css +++ b/devblog/devblog/ClientApp/src/components/styles/Nav.css @@ -53,7 +53,8 @@ s .navbar .nav-items a.active { .nav-items>a:nth-child(1), .nav-items>a:nth-child(2), -.nav-items>a:nth-child(3) { +.nav-items>a:nth-child(3), +.nav-items>a:nth-child(4) { margin-top: auto; margin-bottom: 5px; } @@ -96,7 +97,10 @@ s .navbar .nav-items a.active { .mobile-nav-links form { text-decoration: none; padding-top: 5px; - /* border: 2px solid yellow; */ + } + + .mobile-nav-links>a:hover { + opacity: 1.0; } .mobile-nav-links a.active { @@ -120,9 +124,12 @@ s .navbar .nav-items a.active { flex-direction: column; } + .logout-form { + width: fit-content; + } + .logout { font-size: 16px; - margin-left: auto; padding: 0px; } } \ No newline at end of file diff --git a/devblog/devblog/ClientApp/src/pages/AddPost.tsx b/devblog/devblog/ClientApp/src/pages/AddPost.tsx index 46d334e6..3483efc8 100644 --- a/devblog/devblog/ClientApp/src/pages/AddPost.tsx +++ b/devblog/devblog/ClientApp/src/pages/AddPost.tsx @@ -113,26 +113,28 @@ const AddPost = () => { - +
+ -