Skip to content

Commit 6bf0943

Browse files
Hide elements if not admin
1 parent ed7ac4d commit 6bf0943

File tree

2 files changed

+115
-109
lines changed

2 files changed

+115
-109
lines changed

apps/frontend/src/app/page.tsx

Lines changed: 112 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
import Link from "next/link";
4343
import TextArea from "antd/es/input/TextArea";
4444
import { title } from "process";
45-
import { isAuthenticated } from "@/utils/Auth";
45+
import { isAuthenticated, isAdmin } from "@/utils/Auth";
4646
import { redirect } from 'next/navigation';
4747

4848
/**
@@ -74,7 +74,7 @@ function DeleteModal({
7474
onOk={okHandler}
7575
onCancel={cancelHandler}
7676
confirmLoading={isDeleting}
77-
okButtonProps={{ danger: true }}
77+
okButtonProps={{ danger: true }}
7878
cancelButtonProps={{ disabled: isDeleting }}
7979
>
8080
<p>{text}</p>
@@ -304,7 +304,6 @@ export default function Home() {
304304
dataIndex: "id",
305305
render: (_: number, question: Question, index: number) => (
306306
<div>
307-
{/* TODO (Sean): Include Logic to handle retrieving of editable data here and display in a modal component */}
308307
<Modal
309308
title="Edit Problem"
310309
open={isEditModalOpen && isEditModalOpen[index]}
@@ -399,11 +398,14 @@ export default function Home() {
399398
</Form.Item>
400399
</Form>
401400
</Modal>
402-
<Button
403-
className="edit-button"
404-
icon={<EditOutlined />}
405-
onClick={() => handleEditClick(index, question)}
406-
></Button>
401+
{
402+
isAdmin &&
403+
<Button
404+
className="edit-button"
405+
icon={<EditOutlined />}
406+
onClick={() => handleEditClick(index, question)}
407+
></Button>
408+
}
407409
{/* TODO (Ryan): Include Pop-up confirmation for delete when clicked and link to delete API --> can also explore success notification or look into react-toast*/}
408410
<Button
409411
className="delete-button"
@@ -493,115 +495,117 @@ export default function Home() {
493495
<div className="content-card">
494496
<div className="content-row-1">
495497
<div className="content-title">Problems</div>
496-
<div className="create-button">
497-
{/* TODO (Sean): Launch a popup modal that links to the backend api to create a new entry in db, --> look into success/error notification/react toast */}
498-
<Button
499-
type="primary"
500-
icon={<PlusCircleOutlined />}
501-
onClick={showNewProblemModal}
502-
>
503-
Create New Problem
504-
</Button>
505-
<Modal
506-
title="Create New Problem"
507-
open={isNewProblemModalOpen}
508-
// onOk={() => setIsNewProblemModelOpen(false)} // Replace with handleSubmit
509-
onCancel={() => setIsNewProblemModelOpen(false)}
510-
footer={null}
511-
width={600}
512-
>
513-
<Form
514-
name="create-form"
515-
{...layout}
516-
form={form}
517-
onFinish={(values) => {
518-
handleCreateQuestion(values);
519-
}}
498+
{
499+
isAdmin &&
500+
<div className="create-button">
501+
<Button
502+
type="primary"
503+
icon={<PlusCircleOutlined />}
504+
onClick={showNewProblemModal}
520505
>
521-
<Form.Item
522-
name="title"
523-
label="Title"
524-
rules={[
525-
{
526-
required: true,
527-
message: "Please enter question title!",
528-
},
529-
]}
530-
>
531-
<Input name="title" />
532-
</Form.Item>
533-
<Form.Item
534-
name="description"
535-
label="Description"
536-
rules={[
537-
{
538-
required: true,
539-
message: "Please enter question description!",
540-
},
541-
]}
542-
>
543-
<TextArea name="description" />
544-
</Form.Item>
545-
<Form.Item
546-
name="complexity"
547-
label="Complexity"
548-
rules={[
549-
{
550-
required: true,
551-
message: "Please select a complexity!",
552-
},
553-
]}
506+
Create New Problem
507+
</Button>
508+
<Modal
509+
title="Create New Problem"
510+
open={isNewProblemModalOpen}
511+
// onOk={() => setIsNewProblemModelOpen(false)} // Replace with handleSubmit
512+
onCancel={() => setIsNewProblemModelOpen(false)}
513+
footer={null}
514+
width={600}
515+
>
516+
<Form
517+
name="create-form"
518+
{...layout}
519+
form={form}
520+
onFinish={(values) => {
521+
handleCreateQuestion(values);
522+
}}
554523
>
555-
<Select
556-
options={[
524+
<Form.Item
525+
name="title"
526+
label="Title"
527+
rules={[
557528
{
558-
label: "Easy",
559-
value: "easy",
529+
required: true,
530+
message: "Please enter question title!",
560531
},
532+
]}
533+
>
534+
<Input name="title" />
535+
</Form.Item>
536+
<Form.Item
537+
name="description"
538+
label="Description"
539+
rules={[
561540
{
562-
label: "Medium",
563-
value: "medium",
541+
required: true,
542+
message: "Please enter question description!",
564543
},
544+
]}
545+
>
546+
<TextArea name="description" />
547+
</Form.Item>
548+
<Form.Item
549+
name="complexity"
550+
label="Complexity"
551+
rules={[
565552
{
566-
label: "Hard",
567-
value: "hard",
553+
required: true,
554+
message: "Please select a complexity!",
568555
},
569556
]}
570-
onChange={(value) =>
571-
form.setFieldValue("complexity", value)
572-
}
573-
allowClear
574-
/>
575-
</Form.Item>
576-
<Form.Item
577-
name="categories"
578-
label="Categories"
579-
rules={[
580-
{
581-
required: true,
582-
message: "Please select the relevant categories!",
583-
},
584-
]}
585-
>
586-
<Select
587-
mode="multiple"
588-
options={CategoriesOption}
589-
onChange={(value) =>
590-
form.setFieldValue("categories", value)
591-
}
592-
allowClear
593-
/>
594-
</Form.Item>
595-
<Form.Item
596-
style={{ display: "flex", justifyContent: "flex-end" }}
597-
>
598-
<Button type="primary" htmlType="submit">
599-
Create
600-
</Button>
601-
</Form.Item>
602-
</Form>
603-
</Modal>
604-
</div>
557+
>
558+
<Select
559+
options={[
560+
{
561+
label: "Easy",
562+
value: "easy",
563+
},
564+
{
565+
label: "Medium",
566+
value: "medium",
567+
},
568+
{
569+
label: "Hard",
570+
value: "hard",
571+
},
572+
]}
573+
onChange={(value) =>
574+
form.setFieldValue("complexity", value)
575+
}
576+
allowClear
577+
/>
578+
</Form.Item>
579+
<Form.Item
580+
name="categories"
581+
label="Categories"
582+
rules={[
583+
{
584+
required: true,
585+
message: "Please select the relevant categories!",
586+
},
587+
]}
588+
>
589+
<Select
590+
mode="multiple"
591+
options={CategoriesOption}
592+
onChange={(value) =>
593+
form.setFieldValue("categories", value)
594+
}
595+
allowClear
596+
/>
597+
</Form.Item>
598+
<Form.Item
599+
style={{ display: "flex", justifyContent: "flex-end" }}
600+
>
601+
<Button type="primary" htmlType="submit">
602+
Create
603+
</Button>
604+
</Form.Item>
605+
</Form>
606+
</Modal>
607+
</div>
608+
}
605609
</div>
606610
{/* TODO (Ben/Ryan): Include and link search & filter parameters */}
607611
<div className="content-filter">

apps/frontend/src/utils/Auth.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export const isAuthenticated = true;
1+
export const isAuthenticated = true;
2+
export const isUser = false; // i think we can delete this if we are not using
3+
export const isAdmin = true;

0 commit comments

Comments
 (0)