2025-10-03 17:02:05 +01:00
|
|
|
import { Modal, Text, Button, Group, Stack } from "@mantine/core";
|
|
|
|
|
import { useNavigationGuard } from "../../contexts/NavigationContext";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
|
|
|
|
|
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
|
|
|
|
|
import CheckCircleOutlineIcon from "@mui/icons-material/CheckCircleOutline";
|
2025-07-16 17:53:50 +01:00
|
|
|
|
|
|
|
|
interface NavigationWarningModalProps {
|
|
|
|
|
onApplyAndContinue?: () => Promise<void>;
|
|
|
|
|
onExportAndContinue?: () => Promise<void>;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-03 17:02:05 +01:00
|
|
|
const NavigationWarningModal = ({ onApplyAndContinue, onExportAndContinue }: NavigationWarningModalProps) => {
|
2025-09-26 16:29:58 +01:00
|
|
|
const { t } = useTranslation();
|
2025-10-03 17:02:05 +01:00
|
|
|
const { showNavigationWarning, hasUnsavedChanges, cancelNavigation, confirmNavigation, setHasUnsavedChanges } =
|
|
|
|
|
useNavigationGuard();
|
2025-07-16 17:53:50 +01:00
|
|
|
|
|
|
|
|
const handleKeepWorking = () => {
|
|
|
|
|
cancelNavigation();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDiscardChanges = () => {
|
|
|
|
|
setHasUnsavedChanges(false);
|
|
|
|
|
confirmNavigation();
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-02 20:14:35 +01:00
|
|
|
const handleApplyAndContinue = async () => {
|
|
|
|
|
if (onApplyAndContinue) {
|
|
|
|
|
await onApplyAndContinue();
|
|
|
|
|
}
|
|
|
|
|
setHasUnsavedChanges(false);
|
|
|
|
|
confirmNavigation();
|
|
|
|
|
};
|
2025-07-16 17:53:50 +01:00
|
|
|
|
2025-10-03 17:02:05 +01:00
|
|
|
const _handleExportAndContinue = async () => {
|
2025-07-16 17:53:50 +01:00
|
|
|
if (onExportAndContinue) {
|
|
|
|
|
await onExportAndContinue();
|
|
|
|
|
}
|
|
|
|
|
setHasUnsavedChanges(false);
|
|
|
|
|
confirmNavigation();
|
|
|
|
|
};
|
2025-10-03 17:02:05 +01:00
|
|
|
const BUTTON_WIDTH = "10rem";
|
2025-07-16 17:53:50 +01:00
|
|
|
|
|
|
|
|
if (!hasUnsavedChanges) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
opened={showNavigationWarning}
|
|
|
|
|
onClose={handleKeepWorking}
|
2025-09-26 16:29:58 +01:00
|
|
|
title={t("unsavedChangesTitle", "Unsaved Changes")}
|
2025-07-16 17:53:50 +01:00
|
|
|
centered
|
2025-10-03 17:02:05 +01:00
|
|
|
size="auto"
|
|
|
|
|
closeOnClickOutside={true}
|
|
|
|
|
closeOnEscape={true}
|
2025-07-16 17:53:50 +01:00
|
|
|
>
|
2025-10-03 17:02:05 +01:00
|
|
|
<Stack>
|
|
|
|
|
<Stack ta="center" p="md">
|
|
|
|
|
<Text size="md" fw="300">
|
|
|
|
|
{t("unsavedChanges", "You have unsaved changes to your PDF.")}
|
2025-07-16 17:53:50 +01:00
|
|
|
</Text>
|
2025-10-03 17:02:05 +01:00
|
|
|
<Text size="lg" fw="500" >
|
|
|
|
|
{t("areYouSure", "Are you sure you want to leave?")}
|
|
|
|
|
</Text>
|
|
|
|
|
</Stack>
|
2025-09-26 16:29:58 +01:00
|
|
|
|
2025-10-03 17:02:05 +01:00
|
|
|
{/* Desktop layout: 2 groups side by side */}
|
|
|
|
|
<Group justify="space-between" gap="xl" visibleFrom="md">
|
|
|
|
|
<Group gap="sm">
|
|
|
|
|
<Button variant="light" color="var(--mantine-color-gray-8)" onClick={handleKeepWorking} w={BUTTON_WIDTH} leftSection={<ArrowBackIcon fontSize="small" />}>
|
2025-09-26 16:29:58 +01:00
|
|
|
{t("keepWorking", "Keep Working")}
|
2025-07-16 17:53:50 +01:00
|
|
|
</Button>
|
2025-10-02 20:14:35 +01:00
|
|
|
</Group>
|
2025-10-03 17:02:05 +01:00
|
|
|
<Group gap="sm">
|
|
|
|
|
<Button variant="filled" color="var(--mantine-color-red-9)" onClick={handleDiscardChanges} w={BUTTON_WIDTH} leftSection={<DeleteOutlineIcon fontSize="small" />}>
|
|
|
|
|
{t("discardChanges", "Discard Changes")}
|
|
|
|
|
</Button>
|
2025-10-02 20:14:35 +01:00
|
|
|
{onApplyAndContinue && (
|
2025-10-03 17:02:05 +01:00
|
|
|
<Button variant="filled" onClick={handleApplyAndContinue} w={BUTTON_WIDTH} leftSection={<CheckCircleOutlineIcon fontSize="small" />}>
|
|
|
|
|
{t("applyAndContinue", "Apply & Leave")}
|
2025-09-26 16:29:58 +01:00
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</Group>
|
2025-07-16 17:53:50 +01:00
|
|
|
</Group>
|
2025-10-03 17:02:05 +01:00
|
|
|
|
|
|
|
|
{/* Mobile layout: centered stack of 4 buttons */}
|
|
|
|
|
<Stack align="center" gap="sm" hiddenFrom="md">
|
|
|
|
|
<Button variant="light" color="var(--mantine-color-gray-8)" onClick={handleKeepWorking} w={BUTTON_WIDTH} leftSection={<ArrowBackIcon fontSize="small" />}>
|
|
|
|
|
{t("keepWorking", "Keep Working")}
|
|
|
|
|
</Button>
|
|
|
|
|
<Button variant="filled" color="var(--mantine-color-red-9)" onClick={handleDiscardChanges} w={BUTTON_WIDTH} leftSection={<DeleteOutlineIcon fontSize="small" />}>
|
|
|
|
|
{t("discardChanges", "Discard Changes")}
|
|
|
|
|
</Button>
|
|
|
|
|
{onApplyAndContinue && (
|
|
|
|
|
<Button variant="filled" onClick={handleApplyAndContinue} w={BUTTON_WIDTH} leftSection={<CheckCircleOutlineIcon fontSize="small" />}>
|
|
|
|
|
{t("applyAndContinue", "Apply & Leave")}
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
2025-07-16 17:53:50 +01:00
|
|
|
</Stack>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-26 16:29:58 +01:00
|
|
|
export default NavigationWarningModal;
|