file-tree-modal-delete.jsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { useTranslation } from 'react-i18next'
  2. import { useFileTreeActionable } from '../../contexts/file-tree-actionable'
  3. import OLModal, {
  4. OLModalBody,
  5. OLModalFooter,
  6. OLModalHeader,
  7. OLModalTitle,
  8. } from '@/features/ui/components/ol/ol-modal'
  9. import OLButton from '@/features/ui/components/ol/ol-button'
  10. import OLNotification from '@/features/ui/components/ol/ol-notification'
  11. function FileTreeModalDelete() {
  12. const { t } = useTranslation()
  13. const {
  14. isDeleting,
  15. inFlight,
  16. finishDeleting,
  17. actionedEntities,
  18. cancel,
  19. error,
  20. } = useFileTreeActionable()
  21. if (!isDeleting) return null // the modal will not be rendered; return early
  22. function handleHide() {
  23. cancel()
  24. }
  25. function handleDelete() {
  26. finishDeleting()
  27. }
  28. return (
  29. <OLModal show onHide={handleHide}>
  30. <OLModalHeader>
  31. <OLModalTitle>{t('delete')}</OLModalTitle>
  32. </OLModalHeader>
  33. <OLModalBody>
  34. <p>{t('sure_you_want_to_delete')}</p>
  35. <ul>
  36. {actionedEntities.map(entity => (
  37. <li key={entity._id}>{entity.name}</li>
  38. ))}
  39. </ul>
  40. {error && (
  41. <OLNotification
  42. type="error"
  43. content={t('generic_something_went_wrong')}
  44. />
  45. )}
  46. </OLModalBody>
  47. <OLModalFooter>
  48. {inFlight ? (
  49. <OLButton
  50. variant="danger"
  51. disabled
  52. isLoading
  53. bs3Props={{ loading: `${t('deleting')}…` }}
  54. />
  55. ) : (
  56. <>
  57. <OLButton variant="secondary" onClick={handleHide}>
  58. {t('cancel')}
  59. </OLButton>
  60. <OLButton variant="danger" onClick={handleDelete}>
  61. {t('delete')}
  62. </OLButton>
  63. </>
  64. )}
  65. </OLModalFooter>
  66. </OLModal>
  67. )
  68. }
  69. export default FileTreeModalDelete