"use client"; import { EyeIcon, EyeOffIcon } from "lucide-react"; import { useRouter } from "next/navigation"; import { useTransition } from "react"; import { toast } from "sonner"; import { setStructuredGuideVisibility } from "@/app/admin/actions"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Spinner } from "@/components/ui/spinner"; import { cn } from "@/lib/utils"; export function GuideVisibilityControl({ guideId, guideName, isPublic, className, }: { guideId: string; guideName: string; isPublic: boolean; className?: string; }) { const router = useRouter(); const [pending, startTransition] = useTransition(); const updateVisibility = (nextPublic: boolean) => { startTransition(async () => { const result = await setStructuredGuideVisibility(guideId, nextPublic); if (result.status !== "saved") { toast.error(result.message ?? "เปลี่ยนสถานะ Guide ไม่สำเร็จ"); return; } toast.success(nextPublic ? "เผยแพร่ Guide แล้ว" : "เปลี่ยน Guide เป็น Private แล้ว"); router.refresh(); }); }; return (
{isPublic ? "Public" : "Private"} {isPublic ? ( } > {pending ? : } Make private เปลี่ยน {guideName} เป็น Private? Guide จะหายจากหน้าเว็บไซต์และลิงก์สาธารณะจะเปิดไม่ได้ แต่ยังแก้ไขได้ใน Admin ยกเลิก updateVisibility(false)} > ยืนยัน Private ) : ( )}
); }