file-tree-modal-delete.tsx 1.9 KB

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