Skip to content

Commit 10cce03

Browse files
committed
UPDATE - review system
1 parent 72c8e2d commit 10cce03

14 files changed

Lines changed: 1570 additions & 32 deletions

client/src/App.jsx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,28 @@ import { ShopPage } from "./components/ShopPage.jsx";
99
import { TestPage } from "./components/TestPage.jsx";
1010
import { AdminAirtableSyncPage } from "./components/AdminAirtableSyncPage.jsx";
1111
import { AdminPage } from "./components/AdminPage.jsx";
12+
import { AdminReviewPage } from "./components/AdminReviewPage.jsx";
1213
import { AdminShopPage } from "./components/AdminShopPage.jsx";
1314
import { AdminShopOrdersPage } from "./components/AdminShopOrdersPage.jsx";
1415
import { AdminUsersPage } from "./components/AdminUsersPage.jsx";
1516
import { UserAreaPage } from "./components/UserAreaPage.jsx";
1617

1718
const PROTECTED = new Set(["/main", "/shop", "/projects", "/faq", "/user", "/test", "/admin"]);
18-
const ADMIN_ONLY = new Set(["/admin"]);
19+
20+
function canStaffReviewRole(role) {
21+
return role === "reviewer" || role === "admin" || role === "superadmin";
22+
}
23+
24+
function canFullAdminRole(role) {
25+
return role === "admin" || role === "superadmin";
26+
}
1927

2028
export default function App() {
2129
const [auth, setAuth] = useState({ status: "loading", user: null });
2230
const pathname = window.location.pathname.replace(/\/+$/, "") || "/";
2331
const isLocalhost = ["localhost", "127.0.0.1"].includes(window.location.hostname);
24-
const isAdminPath = pathname === "/admin" || pathname.startsWith("/admin/");
32+
const isAnyAdminPath = pathname === "/admin" || pathname.startsWith("/admin/");
33+
const isReviewPath = pathname === "/admin/review" || pathname.startsWith("/admin/review/");
2534

2635
const loadMe = useCallback(async () => {
2736
try {
@@ -45,15 +54,24 @@ export default function App() {
4554
);
4655
}
4756

48-
if ((PROTECTED.has(pathname) || isAdminPath) && !auth.user) {
57+
if ((PROTECTED.has(pathname) || isAnyAdminPath) && !auth.user) {
4958
const returnTo = `${pathname}${window.location.search}${window.location.hash}`;
5059
window.location.replace(`/login?returnTo=${encodeURIComponent(returnTo)}`);
5160
return null;
5261
}
5362

54-
if ((ADMIN_ONLY.has(pathname) || isAdminPath) && auth.user?.role !== "admin") {
55-
window.location.replace("/main");
56-
return null;
63+
const role = auth.user?.role;
64+
65+
if (isAnyAdminPath && auth.user) {
66+
if (isReviewPath) {
67+
if (!canStaffReviewRole(role)) {
68+
window.location.replace("/main");
69+
return null;
70+
}
71+
} else if (!canFullAdminRole(role)) {
72+
window.location.replace(canStaffReviewRole(role) ? "/admin/review" : "/main");
73+
return null;
74+
}
5775
}
5876

5977
if (pathname === "/" && auth.user) {
@@ -110,9 +128,14 @@ export default function App() {
110128
case "/admin/shop/orders":
111129
page = <AdminShopOrdersPage />;
112130
break;
131+
case "/admin/review":
132+
page = <AdminReviewPage />;
133+
break;
113134
default:
114135
if (pathname.startsWith("/admin/users/")) {
115136
page = <AdminUsersPage userId={pathname.split("/").pop()} />;
137+
} else if (pathname.startsWith("/admin/review/project/")) {
138+
page = <AdminReviewPage projectId={pathname.split("/").pop()} />;
116139
} else {
117140
page = <Hero />;
118141
}

client/src/components/AdminPage.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const adminLinks = [
1313

1414
export function AdminPage() {
1515
const { user } = useAuth();
16-
const showSuperAdmin = user?.role === "super_admin";
16+
const showSuperAdmin = user?.role === "superadmin";
1717

1818
return (
1919
<main className="admin-page" aria-label="Admin page">

0 commit comments

Comments
 (0)