import React, { useEffect, useRef } from 'react'; import { useTranslation } from 'react-i18next'; interface DiscardChangesDialogProps { onDiscard: () => void; onCancel: () => void; } const DiscardChangesDialog: React.FC = ({ onDiscard, onCancel, }) => { const { t } = useTranslation(); const cancelButtonRef = useRef(null); // Focus the "No" (Cancel) button when the dialog opens useEffect(() => { if (cancelButtonRef.current) { cancelButtonRef.current.focus(); } }, []); // Handle Escape key to close the dialog (keeping changes) useEffect(() => { const handleEscape = (e: KeyboardEvent) => { if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); onCancel(); } }; document.addEventListener('keydown', handleEscape); return () => document.removeEventListener('keydown', handleEscape); }, [onCancel]); return (
e.stopPropagation()} >

{t('common.discardChanges', 'Discard changes?')}

{t( 'common.discardChangesMessage', 'You have unsaved changes. Are you sure you want to discard them?' )}

); }; export default DiscardChangesDialog;