This repository was archived by the owner on Mar 21, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
128144export default tasksController ;
Original file line number Diff line number Diff 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+
3141export default router ;
Original file line number Diff line number Diff 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 >
Original file line number Diff line number Diff line change 88 .board-title {
99 height : 5% ;
1010 margin : 0 ;
11+ margin-top : 10px ;
1112 }
1213}
Original file line number Diff line number Diff line change 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 ;
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 }
You can’t perform that action at this time.
0 commit comments