Skip to content

Commit 855d1ee

Browse files
feat: admin panel team view fixes
1 parent 507e294 commit 855d1ee

5 files changed

Lines changed: 265 additions & 191 deletions

File tree

src/models/submissionModel.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ export interface SubmissionInput {
88
files: string[];
99
round1Score: number;
1010
round1Judge: string;
11+
round1Comment: string;
1112
round2Score: number;
1213
round2Judge: string;
14+
round2Comment: string;
1315
round3Score: number;
1416
round3Judge: string;
17+
round3Comment: string;
1518
}
1619

1720
export interface SubmissionType extends SubmissionInput {
@@ -43,11 +46,32 @@ const submissionSchema = new mongoose.Schema({
4346
},
4447
files: [String],
4548
round1Score: Number,
46-
round1Judge: String,
49+
round1Judge: {
50+
type: String,
51+
default: '',
52+
},
53+
round1Comment: {
54+
type: String,
55+
default: '',
56+
},
4757
round2Score: Number,
48-
round2Judge: String,
58+
round2Judge: {
59+
type: String,
60+
default: '',
61+
},
62+
round2Comment: {
63+
type: String,
64+
default: '',
65+
},
4966
round3Score: Number,
50-
round3Judge: String,
67+
round3Judge: {
68+
type: String,
69+
default: '',
70+
},
71+
round3Comment: {
72+
type: String,
73+
default: '',
74+
},
5175
});
5276

5377
const Submission =

src/pages/hack/admin/team/[id].tsx

Lines changed: 103 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -6,94 +6,57 @@ import mongoose from 'mongoose';
66
import { TeamType } from '@/models/teamModel';
77
import Toaster from '@/utils/toaster';
88
import ViewSubmission from '@/sections/admin-page-sections/admin-view-submission';
9-
import EditSubmission from '@/sections/admin-page-sections/admin-edit-submission';
109
import Header from '@/components/common/header';
1110
import { useRouter } from 'next/router';
1211
import { GetServerSidePropsContext } from 'next';
1312
import getHandler from '@/handlers/getHandler';
1413
import patchHandler from '@/handlers/patchHandler';
15-
import InputField from '@/components/common/InputField';
1614
import { CURRENT_ROUND } from '@/constants';
15+
import CommentView from '@/sections/admin-page-sections/admin-view-comment';
16+
import CommentEdit from '@/sections/admin-page-sections/admin-edit-comment copy';
1717

1818
interface Props {
1919
id: string;
2020
}
21-
interface RoundType {
22-
round: string;
23-
checked: boolean;
24-
score: number;
25-
judge: string;
26-
}
2721

