-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathadmin.js
56 lines (49 loc) · 1.44 KB
/
admin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { getSession } from 'next-auth/client';
import Head from 'next/head';
import PropTypes from 'prop-types';
import { Header, LoginMessage, QuestionsTable, NoAccess } from '../components';
import { Roles } from '../lib/constants';
export async function getServerSideProps(context) {
return { props: { session: await getSession(context) } };
}
/**
* The admin page allows administrators to manage and add new questions, via the QuestionsTable component.
* If the user is not logged in, they are prompted to login.
*
* All other users do not have access to this page.
*
* @param session the user's session object to decide what to display
* @param toggleTheme the global function to toggle the current theme
*/
function Manage({ session, toggleTheme }) {
if (!session) {
return (
<div>
<Header session={session} toggleTheme={toggleTheme} />
<LoginMessage />
</div>
);
}
return (
<div>
<Head>
<title>Manage</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<Header session={session} toggleTheme={toggleTheme} />
{session.user.roles.includes(Roles.USER_TYPE_ADMIN) ? (
<div>
<h3>Manage and add new questions</h3>
<QuestionsTable />
</div>
) : (
<NoAccess />
)}
</div>
);
}
Manage.propTypes = {
session: PropTypes.object.isRequired,
toggleTheme: PropTypes.func.isRequired,
};
export default Manage;