|
| 1 | +import { useCallback } from "react" |
| 2 | +import { |
| 3 | + AlertDialog, |
| 4 | + AlertDialogAction, |
| 5 | + AlertDialogCancel, |
| 6 | + AlertDialogContent, |
| 7 | + AlertDialogDescription, |
| 8 | + AlertDialogFooter, |
| 9 | + AlertDialogHeader, |
| 10 | + AlertDialogTitle, |
| 11 | + Button, |
| 12 | +} from "@/components/ui" |
| 13 | +import { vscode } from "@/utils/vscode" |
| 14 | +import { AlertDialogProps } from "@radix-ui/react-alert-dialog" |
| 15 | + |
| 16 | +interface BatchDeleteTaskDialogProps extends AlertDialogProps { |
| 17 | + taskIds: string[] |
| 18 | +} |
| 19 | + |
| 20 | +export const BatchDeleteTaskDialog = ({ taskIds, ...props }: BatchDeleteTaskDialogProps) => { |
| 21 | + const { onOpenChange } = props |
| 22 | + |
| 23 | + const onDelete = useCallback(() => { |
| 24 | + if (taskIds.length > 0) { |
| 25 | + vscode.postMessage({ type: "deleteMultipleTasksWithIds", ids: taskIds }) |
| 26 | + onOpenChange?.(false) |
| 27 | + } |
| 28 | + }, [taskIds, onOpenChange]) |
| 29 | + |
| 30 | + return ( |
| 31 | + <AlertDialog {...props}> |
| 32 | + <AlertDialogContent className="max-w-md"> |
| 33 | + <AlertDialogHeader> |
| 34 | + <AlertDialogTitle>Delete Tasks</AlertDialogTitle> |
| 35 | + <AlertDialogDescription className="text-vscode-foreground"> |
| 36 | + <div className="mb-2"> |
| 37 | + Are you sure you want to delete <strong>{taskIds.length}</strong> selected tasks? |
| 38 | + </div> |
| 39 | + <div className="text-vscode-editor-foreground bg-vscode-editor-background p-2 rounded text-sm"> |
| 40 | + This action cannot be undone. All selected tasks will be permanently deleted. |
| 41 | + </div> |
| 42 | + </AlertDialogDescription> |
| 43 | + </AlertDialogHeader> |
| 44 | + <AlertDialogFooter> |
| 45 | + <AlertDialogCancel asChild> |
| 46 | + <Button variant="secondary">Cancel</Button> |
| 47 | + </AlertDialogCancel> |
| 48 | + <AlertDialogAction asChild> |
| 49 | + <Button variant="destructive" onClick={onDelete}> |
| 50 | + <span className="codicon codicon-trash mr-1"></span> |
| 51 | + Delete {taskIds.length} items |
| 52 | + </Button> |
| 53 | + </AlertDialogAction> |
| 54 | + </AlertDialogFooter> |
| 55 | + </AlertDialogContent> |
| 56 | + </AlertDialog> |
| 57 | + ) |
| 58 | +} |
0 commit comments