2822
const ProjectReviewPage = ({ id }: Props) => {
2923
const { data: session } = useSession();
3024

3125
const router = useRouter();
32-
// ROUND PASSING LOGIC
33-
const [rounds, setRounds] = useState<RoundType[]>([
34-
{ round: 'Round 1', checked: false, score: 0, judge: '' },
35-
{ round: 'Round 2', checked: false, score: 0, judge: '' },
36-
{ round: 'Round 3', checked: false, score: 0, judge: '' },
37-
]);
3826

39-
const handleCheckboxChange = (index: number) => {
40-
const updatedRounds = rounds.map((round, roundIndex) => {
41-
if (roundIndex < index) {
42-
return {
43-
...round,
44-
checked: true,
45-
};
46-
} else if (roundIndex === index) {
47-
return {
48-
...round,
49-
checked: !round.checked,
50-
};
51-
} else {
52-
return {
53-
...round,
54-
checked: false,
55-
};
56-
}
57-
});
58-
setRounds(updatedRounds);
59-
};
27+
const [comment, setComment] = useState('');
28+
29+
const [score, setScore] = useState(0);
6030

6131
const SaveRoundChangesHandler = async () => {
32+
if (score > 10) Toaster.error('Score cannot be more than 10');
6233
let formData = {};
63-
if (CURRENT_ROUND === 1) {
34+
35+
if (CURRENT_ROUND === 1)
6436
formData = {
65-
round1Score: rounds[0].score,
37+
round1Score: score,
38+
round1Comment: comment,
6639
round1Judge: session?.user.name,
6740
};
68-
} else if (CURRENT_ROUND === 2) {
41+
else if (CURRENT_ROUND === 2)
6942
formData = {
70-
round2Score: rounds[1].score,
43+
round2Score: score,
44+
round2Comment: comment,
7145
round2Judge: session?.user.name,
7246
};
73-
} else if (CURRENT_ROUND === 3) {
47+
else if (CURRENT_ROUND === 3)
7448
formData = {
75-
round3Score: rounds[2].score,
49+
round3Score: score,
50+
round3Comment: comment,
7651
round3Judge: session?.user.name,
7752
};
78-
}
7953

80-
const data = await patchHandler(
81-
`${process.env.NEXT_PUBLIC_BASE_URL}/api/admin/submission/${id}`,
82-
formData
83-
);
84-
};
54+
console.log(formData);
8555

86-
const handleScoreChange = (index: number, value: number) => {
87-
const updatedRounds = rounds.map((round, roundIndex) => {
88-
if (roundIndex === index) {
89-
return {
90-
...round,
91-
score: value,
92-
};
93-
}
94-
return round;
95-
});
96-
setRounds(updatedRounds);
56+
// const data = await patchHandler(
57+
// `${process.env.NEXT_PUBLIC_BASE_URL}/api/admin/submission/${id}`,
58+
// formData
59+
// );
9760
};
9861

9962
// FETCHING TEAM / PROJECT LOGIC
@@ -104,10 +67,6 @@ const ProjectReviewPage = ({ id }: Props) => {
10467
submission: new mongoose.Schema.Types.ObjectId(''),
10568
});
10669
const [loading, setLoading] = useState(true);
107-
const [changeTitle, setChangeTitle] = useState(false);
108-
const [newTitle, setNewTitle] = useState('');
109-
const [isSubmission, setIsSubmission] = useState(false);
110-
const [toggleEdit, setToggleEdit] = useState(0);
11170

