Skip to content

Commit

Permalink
admin: admin page improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSavage committed Jan 4, 2025
1 parent bfb540f commit 4bca575
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
47 changes: 44 additions & 3 deletions zettelkasten-front/src/pages/admin/AdminPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect } from "react";
import React, { useEffect, useState } from "react";
import { useAuth } from "../../contexts/AuthContext";
import { useNavigate, Link } from "react-router-dom";
import { MenuIcon } from "../../assets/icons/MenuIcon";

import { AdminUserIndex } from "./AdminUserIndex";
import { AdminUserDetailPage } from "./AdminUserDetailPage";
Expand All @@ -14,6 +15,7 @@ import { Routes, Route } from "react-router-dom";
export function Admin() {
const { isAdmin, isLoading } = useAuth();
const navigate = useNavigate();
const [isSidebarOpen, setIsSidebarOpen] = useState(false);

useEffect(() => {
if (!isLoading && !isAdmin) {
Expand All @@ -35,8 +37,42 @@ export function Admin() {

return (
<div className="flex h-screen overflow-hidden">
{/* Fixed Sidebar */}
<div className="w-64 flex-shrink-0 bg-gray-800">
{/* Mobile Menu Button */}
<button
className="md:hidden fixed top-4 right-4 z-[60] p-2 bg-white rounded shadow"
onClick={() => setIsSidebarOpen(!isSidebarOpen)}
>
<MenuIcon />
</button>

{/* Mobile Backdrop */}
{isSidebarOpen && (
<div
className="fixed inset-0 bg-black bg-opacity-50 md:hidden z-[45]"
onClick={() => setIsSidebarOpen(false)}
/>
)}

{/* Sidebar */}
<div
className={`
fixed md:relative
w-64
min-w-[16rem]
max-w-[16rem]
flex-shrink-0
h-screen
bg-gray-800
flex flex-col
transform
${isSidebarOpen ? "translate-x-0" : "-translate-x-full"}
md:translate-x-0
transition-transform
duration-300
ease-in-out
z-[50]
`}
>
<div className="h-full flex flex-col">
<div className="flex-1 overflow-y-auto py-4">
<nav className="px-4">
Expand All @@ -45,6 +81,7 @@ export function Admin() {
<Link
to="/admin"
className="block py-2 px-4 rounded-lg hover:bg-gray-700 text-gray-300 hover:text-white transition-colors"
onClick={() => setIsSidebarOpen(false)}
>
Users
</Link>
Expand All @@ -53,6 +90,7 @@ export function Admin() {
<Link
to="/admin/mailing-list"
className="block py-2 px-4 rounded-lg hover:bg-gray-700 text-gray-300 hover:text-white transition-colors"
onClick={() => setIsSidebarOpen(false)}
>
Mailing List Subscribers
</Link>
Expand All @@ -61,6 +99,7 @@ export function Admin() {
<Link
to="/admin/mailing-list/send"
className="block py-2 px-4 rounded-lg hover:bg-gray-700 text-gray-300 hover:text-white transition-colors"
onClick={() => setIsSidebarOpen(false)}
>
Send Mailing List Message
</Link>
Expand All @@ -69,6 +108,7 @@ export function Admin() {
<Link
to="/admin/mailing-list/history"
className="block py-2 px-4 rounded-lg hover:bg-gray-700 text-gray-300 hover:text-white transition-colors"
onClick={() => setIsSidebarOpen(false)}
>
Message History
</Link>
Expand All @@ -77,6 +117,7 @@ export function Admin() {
<Link
to="/app"
className="block py-2 px-4 rounded-lg hover:bg-gray-700 text-gray-300 hover:text-white transition-colors"
onClick={() => setIsSidebarOpen(false)}
>
Back to App
</Link>
Expand Down
18 changes: 3 additions & 15 deletions zettelkasten-front/src/pages/admin/AdminUserIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,14 @@ export function AdminUserIndex() {
cell: (info) => (
<Link
to={`/admin/user/${info.row.original.id}`}
className="text-blue-600 hover:text-blue-800"
className={`hover:text-blue-800 ${
info.row.original.is_admin ? "text-purple-600" : "text-blue-600"
}`}
>
{info.getValue()}
</Link>
),
}),
columnHelper.accessor("is_admin", {
header: "Admin",
cell: (info) => (
<span
className={`px-2 py-1 rounded text-sm ${
info.getValue()
? "bg-purple-100 text-purple-800"
: "bg-gray-100 text-gray-800"
}`}
>
{info.getValue() ? "Yes" : "No"}
</span>
),
}),
columnHelper.accessor("last_login", {
header: "Last Login",
cell: (info) => new Date(info.getValue()).toLocaleString(),
Expand Down

0 comments on commit 4bca575

Please sign in to comment.