import { useBlocker } from '@tanstack/react-router'; import { useTranslation } from 'react-i18next'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; /** * Asks for confirmation before the administrator leaves the page through the menu or a link while the form holds changes * that are not saved. (Closing the tab or reloading is covered by the browser warning in the page itself.) */ export function UnsavedChangesGuard({ dirty }: { dirty: boolean }) { const { t } = useTranslation(); const blocker = useBlocker({ shouldBlockFn: () => dirty, disabled: !dirty, enableBeforeUnload: false, withResolver: true, }); return ( { if (!open) blocker.reset?.(); }}> {t('hero.unsaved.leaveTitle')} {t('hero.unsaved.leaveText')} ); }