From b7c518f6edec4e12f2b00dd55ad09bb115695b55 Mon Sep 17 00:00:00 2001 From: faisolavolut Date: Thu, 13 Feb 2025 10:58:25 +0700 Subject: [PATCH] feat: enhance Alert component with open state management and improved dialog interactions --- components/ui/alert.tsx | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/components/ui/alert.tsx b/components/ui/alert.tsx index 55b7b8e..d044403 100644 --- a/components/ui/alert.tsx +++ b/components/ui/alert.tsx @@ -1,4 +1,4 @@ -import { FC } from "react"; +import { FC, useState } from "react"; import { AlertDialog, AlertDialogAction, @@ -36,6 +36,7 @@ export const Alert: FC<{ onOpenChange, hiddenFooter = false, }) => { + const [isOpen, setIsOpen] = useState(false); const message: any = { save: "Your data will be saved securely. You can update it at any time if needed.", delete: @@ -47,7 +48,12 @@ export const Alert: FC<{ open: open, onOpenChange: onOpenChange, } - : {}; + : { + open: isOpen, + onOpenChange: (e: boolean) => { + setIsOpen(e); + }, + }; return ( <> @@ -71,10 +77,21 @@ export const Alert: FC<{ {!hiddenFooter ? ( <> - No + { + setIsOpen(false); + }} + > + No + { + if (typeof onClick === "function") { + await onClick(e); + } + setIsOpen(false); + }} > Yes