feat: enhance Alert component with open state management and improved dialog interactions

This commit is contained in:
faisolavolut 2025-02-13 10:58:25 +07:00
parent 7df02e872d
commit b7c518f6ed
1 changed files with 21 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import { FC } from "react"; import { FC, useState } from "react";
import { import {
AlertDialog, AlertDialog,
AlertDialogAction, AlertDialogAction,
@ -36,6 +36,7 @@ export const Alert: FC<{
onOpenChange, onOpenChange,
hiddenFooter = false, hiddenFooter = false,
}) => { }) => {
const [isOpen, setIsOpen] = useState(false);
const message: any = { const message: any = {
save: "Your data will be saved securely. You can update it at any time if needed.", save: "Your data will be saved securely. You can update it at any time if needed.",
delete: delete:
@ -47,7 +48,12 @@ export const Alert: FC<{
open: open, open: open,
onOpenChange: onOpenChange, onOpenChange: onOpenChange,
} }
: {}; : {
open: isOpen,
onOpenChange: (e: boolean) => {
setIsOpen(e);
},
};
return ( return (
<> <>
<AlertDialog {...param}> <AlertDialog {...param}>
@ -71,10 +77,21 @@ export const Alert: FC<{
{!hiddenFooter ? ( {!hiddenFooter ? (
<> <>
<AlertDialogFooter> <AlertDialogFooter>
<AlertDialogCancel>No</AlertDialogCancel> <AlertDialogCancel
onClick={() => {
setIsOpen(false);
}}
>
No
</AlertDialogCancel>
<AlertDialogAction <AlertDialogAction
className={"bg-primary text-white"} className={"bg-primary text-white"}
onClick={onClick} onClick={async (e) => {
if (typeof onClick === "function") {
await onClick(e);
}
setIsOpen(false);
}}
> >
Yes Yes
</AlertDialogAction> </AlertDialogAction>