Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete Judge Assignment #208 #256

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/components/projectStatus/ProjectTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const columns = [
dataIndex: "deleteScore",
key: "deleteScore",
},
{
title: "Delete Judge",
dataIndex: "deleteJudge",
key: "deleteJudge",
},
];

type ProjectTableType = {
Expand Down
36 changes: 36 additions & 0 deletions src/components/projectStatus/ProjectTableContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ const ProjectTableContainer: React.FC<Props> = props => {
}
};

const deleteJudge = async (judgeName: string, project: Project) => {
const ballotIds = project.ballots
.filter((ballot: Ballot) => ballot.user.name === judgeName)
.map((ballot: Ballot) => ballot.id);

const ids = { ids: ballotIds };

try {
const response = await axios.delete(apiUrl(Service.EXPO, `/ballots/batch/delete`), { data: ids });

if (response.data.error) {
message.error(response.data.message, 2);
} else {
message.success(`Successfully deleted scores for judge ${judgeName}`, 2);
props.refetch();
}
} catch (error) {
console.error("Error deleting judge:", error);
message.error("Error: Please ask for help", 2);
}
};

const openModal = (values: any) => {
setModalState({
visible: true,
Expand Down Expand Up @@ -147,11 +169,24 @@ const ProjectTableContainer: React.FC<Props> = props => {
</Button>
);

const deleteJudgeButton = (
<Button
type="primary"
danger
onClick={() => {
deleteJudge(e[0], project);
}}
>
Delete Judge
</Button>
);

return {
judge: e[0],
total: e[1],
editScore: editButton,
deleteScore: deleteButton,
deleteJudge: deleteJudgeButton,
};
});

Expand All @@ -160,6 +195,7 @@ const ProjectTableContainer: React.FC<Props> = props => {
total: Math.round((total / newData.length) * 10) / 10,
editScore: <></>,
deleteScore: <></>,
deleteJudge: <></>,
});
return newData;
};
Expand Down