|
|
@@ -1,8 +1,11 @@
|
|
|
-import { Button, Modal } from 'react-bootstrap'
|
|
|
+import { Button } from 'react-bootstrap'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
import type { HistoryContextValue } from '../../../context/types/history-context-value'
|
|
|
import { useRevertSelectedFile } from '@/features/history/context/hooks/use-revert-selected-file'
|
|
|
import withErrorBoundary from '@/infrastructure/error-boundary'
|
|
|
+import { RevertFileConfirmModal } from '../modals/revert-file-confirm-modal'
|
|
|
+import { useState } from 'react'
|
|
|
+import { RevertFileErrorModal } from '../modals/revert-file-error-modal'
|
|
|
|
|
|
type ToolbarRevertingFileButtonProps = {
|
|
|
selection: HistoryContextValue['selection']
|
|
|
@@ -13,47 +16,34 @@ function ToolbarRevertFileButton({
|
|
|
}: ToolbarRevertingFileButtonProps) {
|
|
|
const { t } = useTranslation()
|
|
|
const { revertSelectedFile, isLoading } = useRevertSelectedFile()
|
|
|
+ const [showConfirmModal, setShowConfirmModal] = useState(false)
|
|
|
|
|
|
- return (
|
|
|
- <Button
|
|
|
- className="btn-secondary history-react-toolbar-revert-file-button"
|
|
|
- bsSize="xs"
|
|
|
- bsStyle={null}
|
|
|
- onClick={() => revertSelectedFile(selection)}
|
|
|
- disabled={isLoading}
|
|
|
- >
|
|
|
- {isLoading ? `${t('reverting')}…` : t('revert_file')}
|
|
|
- </Button>
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
-function ToolbarRevertErrorModal({
|
|
|
- resetErrorBoundary,
|
|
|
-}: {
|
|
|
- resetErrorBoundary: VoidFunction
|
|
|
-}) {
|
|
|
- const { t } = useTranslation()
|
|
|
+ if (!selection.updateRange || !selection.selectedFile) {
|
|
|
+ return null
|
|
|
+ }
|
|
|
|
|
|
return (
|
|
|
- <Modal show onHide={resetErrorBoundary}>
|
|
|
- <Modal.Header closeButton>
|
|
|
- <Modal.Title>{t('revert_file_error_title')}</Modal.Title>
|
|
|
- </Modal.Header>
|
|
|
- <Modal.Body>{t('revert_file_error_message')}</Modal.Body>
|
|
|
- <Modal.Footer>
|
|
|
- <Button
|
|
|
- bsStyle={null}
|
|
|
- className="btn-secondary pull-left"
|
|
|
- onClick={resetErrorBoundary}
|
|
|
- >
|
|
|
- {t('close')}
|
|
|
- </Button>
|
|
|
- </Modal.Footer>
|
|
|
- </Modal>
|
|
|
+ <>
|
|
|
+ <RevertFileConfirmModal
|
|
|
+ show={showConfirmModal}
|
|
|
+ timestamp={selection.updateRange.toVTimestamp}
|
|
|
+ onConfirm={() => {
|
|
|
+ setShowConfirmModal(false)
|
|
|
+ revertSelectedFile(selection)
|
|
|
+ }}
|
|
|
+ onHide={() => setShowConfirmModal(false)}
|
|
|
+ />
|
|
|
+ <Button
|
|
|
+ className="btn-secondary history-react-toolbar-revert-file-button"
|
|
|
+ bsSize="xs"
|
|
|
+ bsStyle={null}
|
|
|
+ onClick={() => setShowConfirmModal(true)}
|
|
|
+ disabled={isLoading}
|
|
|
+ >
|
|
|
+ {isLoading ? `${t('reverting')}…` : t('revert_file')}
|
|
|
+ </Button>
|
|
|
+ </>
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-export default withErrorBoundary(
|
|
|
- ToolbarRevertFileButton,
|
|
|
- ToolbarRevertErrorModal
|
|
|
-)
|
|
|
+export default withErrorBoundary(ToolbarRevertFileButton, RevertFileErrorModal)
|