ENCOA-216: Added a button to remove inactive assignees
This commit is contained in:
@@ -42,7 +42,7 @@ async function DELETE(req: NextApiRequest, res: NextApiResponse) {
|
||||
async function PATCH(req: NextApiRequest, res: NextApiResponse) {
|
||||
const {id} = req.query;
|
||||
|
||||
await db.collection("assignments").updateOne({id: id as string}, {$set: {assigner: req.session.user?.id, ...req.body}});
|
||||
await db.collection("assignments").updateOne({id: id as string}, {$set: {...req.body}});
|
||||
|
||||
res.status(200).json({ok: true});
|
||||
}
|
||||
|
||||
@@ -298,6 +298,25 @@ export default function AssignmentView({user, users, entity, assignment}: Props)
|
||||
return false;
|
||||
};
|
||||
|
||||
const removeInactiveAssignees = () => {
|
||||
const mappedResults = mapBy(assignment.results, 'user')
|
||||
const inactiveAssignees = assignment.assignees.filter((a) => !mappedResults.includes(a))
|
||||
const activeAssignees = assignment.assignees.filter((a) => mappedResults.includes(a))
|
||||
|
||||
if (!confirm(`Are you sure you want to remove ${inactiveAssignees.length} assignees?`)) return
|
||||
|
||||
axios
|
||||
.patch(`/api/assignments/${assignment.id}`, {assignees: activeAssignees})
|
||||
.then(() => {
|
||||
toast.success(`The assignment "${assignment.name}" has been updated successfully!`);
|
||||
router.replace(router.asPath);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e);
|
||||
toast.error("Something went wrong, please try again later!");
|
||||
});
|
||||
}
|
||||
|
||||
const copyLink = async () => {
|
||||
const origin = window.location.origin
|
||||
await navigator.clipboard.writeText(`${origin}/exam?assignment=${assignment.id}`)
|
||||
@@ -360,6 +379,11 @@ export default function AssignmentView({user, users, entity, assignment}: Props)
|
||||
<span>Assigner: {getUserName(users.find((x) => x.id === assignment?.assigner))}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{assignment.assignees.length !== 0 && assignment.results.length !== assignment.assignees.length && (
|
||||
<Button onClick={removeInactiveAssignees} variant="outline">Remove Inactive Assignees</Button>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-xl font-bold">Average Scores</span>
|
||||
<div className="-md:mt-2 flex w-full items-center gap-4">
|
||||
|
||||
Reference in New Issue
Block a user