From ce9d0412a775afadb5fe3f38b8304099e968abf6 Mon Sep 17 00:00:00 2001 From: gunshiz Date: Sat, 12 Sep 2026 15:35:52 +0700 Subject: [PATCH] feat : alert confirm when chaning visble --- components/admin/guide-visibility-control.tsx | 81 +++++++++---------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/components/admin/guide-visibility-control.tsx b/components/admin/guide-visibility-control.tsx index 4cca262..25fded2 100644 --- a/components/admin/guide-visibility-control.tsx +++ b/components/admin/guide-visibility-control.tsx @@ -2,7 +2,7 @@ import { EyeIcon, EyeOffIcon } from "lucide-react"; import { useRouter } from "next/navigation"; -import { useTransition } from "react"; +import { useState, useTransition } from "react"; import { toast } from "sonner"; import { setStructuredGuideVisibility } from "@/app/admin/actions"; @@ -15,7 +15,6 @@ import { AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, - AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; @@ -35,6 +34,7 @@ export function GuideVisibilityControl({ }) { const router = useRouter(); const [pending, startTransition] = useTransition(); + const [open, setOpen] = useState(false); const updateVisibility = (nextPublic: boolean) => { startTransition(async () => { @@ -44,6 +44,7 @@ export function GuideVisibilityControl({ return; } toast.success(nextPublic ? "เผยแพร่ Guide แล้ว" : "เปลี่ยน Guide เป็น Private แล้ว"); + setOpen(false); router.refresh(); }); }; @@ -53,45 +54,43 @@ export function GuideVisibilityControl({ {isPublic ? "Public" : "Private"} - {isPublic ? ( - - - } - > - {pending ? : } - Make private - - - - เปลี่ยน {guideName} เป็น Private? - - Guide จะหายจากหน้าเว็บไซต์และลิงก์สาธารณะจะเปิดไม่ได้ แต่ยังแก้ไขได้ใน Admin - - - - ยกเลิก - updateVisibility(false)} - > - ยืนยัน Private - - - - - ) : ( - - )} + + + + + + {isPublic ? `เปลี่ยน ${guideName} เป็น Private?` : `เผยแพร่ ${guideName} เป็น Public?`} + + + {isPublic + ? "Guide จะหายจากหน้าเว็บไซต์และลิงก์สาธารณะจะเปิดไม่ได้ แต่ยังแก้ไขได้ใน Admin" + : "Guide จะแสดงบนหน้าเว็บไซต์และทุกคนจะเปิดดูผ่านลิงก์สาธารณะได้"} + + + + ยกเลิก + updateVisibility(!isPublic)} + > + {pending && } + {isPublic ? "ยืนยัน Private" : "ยืนยัน Public"} + + + + ); }