import { not } from 'ramda'; import { useTranslation } from 'react-i18next'; import { Modal } from '../../components/Modal'; import { labelDiscard, labelDoYouWantToQuit, labelDoYouWantToSaveChanges, labelIfYouClickOnDiscard, labelLeave, labelSave, labelStay, labelYourFormHasUnsavedChanges } from './translatedLabels'; interface Props { closeDialog: () => void; dialogOpened: boolean; discardChanges: () => void; isSubmitting: boolean; isValidForm: boolean; saveChanges: () => void; } const UnsavedChangesDialog = ({ isValidForm, isSubmitting, closeDialog, discardChanges, saveChanges, dialogOpened }: Props): JSX.Element | null => { const { t } = useTranslation(); const labelTitle = isValidForm ? labelDoYouWantToSaveChanges : labelDoYouWantToQuit; const lebelConfirm = isValidForm ? labelSave : labelLeave; const labelCancel = isValidForm ? labelDiscard : labelStay; const labelMessage = isValidForm ? labelIfYouClickOnDiscard : labelYourFormHasUnsavedChanges; if (not(dialogOpened)) { return null; } return ( {t(labelTitle)} {t(labelMessage)} ); }; export default UnsavedChangesDialog;