file-tree-modal-delete.jsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Button, Modal } from 'react-bootstrap'
  2. import { useTranslation } from 'react-i18next'
  3. import AccessibleModal from '../../../../shared/components/accessible-modal'
  4. import { useFileTreeActionable } from '../../contexts/file-tree-actionable'
  5. function FileTreeModalDelete() {
  6. const { t } = useTranslation()
  7. const {
  8. isDeleting,
  9. inFlight,
  10. finishDeleting,
  11. actionedEntities,
  12. cancel,
  13. error,
  14. } = useFileTreeActionable()
  15. if (!isDeleting) return null // the modal will not be rendered; return early
  16. function handleHide() {
  17. cancel()
  18. }
  19. function handleDelete() {
  20. finishDeleting()
  21. }
  22. return (
  23. <AccessibleModal show onHide={handleHide}>
  24. <Modal.Header>
  25. <Modal.Title>{t('delete')}</Modal.Title>
  26. </Modal.Header>
  27. <Modal.Body>
  28. <p>{t('sure_you_want_to_delete')}</p>
  29. <ul>
  30. {actionedEntities.map(entity => (
  31. <li key={entity._id}>{entity.name}</li>
  32. ))}
  33. </ul>
  34. {error && (
  35. <div className="alert alert-danger file-tree-modal-alert">
  36. {t('generic_something_went_wrong')}
  37. </div>
  38. )}
  39. </Modal.Body>
  40. <Modal.Footer>
  41. {inFlight ? (
  42. <Button bsStyle="danger" disabled>
  43. {t('deleting')}…
  44. </Button>
  45. ) : (
  46. <>
  47. <Button
  48. bsStyle={null}
  49. className="btn-secondary"
  50. onClick={handleHide}
  51. >
  52. {t('cancel')}
  53. </Button>
  54. <Button bsStyle="danger" onClick={handleDelete}>
  55. {t('delete')}
  56. </Button>
  57. </>
  58. )}
  59. </Modal.Footer>
  60. </AccessibleModal>
  61. )
  62. }
  63. export default FileTreeModalDelete