Files
eu/components/drafts.tsx
T
2026-06-20 18:30:39 +03:00

69 lines
2.3 KiB
TypeScript

"use client"
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { deletePageAction } from "@/lib/pages/actions";
import { PencilIcon, XIcon } from "lucide-react";
import Link from "next/link";
import { useState } from "react";
import { Spinner } from "@/components/ui/spinner";
type Draft = { id: string; title: string; slug: string; updatedAt: Date };
export default function DraftsDialog({ drafts }: { drafts: Draft[]}) {
const [isDeletingId, setIsDeletingId] = useState("");
async function deletePage(id: string) {
setIsDeletingId(id);
try {
await deletePageAction(id)
} finally {
setIsDeletingId("")
}
}
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="secondary" className="flex flex-row items-center gap-2">Drafts<div className="flex items-center justify-center bg-black/50 text-white w-3.5 h-3.5 text-xs rounded-full">{drafts.length}</div></Button>
</DialogTrigger>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>Drafts</DialogTitle>
<DialogDescription>Here are drafts of your pages</DialogDescription>
</DialogHeader>
{drafts.length > 0 ? (
<div className="flex flex-col items-center gap-2">
{drafts.map((draft) => (
<div className="w-full flex flex-row items-center justify-between" key={draft.id}>
<h3 className="w-64 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer truncate">
{draft.title}
</h3>
<div className="flex flex-row items-center gap-2">
<Link href={`/news/${draft.slug}/edit`}>
<Button variant="secondary" size="icon-sm"><PencilIcon /></Button>
</Link>
<Button disabled={isDeletingId === draft.id} variant="secondary" size="icon-sm" onClick={() => deletePage(draft.id)}>
{isDeletingId === draft.id ? <Spinner /> : <XIcon />}
</Button>
</div>
</div>
))}
</div>
) : (
<h4>There are no drafts yet...</h4>
)}
</DialogContent>
</Dialog>
)
}