"use client"; import { useState } from "react"; import { X, Trash2 } from "lucide-react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { Popover, PopoverTrigger, PopoverContent, } from "@/components/ui/popover"; import type { UpdateIssueRequest } from "@/shared/types"; import { ALL_STATUSES, STATUS_CONFIG, PRIORITY_ORDER, PRIORITY_CONFIG } from "@/features/issues/config"; import { useIssueSelectionStore } from "@/features/issues/stores/selection-store"; import { useBatchUpdateIssues, useBatchDeleteIssues } from "@core/issues/mutations"; import { StatusIcon } from "./status-icon"; import { PriorityIcon } from "./priority-icon"; import { AssigneePicker } from "./pickers"; export function BatchActionToolbar() { const selectedIds = useIssueSelectionStore((s) => s.selectedIds); const clear = useIssueSelectionStore((s) => s.clear); const count = selectedIds.size; const [statusOpen, setStatusOpen] = useState(false); const [priorityOpen, setPriorityOpen] = useState(false); const [assigneeOpen, setAssigneeOpen] = useState(false); const [deleteOpen, setDeleteOpen] = useState(false); const batchUpdate = useBatchUpdateIssues(); const batchDelete = useBatchDeleteIssues(); const loading = batchUpdate.isPending || batchDelete.isPending; if (count === 0) return null; const ids = Array.from(selectedIds); const handleBatchUpdate = async (updates: Partial) => { try { await batchUpdate.mutateAsync({ ids, updates }); toast.success(`Updated ${count} issue${count > 1 ? "s" : ""}`); } catch { toast.error("Failed to update issues"); } }; const handleBatchDelete = async () => { try { await batchDelete.mutateAsync(ids); clear(); toast.success(`Deleted ${count} issue${count > 1 ? "s" : ""}`); } catch { toast.error("Failed to delete issues"); } finally { setDeleteOpen(false); } }; return ( <>
{count} selected
{/* Status */} } > Status {ALL_STATUSES.map((s) => { const cfg = STATUS_CONFIG[s]; return ( ); })} {/* Priority */} } > Priority {PRIORITY_ORDER.map((p) => { const cfg = PRIORITY_CONFIG[p]; return ( ); })} {/* Assignee */} } trigger="Assignee" align="center" /> {/* Delete */}
Delete {count} issue{count > 1 ? "s" : ""}? This action cannot be undone. This will permanently delete the selected issue{count > 1 ? "s" : ""} and all associated data. Cancel Delete ); }