This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
passJudgment.tsx
399 lines (371 loc) · 11.7 KB
/
passJudgment.tsx
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
import React, { useEffect, useRef, useState } from "react";
import styled from "styled-components";
import PacmanLoader from "react-spinners/PacmanLoader";
import { handleLoginRedirect, getProfile, getJudgeList } from "../../lib";
import { Head, Navbar, Footer, Select } from "../../components";
import {
Background,
Container,
Button,
Flex,
Column,
Form,
} from "../../styles";
import { updateJudging } from "../../lib/judging";
const passJudgment = ({ profile, propJudgeList }) => {
const [closestTime, setClosestTime] = useState(null);
const [judgeList, setJudgeList] = useState(propJudgeList);
const [item_refs, setItemRefs] = useState(
judgeList && judgeList.length > 0
? [judgeList.map((item) => useRef(null))][0]
: []
);
const [loading, setLoading] = useState(false);
const [submitted, setSubmitted] = useState(false);
const form = useRef(null);
const resortJudgeList = (newJudgeList) => {
// * Find current judging item
var closest = null;
newJudgeList.map(
(item) => {
let item_date = new Date(
new Date(Date.parse(item.startsAt)).getTime() + 8 * 60 * 60 * 1000
).getTime();
if (item_date - new Date().getTime() > 0 && !item.judged) {
if (closest === null) closest = item;
let closest_date = new Date(
new Date(Date.parse(closest.startsAt)).getTime() +
8 * 60 * 60 * 1000
).getTime();
closest =
item_date - new Date().getTime() > 0 &&
item_date - new Date().getTime() <
closest_date - new Date().getTime()
? item
: closest;
}
},
[newJudgeList, closestTime]
);
setClosestTime(closest);
if (closest !== null) {
item_refs[newJudgeList.indexOf(closest)].current.scrollIntoView();
if (typeof window !== "undefined") {
window.scrollTo({ top: 0 });
setTimeout(() => window.scrollTo({ top: 0 }), 500);
}
} else if (newJudgeList.length > 0) {
item_refs[newJudgeList.length - 1].current.scrollIntoView();
if (typeof window !== "undefined") {
window.scrollTo({ top: 0 });
setTimeout(() => window.scrollTo({ top: 0 }), 500);
}
}
};
useEffect(() => {
resortJudgeList(judgeList);
}, []);
const handleJudgment = async (e) => {
e.preventDefault();
setLoading(true);
if (closestTime !== null) {
await updateJudging(
form.current.score.value,
closestTime.id,
form.current.vertical.value,
form.current.notes.value,
form.current.sponsor.value
);
let new_judge_list = await getJudgeList(null);
setJudgeList(new_judge_list);
resortJudgeList(new_judge_list);
}
setTimeout(() => {
setLoading(false);
}, 1000);
};
return (
<>
<Head title="HackSC Odyssey - Application" />
<Navbar
loggedIn
admin
superadmin={profile.role === "superadmin"}
activePage="/judgingManager"
/>
<Background padding="2rem">
<Container>
<PaddedTitle>Pass Judgment</PaddedTitle>
<Flex
direction="row"
justify="space-between"
style={{ flexWrap: "wrap" }}
>
<Column flexBasis={30} style={{ padding: "0 0 2rem 0" }}>
<CardContainer>
{/* <Flex direction="column" style={{ flexWrap: "wrap" }}> */}
{judgeList && judgeList.length > 0 ? (
<>
{judgeList.map((item) => (
<TimeCard
ref={item_refs[judgeList.indexOf(item)]}
key={Object.entries(item).toString()}
greyed={
item.judged ||
new Date(
new Date(Date.parse(item.startsAt)).getTime() +
8 * 60 * 60 * 1000
).getTime() -
new Date().getTime() <
0
}
primary={
!item.judged && closestTime
? closestTime.id === item.id
: false
}
>
<TimeCardLabel>
{new Date(
new Date(Date.parse(item.startsAt)).getTime() +
8 * 60 * 60 * 1000
).toLocaleString()}
</TimeCardLabel>
<TimeCardTeamName>{item.team.name}</TimeCardTeamName>
<div style={{ padding: "0 0 1rem 0" }}>
<p>Team Members:</p>
<ul style={{ padding: "0 0 0 1rem" }}>
{item.teammates.map((teammate) => (
<li key={Object.entries(teammate).toString()}>
- {teammate.firstName} {teammate.lastName}
</li>
))}
</ul>
</div>
<TimeCardLink>
{item.zoomLink
? item.zoomLink
: "This team has not been assigned a zoom link. Please reach out to the organizers."}
{/*
// TODO: Add Input for judge to enter link for zoom???
// TODO: How do we assign judges zoom links?
*/}
</TimeCardLink>
</TimeCard>
))}
</>
) : (
<PaddedTitle>No teams to judge now.</PaddedTitle>
)}
{/* </Flex> */}
</CardContainer>
</Column>
<Column flexBasis={65} style={{ padding: "0 0 2rem 0" }}>
<Cell style={{ padding: "20px" }}>
<Form ref={form} onSubmit={handleJudgment}>
<JudgeField>
<JudgeFieldLabel>Vertical</JudgeFieldLabel>
<JudgeFieldSelectInput
placeholder="Vertical"
id="verticalSelect"
name="vertical"
>
<option value="person">Person</option>
<option value="team">Team</option>
<option value="customer">Customer</option>
<option value="device">Device</option>
</JudgeFieldSelectInput>
</JudgeField>
<JudgeField>
<JudgeFieldLabel>Sponsor</JudgeFieldLabel>
<JudgeFieldSelectInput name="sponsor" placeholder="Sponsor">
<option value="sponsor1">Sponsor 1</option>
<option value="sponsor2">Sponsor 2</option>
</JudgeFieldSelectInput>
</JudgeField>
<JudgeField>
<JudgeFieldLabel>Notes</JudgeFieldLabel>
<JudgeFieldTextArea
name="notes"
placeholder="Write notes here..."
></JudgeFieldTextArea>
</JudgeField>
<JudgeField>
<JudgeFieldLabel>Score</JudgeFieldLabel>
<JudgeFieldSelectInput
name="score"
placeholder="Score"
id="scoreSelect"
>
{[...new Array(11).keys()].map((i) => (
<option key={`${i}`} value={`${i}`}>
{i}
</option>
))}
</JudgeFieldSelectInput>
<p style={{ marginTop: "4px", fontSize: "14px" }}>
For unsubmitted projects and/or judging mishaps, enter a
score of 0 and hit up engineering slack channel:
#2021-engineering.
</p>
</JudgeField>
{loading ? (
<PaddedFlex>
<PacmanLoader size={20} color={"#FF8379"} />
</PaddedFlex>
) : (
<FullButton type={"submit"} onClick={handleJudgment}>
Submit
</FullButton>
)}
</Form>
</Cell>
</Column>
</Flex>
</Container>
</Background>
<Footer />
</>
);
};
passJudgment.getInitialProps = async (ctx) => {
const { req } = ctx;
const profile = await getProfile(req);
const propJudgeList = await getJudgeList(req);
// Null profile means user is not logged in or user does not have enough rights
if (
!profile ||
!(
profile.role == "admin" ||
profile.role == "judge" ||
profile.role == "superadmin"
)
) {
handleLoginRedirect(req);
}
return { profile, propJudgeList };
};
const CardContainer = styled.div`
width: 100%;
max-height: 63vh;
flex: 1 1 auto;
border: 1px solid #cfcfcf;
border-radius: 4px;
padding: 32px;
box-sizing: border-box;
overflow-y: scroll;
`;
const PaddedFlex = styled(Flex)`
margin: auto;
display: flex;
min-height: 3rem;
justify-content: center;
padding: 1rem;
`;
const PaddedTitle = styled.h1`
padding: 1rem 0 2rem 0;
`;
const Cell = styled.div`
display: inline-block;
padding: 10px 20px;
background: #ffffff;
border-radius: 8px;
font-size: 16px;
`;
const SmallCell = styled.div`
padding: 12px 1px;
margin: 0px 1px;
background: #ffffff;
border-radius: 8px;
border: 1px solid #b2b2b2;
min-width: 39px;
display: inline-block;
text-align: center;
font-size: 16px;
`;
const Input = styled.input`
border-radius: 8px;
border: 1px solid #b2b2b2;
padding: 12px 16px;
font-weight: 300;
color: ${({ theme }) => theme.colors.black};
font-size: 16px;
width: 100%;
box-sizing: border-box;
`;
const FullButton = styled(Button)`
width: 100%;
text-align: center;
`;
type TimeCardType = {
primary?: boolean;
greyed?: boolean;
};
const TimeCard = styled.div<TimeCardType>`
margin-bottom: 20px;
padding: 20px;
background-color: white;
border-radius: 4px;
border: 2px solid;
opacity: ${(props) => (props.greyed ? "50%" : "100%")};
border-color: ${(props) => (props.primary ? "#FF8379" : "white")};
`;
const TimeCardLabel = styled.label`
margin-bottom: 20px;
color: #757575;
font-weight: 600;
font-size: 16px;
text-indent: 1em;
&::before {
content: "🕐 ";
padding-right: 4px;
}
`;
const TimeCardTeamName = styled.h2`
margin-bottom: 16px;
margin-top: 12px;
padding: 0;
`;
const TimeCardTeamList = styled.p`
margin-bottom: 10px;
`;
const TimeCardLink = styled.a`
font-size: 16px;
`;
const JudgeField = styled.div`
margin-bottom: 20px;
width: 100%;
`;
const JudgeFieldLabel = styled.label`
display: block;
margin-bottom: 4px;
`;
const JudgeFieldTextInput = styled(Input)`
width: 100%;
padding: 10px 0px 10px 10px;
box-sizing: border-box;
background-color: #f8f8f8;
border: 2px solid #e5e5e5;
border-radius: 4px;
font-size: 16px;
`;
const JudgeFieldTextArea = styled.textarea`
width: 100%;
padding: 10px 0px 10px 10px;
box-sizing: border-box;
background-color: #white;
border: 2px solid #e5e5e5;
border-radius: 4px;
height: 150px;
font-size: 16px;
font-family: Arial;
`;
const JudgeFieldSelectInput = styled.select`
width: 100%;
padding: 10px 0px 10px 10px;
background-color: #f8f8f8;
border: 2px solid #e5e5e5;
border-radius: 4px;
font-size: 16px;
`;
export default passJudgment;