11271
useEffect(() => {
11372
getHandler(`${process.env.NEXT_PUBLIC_BASE_URL}/api/admin/team/${id}`)
@@ -121,6 +80,7 @@ const ProjectReviewPage = ({ id }: Props) => {
12180
console.log(err);
12281
});
12382
}, []);
83+
12484
return (
12585
<>
12686
<Header />
@@ -190,42 +150,87 @@ const ProjectReviewPage = ({ id }: Props) => {
190150
</div>
191151
</div>
192152
{teamDetails.submission ? (
193-
<div className="flex md:flex-col gap-4 max-md:w-full max-md:justify-between pt-6">
194-
{rounds.map((round, index) => (
195-
<>
196-
<div
197-
key={index}
198-
className="text-xl py-1 flex justify-start items-center gap-x-2 font-spaceGrotesk"
199-
>
200-
{round.round}
201-
<label className="ml-2">
202-
<input
203-
type="checkbox"
204-
checked={round.checked}
205-
onChange={() =>
206-
handleCheckboxChange(
207-
index
208-
)
209-
}
210-
/>
211-
Checked
212-
</label>
213-
<div>- Score : </div>
214-
<InputField
215-
label=""
216-
value={round.score.toString()}
217-
type="number"
218-
canEdit={true}
219-
onChange={(value) =>
220-
handleScoreChange(
221-
index,
222-
Number(value)
223-
)
224-
}
225-
/>
226-
</div>
227-
</>
228-
))}
153+
<div className="flex flex-col gap-4 max-md:w-full max-md:justify-between pt-6">
154+
<div className="w-full flex flex-col pr-20 gap-12 max-md:pr-2">
155+
{CURRENT_ROUND === 1 ? (
156+
<CommentEdit
157+
score={score}
158+
setScore={setScore}
159+
comment={comment}
160+
setComment={setComment}
161+
/>
162+
) : (
163+
<>
164+
{CURRENT_ROUND === 2 ? (
165+
<>
166+
<CommentView
167+
roundNumber={1}
168+
score={9}
169+
judge={'someone'}
170+
comment={
171+
'iawjdhuihwaduahi'
172+
}
173+
/>
174+
<CommentEdit
175+
score={score}
176+
setScore={setScore}
177+
comment={comment}
178+
setComment={
179+
setComment
180+
}
181+
/>
182+
</>
183+
) : (
184+
<>
185+
{CURRENT_ROUND === 3 ? (
186+
<>
187+
<CommentView
188+
roundNumber={
189+
1
190+
}
191+
score={9}
192+
judge={
193+
'someone'
194+
}
195+
comment={
196+
'iawjdhuihwaduahi'
197+
}
198+
/>
199+
<CommentView
200+
roundNumber={
201+
1
202+
}
203+
score={9}
204+
judge={
205+
'someone'
206+
}
207+
comment={
208+
'iawjdhuihwaduahi'
209+
}
210+
/>
211+
<CommentEdit
212+
score={
213+
score
214+
}
215+
setScore={
216+
setScore
217+
}
218+
comment={
219+
comment
220+
}
221+
setComment={
222+
setComment
223+
}
224+
/>
225+
</>
226+
) : (
227+
<></>
228+
)}
229+
</>
230+
)}
231+
</>
232+
)}
233+
</div>
229234
<div
230235
onClick={() => {
231236
SaveRoundChangesHandler();
@@ -251,18 +256,9 @@ const ProjectReviewPage = ({ id }: Props) => {
251256
{/* STRONGLY SUGGESTED MAKE NEW DUPLICATE 2 COMPONENTS BELOW JUST FOR ADMIN PANEL SOLO PROJECT VIEW PAGE CUZ IT WILL HAVE A NEW CHECK KI EVEN SUPER USER CAN VIEW ALL */}
252257

253258
<div className="w-full lg:w-[50%] h-full">
254-
{/* {toggleEdit === 0 ? (
255-
<ViewSubmission
256-
id={id}
257-
toggleEdit={setToggleEdit}
258-
/>
259-
) : (
260-
<EditSubmission id={id} />
261-
)} */}
262259
{teamDetails.submission ? (
263260
<ViewSubmission
264261
id={teamDetails.submission._id}
265-
toggleEdit={setToggleEdit}
266262
/>
267263
) : (
268264
<></>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react';
2+
3+
interface Props {
4+
comment: string;
5+
setComment: (comment: string) => void;
6+
score: number;
7+
setScore: (score: number) => void;
8+
}
9+
10+
const CommentEdit = ({ comment, setComment, score, setScore }: Props) => {
11+
return (
12+
<div className="w-full flex flex-col gap-2">
13+
<div className="text-2xl font-bronson font-bold">
14+
Round 2 Details
15+
</div>
16+
17+
<div className="flex flex-col gap-4">
18+
<div className="flex items-center border-b-2 border-white py-2">
19+
<textarea
20+
className="appearance-none rounded-lg p-3 max-h-[25vh] min-h-[15vh] bg-[#2828287e] border-none w-full text-white leading-tight focus:outline-none"
21+
value={comment}
22+
onChange={(el) => {
23+
setComment(el.target.value.slice(0, 500));
24+
}}
25+
placeholder={'Comment'}
26+
/>
27+
</div>
28+
<div className="font-ibmMono font-extrabold text-lg flex gap-2">
29+
<div> Score: </div>
30+
<input
31+
className="text-black w-1/2"
32+
type="number"
33+
value={score}
34+
onChange={(el) => {
35+
const currValue = Number(el.target.value);
36+
37+
setScore(currValue);
38+
}}
39+
/>
40+
</div>
41+
</div>
42+
</div>
43+
);
44+
};
45+
46+
export default CommentEdit;

0 commit comments

Comments
 (0)