Added delete version
Deploy / deploy (push) Successful in 2m28s

This commit is contained in:
twotalesanimation
2026-05-20 21:53:18 +02:00
parent 05475a6c19
commit e4eb8fb3a9
3 changed files with 102 additions and 0 deletions
+32
View File
@@ -32,9 +32,11 @@ import {
ChevronDown,
ChevronUp,
MessageSquare,
Trash2,
} from "lucide-react";
import type { VersionWithDetails } from "@/types";
import { submitApproval } from "@/actions/approvals";
import { deleteVersion } from "@/actions/versions";
import { useToast } from "@/components/ui/use-toast";
interface VersionListProps {
@@ -43,6 +45,7 @@ interface VersionListProps {
currentVersionId?: string;
onVersionSelect?: (versionId: string) => void;
canApprove?: boolean;
canManage?: boolean;
}
const APPROVAL_STATUS_STYLES: Record<string, string> = {
@@ -75,6 +78,7 @@ export function VersionList({
currentVersionId,
onVersionSelect,
canApprove = false,
canManage = false,
}: VersionListProps) {
const [expanded, setExpanded] = useState<string | null>(currentVersionId ?? null);
const { toast } = useToast();
@@ -109,6 +113,17 @@ export function VersionList({
}
};
const handleDelete = async (versionId: string, label: string) => {
if (!confirm(`Delete ${label}? This will permanently remove the file and all comments.`)) return;
try {
await deleteVersion(versionId);
toast({ title: "Version deleted" });
router.refresh();
} catch (e) {
toast({ title: "Delete failed", description: e instanceof Error ? e.message : undefined, variant: "destructive" });
}
};
return (
<div className="space-y-2">
{versions.map((version) => {
@@ -220,6 +235,23 @@ export function VersionList({
</DropdownMenuItem>
</>
)}
{canManage && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem
className="text-red-500 focus:text-red-500"
onClick={() =>
handleDelete(
version.id,
`v${String(version.versionNumber).padStart(3, "0")}`
)
}
>
<Trash2 className="h-3.5 w-3.5 mr-2" />
Delete version
</DropdownMenuItem>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
</div>