file-tree-modal-delete.jsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 variant="danger" disabled isLoading />
  50. ) : (
  51. <>
  52. <OLButton variant="secondary" onClick={handleHide}>
  53. {t('cancel')}
  54. </OLButton>
  55. <OLButton variant="danger" onClick={handleDelete}>
  56. {t('delete')}
  57. </OLButton>
  58. </>
  59. )}
  60. </OLModalFooter>
  61. </OLModal>
  62. )
  63. }
  64. export default FileTreeModalDelete