file-tree-modal-delete.jsx 1.9 KB

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