feat: add undo toasts for task and note deletions

- Capture deleted item before DELETE call
- Show sonner toast with Undo action button
- On Undo, POST to recreate the item with original data
- Applied to tasks-list-view, task-detail-panel, and notes page
This commit is contained in:
2026-07-29 19:26:05 +00:00
parent fb68009c23
commit 7ced6f2bf2
3 changed files with 81 additions and 3 deletions
+27 -1
View File
@@ -284,12 +284,38 @@ export function TasksListView({
onClick={async () => {
if (!deleteId || !domainId) return;
setDeleting(true);
const deletedTask = tasks.find(t => t.id === deleteId);
try {
const res = await fetch(`/api/domains/${domainId}/tasks/${deleteId}`, { method: 'DELETE' });
if (!res.ok) throw new Error();
toast.success('Task deleted');
setDeleteId(null);
fetchTasks();
toast.success('Task deleted', {
action: {
label: 'Undo',
onClick: async () => {
if (!deletedTask) return;
try {
await fetch(`/api/domains/${domainId}/tasks`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
title: deletedTask.title,
description: deletedTask.description,
status: deletedTask.status,
priority: deletedTask.priority,
dueDate: deletedTask.dueDate,
projectId: deletedTask.projectId,
}),
});
fetchTasks();
toast.success('Task restored');
} catch {
toast.error('Unable to restore task');
}
},
},
});
} catch {
toast.error('Unable to delete task');
} finally {