0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/apps/admin-x-settings/src/utils/modals.tsx

26 lines
906 B
TypeScript

import ConfirmationModal, {ConfirmationModalProps} from '../admin-x-ds/global/modal/ConfirmationModal';
import NiceModal from '@ebay/nice-modal-react';
export function confirmIfDirty(dirty: boolean, action: () => void, options: Partial<ConfirmationModalProps> = {}) {
if (!dirty) {
action();
} else {
NiceModal.show(ConfirmationModal, {
title: 'Are you sure you want to leave this page?',
prompt: (
<>
<p>{`Hey there! It looks like you didn't save the changes you made.`}</p>
<p>Save before you go!</p>
</>
),
okLabel: 'Leave',
cancelLabel: 'Stay',
okColor: 'red',
onOk: (confirmationModal) => {
action();
confirmationModal?.remove();
},
...options
});
}
}