11import { useQueryClient } from "@tanstack/react-query" ;
2+ import EasyModal , { type InnerModalProps } from "ez-modal-react" ;
23import { type ReactNode , useState } from "react" ;
34import { Alert } from "react-bootstrap" ;
45import Modal from "react-bootstrap/Modal" ;
56import { Button } from "src/components" ;
67import { T } from "src/locale" ;
78
8- interface Props {
9+ interface ShowProps {
910 title : string ;
1011 children : ReactNode ;
1112 onConfirm : ( ) => Promise < void > | void ;
12- onClose : ( ) => void ;
1313 invalidations ?: any [ ] ;
1414}
15- export function DeleteConfirmModal ( { title, children, onConfirm, onClose, invalidations } : Props ) {
15+
16+ interface Props extends InnerModalProps , ShowProps { }
17+
18+ const showDeleteConfirmModal = ( props : ShowProps ) => {
19+ EasyModal . show ( DeleteConfirmModal , props ) ;
20+ } ;
21+
22+ const DeleteConfirmModal = EasyModal . create ( ( { title, children, onConfirm, invalidations, visible, remove } : Props ) => {
1623 const queryClient = useQueryClient ( ) ;
1724 const [ error , setError ] = useState < ReactNode | null > ( null ) ;
1825 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
@@ -23,7 +30,7 @@ export function DeleteConfirmModal({ title, children, onConfirm, onClose, invali
2330 setError ( null ) ;
2431 try {
2532 await onConfirm ( ) ;
26- onClose ( ) ;
33+ remove ( ) ;
2734 // invalidate caches as requested
2835 invalidations ?. forEach ( ( inv ) => {
2936 queryClient . invalidateQueries ( { queryKey : inv } ) ;
@@ -35,7 +42,7 @@ export function DeleteConfirmModal({ title, children, onConfirm, onClose, invali
3542 } ;
3643
3744 return (
38- < Modal show onHide = { onClose } animation = { false } >
45+ < Modal show = { visible } onHide = { remove } >
3946 < Modal . Header closeButton >
4047 < Modal . Title >
4148 < T id = { title } />
@@ -48,7 +55,7 @@ export function DeleteConfirmModal({ title, children, onConfirm, onClose, invali
4855 { children }
4956 </ Modal . Body >
5057 < Modal . Footer >
51- < Button data-bs-dismiss = "modal" onClick = { onClose } disabled = { isSubmitting } >
58+ < Button data-bs-dismiss = "modal" onClick = { remove } disabled = { isSubmitting } >
5259 < T id = "cancel" />
5360 </ Button >
5461 < Button
@@ -65,4 +72,6 @@ export function DeleteConfirmModal({ title, children, onConfirm, onClose, invali
6572 </ Modal . Footer >
6673 </ Modal >
6774 ) ;
68- }
75+ } ) ;
76+
77+ export { showDeleteConfirmModal } ;
0 commit comments