mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2026-03-04 02:20:19 +01:00
114 lines
2.8 KiB
TypeScript
114 lines
2.8 KiB
TypeScript
import { Modal, Text, Button, Group, Stack } from '@mantine/core';
|
|
import { useNavigationGuard } from '../../contexts/NavigationContext';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
interface NavigationWarningModalProps {
|
|
onApplyAndContinue?: () => Promise<void>;
|
|
onExportAndContinue?: () => Promise<void>;
|
|
}
|
|
|
|
const NavigationWarningModal = ({
|
|
onApplyAndContinue,
|
|
onExportAndContinue
|
|
}: NavigationWarningModalProps) => {
|
|
|
|
const { t } = useTranslation();
|
|
const {
|
|
showNavigationWarning,
|
|
hasUnsavedChanges,
|
|
cancelNavigation,
|
|
confirmNavigation,
|
|
setHasUnsavedChanges
|
|
} = useNavigationGuard();
|
|
|
|
const handleKeepWorking = () => {
|
|
cancelNavigation();
|
|
};
|
|
|
|
const handleDiscardChanges = () => {
|
|
setHasUnsavedChanges(false);
|
|
confirmNavigation();
|
|
};
|
|
|
|
const handleApplyAndContinue = async () => {
|
|
if (onApplyAndContinue) {
|
|
await onApplyAndContinue();
|
|
}
|
|
setHasUnsavedChanges(false);
|
|
confirmNavigation();
|
|
};
|
|
|
|
const handleExportAndContinue = async () => {
|
|
if (onExportAndContinue) {
|
|
await onExportAndContinue();
|
|
}
|
|
setHasUnsavedChanges(false);
|
|
confirmNavigation();
|
|
};
|
|
|
|
if (!hasUnsavedChanges) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<Modal
|
|
opened={showNavigationWarning}
|
|
onClose={handleKeepWorking}
|
|
title={t("unsavedChangesTitle", "Unsaved Changes")}
|
|
centered
|
|
size="xl"
|
|
closeOnClickOutside={false}
|
|
closeOnEscape={false}
|
|
>
|
|
<Stack gap="md">
|
|
<Text>
|
|
{t("unsavedChanges", "You have unsaved changes to your PDF. What would you like to do?")}
|
|
</Text>
|
|
|
|
<Group justify="space-between" gap="sm">
|
|
<Group gap="sm">
|
|
<Button
|
|
variant="light"
|
|
color="red"
|
|
onClick={handleDiscardChanges}
|
|
>
|
|
{t("discardChanges", "Discard Changes")}
|
|
</Button>
|
|
|
|
<Button
|
|
variant="light"
|
|
color="var(--mantine-color-gray-8)"
|
|
onClick={handleKeepWorking}
|
|
>
|
|
{t("keepWorking", "Keep Working")}
|
|
</Button>
|
|
</Group>
|
|
|
|
<Group gap="sm">
|
|
{onExportAndContinue && (
|
|
<Button
|
|
variant="light"
|
|
onClick={handleExportAndContinue}
|
|
>
|
|
{t("exportAndContinue", "Export & Continue")}
|
|
</Button>
|
|
)}
|
|
|
|
{onApplyAndContinue && (
|
|
<Button
|
|
variant="light"
|
|
color="green"
|
|
onClick={handleApplyAndContinue}
|
|
>
|
|
{t("applyAndContinue", "Apply & Continue")}
|
|
</Button>
|
|
)}
|
|
</Group>
|
|
</Group>
|
|
</Stack>
|
|
</Modal>
|
|
);
|
|
};
|
|
|
|
export default NavigationWarningModal;
|