Skip to content
This repository was archived by the owner on Mar 21, 2026. It is now read-only.

Commit 3673e4e

Browse files
committed
adds task delete functionality
1 parent 1979b3c commit 3673e4e

5 files changed

Lines changed: 59 additions & 10 deletions

File tree

server/controllers/tasksController.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ const tasksController = {
123123
});
124124
}
125125
},
126+
deleteTask: async (req: Request, res: Response, next: NextFunction) => {
127+
try {
128+
const deletedTask = await Card.findOneAndDelete({
129+
_id: req.params.taskId,
130+
});
131+
res.locals.task = deletedTask;
132+
return next();
133+
} catch (err) {
134+
// pass error through to global error handler
135+
return next({
136+
log: `tasksController.deleteTask ERROR: ${err}`,
137+
status: 500,
138+
message: { err: "Error deleting Task" },
139+
});
140+
}
141+
},
126142
};
127143

128144
export default tasksController;

server/routes/tasksRouter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,14 @@ router.post(
2828
}
2929
);
3030

31+
// route for deleting a task card
32+
router.delete(
33+
"/delete/:taskId",
34+
tasksController.deleteTask,
35+
tasksController.pullTask,
36+
(_req: Request, res: Response) => {
37+
return res.status(200).json();
38+
}
39+
);
40+
3141
export default router;

src/components/EditTaskModal.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,27 @@ const EditTaskModal = ({
8181
setFormData((prevData: TaskFormState) => ({ ...prevData, [name]: value }));
8282
};
8383

84+
const handleDeleteTask = () => {
85+
const fetchDeleteTask = async () => {
86+
const response: Response = await fetch(`/tasks/delete/${task._id}`, {
87+
method: "DELETE",
88+
});
89+
if (response.status === 200) {
90+
setBoardState((prevState: BoardState) => {
91+
const column = [...prevState[startColumn]];
92+
const idx = column.indexOf(task);
93+
column.splice(idx, 1);
94+
return {
95+
...prevState,
96+
[startColumn]: column,
97+
};
98+
});
99+
}
100+
};
101+
fetchDeleteTask().catch(console.error);
102+
setEditingTask(null);
103+
};
104+
84105
return createPortal(
85106
<div className="modal-overlay">
86107
<div className="modal">
@@ -154,6 +175,9 @@ const EditTaskModal = ({
154175
>
155176
Cancel
156177
</button>
178+
<button className="modal-delete" onClick={handleDeleteTask}>
179+
Delete
180+
</button>
157181
</div>
158182
</form>
159183
</div>

src/scss/mainContainer.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
.board-title {
99
height: 5%;
1010
margin: 0;
11+
margin-top: 10px;
1112
}
1213
}

src/scss/modal.scss

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@
5858
padding: 10px 20px;
5959
border: none;
6060
border-radius: 5px;
61-
}
62-
63-
.modal-submit {
64-
background-color: #c3ff0e;
6561
width: 100px;
6662
cursor: pointer;
6763
transition: all 0.3s ease-in-out;
@@ -73,14 +69,16 @@
7369
}
7470
}
7571

72+
.modal-submit {
73+
background-color: #c3ff0e;
74+
}
75+
7676
.modal-cancel {
7777
background-color: goldenrod;
78-
width: 100px;
79-
cursor: pointer;
80-
transition: all 0.3s ease-in-out;
81-
&:hover {
82-
transform: scale(1.1);
83-
}
78+
}
79+
80+
.modal-delete {
81+
background-color: rgb(206, 61, 61);
8482
}
8583
}
8684
}

0 commit comments

Comments
 (0)