Skip to content

Commit 0f5fc61

Browse files
committed
Change task deletion confirmation alert
1 parent cfcf620 commit 0f5fc61

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/store/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,14 @@ export default createStore({
239239
const index = state.todos.findIndex(
240240
(todo: { newId: number }) => todo.newId === payload
241241
);
242-
const deleteTask: boolean = confirm(
243-
`Do you want to delete the task ${state.todos[index].task}?\nThis action cannot be undone.`
244-
);
245-
if (deleteTask) {
242+
let deleteTask;
243+
if (!state.todos[index].completed) {
244+
//don't ask for confirmation when one-time task is completed
245+
deleteTask = confirm(
246+
`Do you want to delete the task ${state.todos[index].task}?\nThis action cannot be undone.`
247+
) as boolean; //ask user to confirm task deletion
248+
}
249+
if (deleteTask || state.todos[index].completed) {
246250
state.todos.splice(index, 1); //delete task item
247251
}
248252
},

0 commit comments

Comments
 (0)