file-tree-modal-delete.tsx 1.9 KB

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