-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJudgingCardsContainer.tsx
More file actions
160 lines (146 loc) · 4.53 KB
/
JudgingCardsContainer.tsx
File metadata and controls
160 lines (146 loc) · 4.53 KB
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
import React, { useEffect, useState } from "react";
import axios from "axios";
import { Button, Popconfirm, message } from "antd";
import { apiUrl, Service } from "@hex-labs/core";
import { Criteria } from "../../types/Criteria";
import { handleAxiosError } from "../../util/util";
import CriteriaCardContainer from "./CriteriaCardContainer";
interface Props {
data: any;
}
const JudgingCardsContainer: React.FC<Props> = props => {
const [projectScores, setProjectScores] = useState({});
const [categoryToCriteriaMapping, setCategoryToCriteriaMapping] = useState({});
useEffect(() => {
if (!props.data[0] || props.data[0].length === 0) {
return;
}
const newCriteriaArray: any[] = [];
const newCategoryToCriteriaMapping: any = {};
props.data[0].categories.forEach((category: any) => {
category.criterias.forEach((criteria: any) => {
newCriteriaArray.push(criteria);
if (newCategoryToCriteriaMapping[category.name]) {
newCategoryToCriteriaMapping[category.name].push(criteria);
} else {
newCategoryToCriteriaMapping[category.name] = [criteria];
}
});
});
const mapping: any = {};
newCriteriaArray.forEach((criteria: Criteria) => {
mapping[criteria.id] = criteria.minScore;
});
setProjectScores(mapping);
setCategoryToCriteriaMapping(newCategoryToCriteriaMapping);
}, [props.data[0], setProjectScores, setCategoryToCriteriaMapping]);
const onSubmit = async () => {
const hide = message.loading("Loading...", 0);
const ballots: any = {
criterium: projectScores,
round: props.data[0].round,
projectId: props.data[0].id,
userId: props.data[0].assignment.userId,
};
try {
await axios.post(apiUrl(Service.EXPO, "/ballots"), ballots);
await axios.patch(apiUrl(Service.EXPO, `/assignments/${props.data[0].assignment.id}`), {
data: { status: "COMPLETED" },
});
hide();
// TODO: Fix modal showing next table to go to
// Modal.info({
// title: "Notification",
// okText: "I'm Here",
// content: props.data[1],
// onOk() {
// window.location.reload();
// },
// });
window.location.reload();
} catch (err: any) {
hide();
handleAxiosError(err);
}
};
const onSkip = async () => {
const hide = message.loading("Loading...", 0);
try {
await axios.patch(apiUrl(Service.EXPO, `/assignments/${props.data[0].assignment.id}`), {
data: { status: "SKIPPED" },
});
hide();
// TODO: Fix modal showing next table to go to
// Modal.info({
// title: "Notification",
// okText: "I'm Here",
// content: props.data[1],
// onOk() {
// window.location.reload();
// },
// });
window.location.reload();
} catch (err: any) {
hide();
handleAxiosError(err);
}
};
const changeScore = (value: number, id: number) => {
const objectValue = {
...projectScores,
[id]: value,
};
setProjectScores(objectValue);
};
const renderCategoryContainers = (cToCMapping: any) => {
const categoryContainerArr = [];
for (const key of Object.keys(cToCMapping)) {
categoryContainerArr.push(
<CriteriaCardContainer
criteriaArray={cToCMapping[key]}
changeScore={changeScore}
categoryName={key}
projectScores={projectScores}
/>
);
}
return categoryContainerArr;
};
return (
<>
{renderCategoryContainers(categoryToCriteriaMapping)}
<div style={{ marginTop: "15px" }}>
<Popconfirm
placement="right"
title="Are you sure you want to submit these scores?"
onConfirm={onSubmit}
okText="Yes"
cancelText="No"
>
<Button type="primary" style={{ marginRight: "10px" }}>
Submit
</Button>
</Popconfirm>
<Popconfirm
placement="right"
title="Are you sure that the project is not there?"
onConfirm={onSkip}
okText="Yes"
cancelText="No"
>
<Button style={{ marginRight: "10px" }}>This Project Is Not Here</Button>
</Popconfirm>
<Popconfirm
placement="right"
title="Are you sure you want to skip this project?"
onConfirm={onSkip}
okText="Yes"
cancelText="No"
>
<Button>Skip Project</Button>
</Popconfirm>
</div>
</>
);
};
export default JudgingCardsContainer;