feat: enhance Alert component with open state management and improved dialog interactions
This commit is contained in:
parent
7df02e872d
commit
b7c518f6ed
|
|
@ -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>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue