Updated global Modals to handle after close method

refs https://github.com/TryGhost/Product/issues/3349

- allows modals to call `afterClose` when removed in case the parent wants any action on modal close, like routing update
This commit is contained in:
Rishabh 2023-07-04 20:21:30 +05:30 committed by Rishabh Garg
parent 9ac6001031
commit 56fcba1d27
2 changed files with 13 additions and 2 deletions

View File

@ -28,6 +28,7 @@ export interface ModalProps {
noPadding?: boolean;
onOk?: () => void;
onCancel?: () => void;
afterClose?: () => void;
children?: React.ReactNode;
backDrop?: boolean;
backDropClick?: boolean;
@ -49,6 +50,7 @@ const Modal: React.FC<ModalProps> = ({
onOk,
okColor = 'black',
onCancel,
afterClose,
children,
backDrop = true,
backDropClick = true,
@ -66,7 +68,10 @@ const Modal: React.FC<ModalProps> = ({
let buttons: ButtonProps[] = [];
const removeModal = () => {
confirmIfDirty(dirty, () => modal.remove());
confirmIfDirty(dirty, () => {
modal.remove();
afterClose?.();
});
};
if (!footer) {

View File

@ -36,6 +36,7 @@ export interface PreviewModalProps {
onCancel?: () => void;
onOk?: () => void;
afterClose?: () => void;
onSelectURL?: (url: string) => void;
onSelectDesktopView?: () => void;
onSelectMobileView?: () => void;
@ -65,6 +66,7 @@ export const PreviewModalContent: React.FC<PreviewModalProps> = ({
onCancel,
onOk,
afterClose,
onSelectURL,
onSelectDesktopView,
onSelectMobileView
@ -155,7 +157,10 @@ export const PreviewModalContent: React.FC<PreviewModalProps> = ({
key: 'cancel-modal',
label: cancelLabel,
onClick: (onCancel ? onCancel : () => {
confirmIfDirty(dirty, () => modal.remove());
confirmIfDirty(dirty, () => {
modal.remove();
afterClose?.();
});
}),
disabled: buttonsDisabled
});
@ -172,6 +177,7 @@ export const PreviewModalContent: React.FC<PreviewModalProps> = ({
return (
<Modal
afterClose={afterClose}
footer={false}
noPadding={true}
size={size}