@@ -9,19 +9,28 @@ import { ShopPage } from "./components/ShopPage.jsx";
99import { TestPage } from "./components/TestPage.jsx" ;
1010import { AdminAirtableSyncPage } from "./components/AdminAirtableSyncPage.jsx" ;
1111import { AdminPage } from "./components/AdminPage.jsx" ;
12+ import { AdminReviewPage } from "./components/AdminReviewPage.jsx" ;
1213import { AdminShopPage } from "./components/AdminShopPage.jsx" ;
1314import { AdminShopOrdersPage } from "./components/AdminShopOrdersPage.jsx" ;
1415import { AdminUsersPage } from "./components/AdminUsersPage.jsx" ;
1516import { UserAreaPage } from "./components/UserAreaPage.jsx" ;
1617
1718const 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
2028export 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 }
0 commit comments