"use client" import { useState } from "react" import { MoreHorizontal, Pencil, Trash, Eye, Copy } from "lucide-react" import { useRouter } from "next/navigation" import { Button } from "@/shared/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/shared/components/ui/dropdown-menu" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/shared/components/ui/alert-dialog" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/shared/components/ui/dialog" import { Question } from "../types" import { deleteQuestionAction } from "../actions" import { CreateQuestionDialog } from "./create-question-dialog" import { toast } from "sonner" interface QuestionActionsProps { question: Question } export function QuestionActions({ question }: QuestionActionsProps) { const router = useRouter() const [showEditDialog, setShowEditDialog] = useState(false) const [showDeleteDialog, setShowDeleteDialog] = useState(false) const [showViewDialog, setShowViewDialog] = useState(false) const [isDeleting, setIsDeleting] = useState(false) const copyId = () => { navigator.clipboard.writeText(question.id) toast.success("Question ID copied to clipboard") } const handleDelete = async () => { setIsDeleting(true) try { const fd = new FormData() fd.set("id", question.id) const res = await deleteQuestionAction(undefined, fd) if (res.success) { toast.success("Question deleted successfully") setShowDeleteDialog(false) router.refresh() } else { toast.error(res.message || "Failed to delete question") } } catch { toast.error("Failed to delete question") } finally { setIsDeleting(false) } } return ( <> Actions Copy ID setShowViewDialog(true)}> View Details setShowEditDialog(true)}> Edit setShowDeleteDialog(true)} > Delete Are you absolutely sure? This action cannot be undone. This will permanently delete the question and remove it from our servers. Cancel { e.preventDefault() handleDelete() }} className="bg-destructive text-destructive-foreground hover:bg-destructive/90" disabled={isDeleting} > {isDeleting ? "Deleting..." : "Delete"} Question Details ID: {question.id}
Type: {question.type.replaceAll("_", " ")}
Difficulty: {question.difficulty}
Content:
{typeof question.content === "string" ? question.content : JSON.stringify(question.content, null, 2)}
{question.author && (
Author: {question.author.name || "Unknown"}
)} {question.knowledgePoints && question.knowledgePoints.length > 0 && (
Tags:
{question.knowledgePoints.map(kp => ( {kp.name} ))}
)}
) }