mirror of
https://github.com/strapi/strapi.git
synced 2025-08-11 10:18:28 +00:00
feat: add in prompt to CTB modals to avoid premature closing and data loss
This commit is contained in:
parent
16fb8dfe0c
commit
107e0d59b9
@ -20,6 +20,7 @@ import { ModalLayout, ModalBody, ModalFooter } from '@strapi/design-system/Modal
|
|||||||
import { Tabs, Tab, TabGroup, TabPanels, TabPanel } from '@strapi/design-system/Tabs';
|
import { Tabs, Tab, TabGroup, TabPanels, TabPanel } from '@strapi/design-system/Tabs';
|
||||||
import { Flex } from '@strapi/design-system/Flex';
|
import { Flex } from '@strapi/design-system/Flex';
|
||||||
import { Stack } from '@strapi/design-system/Stack';
|
import { Stack } from '@strapi/design-system/Stack';
|
||||||
|
import { isEqual } from 'lodash';
|
||||||
import pluginId from '../../pluginId';
|
import pluginId from '../../pluginId';
|
||||||
import useDataManager from '../../hooks/useDataManager';
|
import useDataManager from '../../hooks/useDataManager';
|
||||||
import useFormModalNavigation from '../../hooks/useFormModalNavigation';
|
import useFormModalNavigation from '../../hooks/useFormModalNavigation';
|
||||||
@ -790,13 +791,35 @@ const FormModal = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleConfirmClose = () => {
|
||||||
|
// eslint-disable-next-line no-alert
|
||||||
|
const confirm = window.confirm(
|
||||||
|
formatMessage({
|
||||||
|
id: 'window.confirm.close-modal.file',
|
||||||
|
defaultMessage: 'Are you sure? Your changes will be lost.',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
if (confirm) {
|
||||||
|
onCloseModal();
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: RESET_PROPS,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleClosed = () => {
|
const handleClosed = () => {
|
||||||
// Close the modal
|
// Close the modal
|
||||||
onCloseModal();
|
if (!isEqual(modifiedData, initialData)) {
|
||||||
// Reset the reducer
|
handleConfirmClose();
|
||||||
dispatch({
|
} else {
|
||||||
type: RESET_PROPS,
|
onCloseModal();
|
||||||
});
|
// Reset the reducer
|
||||||
|
dispatch({
|
||||||
|
type: RESET_PROPS,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendAdvancedTabEvent = (tab) => {
|
const sendAdvancedTabEvent = (tab) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user