PreventNavigationOnUnsavedChanges.tsx26 lines · main
| 1 | import { |
| 2 | DiscardChangesConfirmationDialog, |
| 3 | type DiscardChangesConfirmationDialogProps, |
| 4 | } from './DiscardChangesConfirmationDialog' |
| 5 | import { usePreventNavigationOnUnsavedChanges } from '@/hooks/ui/usePreventNavigationOnUnsavedChanges' |
| 6 | |
| 7 | export const PreventNavigationOnUnsavedChanges = ({ |
| 8 | hasChanges, |
| 9 | ...props |
| 10 | }: { hasChanges: boolean } & Omit< |
| 11 | DiscardChangesConfirmationDialogProps, |
| 12 | 'visible' | 'onClose' | 'onCancel' |
| 13 | >) => { |
| 14 | const { handleCancel, handleConfirm, shouldConfirm } = usePreventNavigationOnUnsavedChanges({ |
| 15 | hasChanges, |
| 16 | }) |
| 17 | |
| 18 | return ( |
| 19 | <DiscardChangesConfirmationDialog |
| 20 | visible={shouldConfirm} |
| 21 | onCancel={handleCancel} |
| 22 | onClose={handleConfirm} |
| 23 | {...props} |
| 24 | /> |
| 25 | ) |
| 26 | } |