Skip to content

Commit 9dbcef0

Browse files
committed
use common admin page layout, fix styling
1 parent 294f2b8 commit 9dbcef0

File tree

5 files changed

+62
-55
lines changed

5 files changed

+62
-55
lines changed

frontend/src/App.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { BrowserRouter, Route, Routes } from "react-router-dom";
22
import SearchPage from "./pages/SearchPage";
33
import UploadPage from "./pages/UploadPage";
44
import OAuthPage from "./pages/OAuthPage";
5+
import AdminLayout from "./pages/AdminLayout";
56
import AdminDashboard from "./pages/AdminDashboard";
67
import TrashPage from "./pages/TrashPage";
78
import { AuthProvider } from "./utils/auth";
@@ -26,14 +27,16 @@ function App() {
2627
path="/oauth"
2728
element={<OAuthPage />}
2829
/>
29-
<Route
30-
path="/admin"
31-
element={<AdminDashboard />}
32-
/>
33-
<Route
34-
path="/admin/trash"
35-
element={<TrashPage />}
36-
/>
30+
<Route path="/admin" element={<AdminLayout />}>
31+
<Route
32+
index
33+
element={<AdminDashboard />}
34+
/>
35+
<Route
36+
path="trash"
37+
element={<TrashPage />}
38+
/>
39+
</Route>
3740
</Routes>
3841
</AuthProvider>
3942
<Footer />

frontend/src/pages/AdminDashboard.tsx

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,7 @@ function AdminDashboard() {
214214

215215

216216
useEffect(() => {
217-
if (!auth.isAuthenticated) {
218-
window.location.assign(OAUTH_LOGIN_URL);
219-
} else {
220217
fetchUnapprovedPapers();
221-
}
222218
}, []);
223219

224220
const storeOcrDetails = async (paper: IAdminDashboardQP) => {
@@ -263,22 +259,8 @@ function AdminDashboard() {
263259
// ocrDetailsLoop();
264260
// }, [ocrRequests])
265261

266-
return auth.isAuthenticated ? (
267-
<div id="admin-dashboard">
268-
<Header
269-
title="Admin Dashboard"
270-
subtitle="Top secret documents - to be approved inside n-sided polygon shaped buildings only."
271-
link={{
272-
onClick: (e) => {
273-
e.preventDefault();
274-
auth.logout();
275-
},
276-
text: "Want to destroy the paper trail?",
277-
button_text: "Logout",
278-
icon: MdLogout,
279-
}}
280-
/>
281-
262+
return (
263+
<>
282264
<div className="dashboard-container">
283265
{awaitingResponse ? (
284266
<Spinner />
@@ -356,9 +338,7 @@ function AdminDashboard() {
356338
editPaper={(id) => setSearchParams({ edit: id.toString() })}
357339
/>
358340
)}
359-
</div>
360-
) : (
361-
<p>You are unauthenticated. This incident will be reported.</p>
341+
</>
362342
);
363343
}
364344

frontend/src/pages/AdminLayout.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { useEffect } from "react";
2+
import { OAUTH_LOGIN_URL, useAuthContext } from "../utils/auth";
3+
import { Header } from "../components/Common/Common";
4+
import { MdLogout } from "react-icons/md";
5+
import { Outlet } from "react-router-dom";
6+
7+
function AdminLayout() {
8+
const auth = useAuthContext();
9+
10+
useEffect(() => {
11+
if (!auth.isAuthenticated) {
12+
window.location.assign(OAUTH_LOGIN_URL);
13+
}
14+
}, []);
15+
16+
return auth.isAuthenticated ? (
17+
<div id="admin-dashboard">
18+
<Header
19+
title="Admin Dashboard"
20+
subtitle="Top secret documents - to be approved inside n-sided polygon shaped buildings only."
21+
link={{
22+
onClick: (e) => {
23+
e.preventDefault();
24+
auth.logout();
25+
},
26+
text: "Want to destroy the paper trail?",
27+
button_text: "Logout",
28+
icon: MdLogout,
29+
}}
30+
/>
31+
32+
<Outlet />
33+
</div>
34+
) : (
35+
<p>You are unauthenticated. This incident will be reported.</p>
36+
);
37+
}
38+
39+
export default AdminLayout;

frontend/src/pages/TrashPage.tsx

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,11 @@ function TrashPage() {
9595

9696

9797
useEffect(() => {
98-
if (!auth.isAuthenticated) {
99-
window.location.assign(OAUTH_LOGIN_URL);
100-
} else {
101-
fetchTrashedPapers();
102-
}
98+
fetchTrashedPapers();
10399
}, []);
104100

105-
return auth.isAuthenticated ? (
106-
<div id="admin-dashboard">
107-
<Header
108-
title="Admin Dashboard"
109-
subtitle="Top secret documents - to be approved inside n-sided polygon shaped buildings only."
110-
link={{
111-
onClick: (e) => {
112-
e.preventDefault();
113-
auth.logout();
114-
},
115-
text: "Want to destroy the paper trail?",
116-
button_text: "Logout",
117-
icon: MdLogout,
118-
}}
119-
/>
120-
101+
return (
102+
<div id="trash-page">
121103
<div className="dashboard-container">
122104
{awaitingResponse ? (
123105
<Spinner />
@@ -194,8 +176,6 @@ function TrashPage() {
194176
)}
195177
</div>
196178
</div>
197-
) : (
198-
<p>You are unauthenticated. This incident will be reported.</p>
199179
);
200180
}
201181

frontend/src/pages/styles/trash_page.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030
}
3131

32-
#admin-dashboard {
32+
#trash-page {
3333
display: flex;
3434
flex-direction: column;
3535
justify-items: center;
@@ -109,6 +109,7 @@
109109
color: inherit;
110110
font-family: inherit;
111111
font-size: inherit;
112+
cursor: pointer;
112113

113114
&.icon-btn {
114115
display: flex;
@@ -120,6 +121,10 @@
120121
background-color: $accent-color-darker;
121122
padding: 0.5rem;
122123
border-radius: 10px;
124+
125+
&:hover {
126+
background-color: $accent-color;
127+
}
123128
}
124129
}
125130
}

0 commit comments

Comments
 (0)