DeleteAttachmentModal.jsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* eslint-disable react/prop-types */
  2. import React from 'react';
  3. import {
  4. Button,
  5. Modal, ModalHeader, ModalBody, ModalFooter,
  6. } from 'reactstrap';
  7. import UserPicture from '../User/UserPicture';
  8. import Username from '../User/Username';
  9. export default class DeleteAttachmentModal extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this._onDeleteConfirm = this._onDeleteConfirm.bind(this);
  13. }
  14. _onDeleteConfirm() {
  15. this.props.onAttachmentDeleteClickedConfirm(this.props.attachmentToDelete);
  16. }
  17. iconNameByFormat(format) {
  18. if (format.match(/image\/.+/i)) {
  19. return 'icon-picture';
  20. }
  21. return 'icon-doc';
  22. }
  23. renderByFileFormat(attachment) {
  24. const content = (attachment.fileFormat.match(/image\/.+/i))
  25. ? <img src={attachment.filePathProxied} alt="deleting image" />
  26. : '';
  27. return (
  28. <div className="attachment-delete-image">
  29. <p>
  30. <i className={this.iconNameByFormat(attachment.fileFormat)}></i> {attachment.originalName}
  31. </p>
  32. <p>
  33. uploaded by <UserPicture user={attachment.creator} size="sm"></UserPicture> <Username user={attachment.creator}></Username>
  34. </p>
  35. {content}
  36. </div>
  37. );
  38. }
  39. render() {
  40. const attachment = this.props.attachmentToDelete;
  41. if (attachment === null) {
  42. return null;
  43. }
  44. const props = Object.assign({}, this.props);
  45. delete props.onAttachmentDeleteClickedConfirm;
  46. delete props.attachmentToDelete;
  47. delete props.inUse;
  48. delete props.deleting;
  49. delete props.deleteError;
  50. let deletingIndicator = '';
  51. if (this.props.deleting) {
  52. deletingIndicator = <div className="speeding-wheel-sm"></div>;
  53. }
  54. if (this.props.deleteError) {
  55. deletingIndicator = <span>{this.props.deleteError}</span>;
  56. }
  57. const renderAttachment = this.renderByFileFormat(attachment);
  58. return (
  59. <Modal {...props} className="attachment-delete-modal" bssize="large" aria-labelledby="contained-modal-title-lg">
  60. <ModalHeader tag="h4" toggle={this.props.toggle} className="bg-danger">
  61. <span id="contained-modal-title-lg">Delete attachment?</span>
  62. </ModalHeader>
  63. <ModalBody>
  64. {renderAttachment}
  65. </ModalBody>
  66. <ModalFooter>
  67. <div className="mr-3 d-inline-block">
  68. {deletingIndicator}
  69. </div>
  70. <Button
  71. color="danger"
  72. onClick={this._onDeleteConfirm}
  73. disabled={this.props.deleting}
  74. >Delete!
  75. </Button>
  76. </ModalFooter>
  77. </Modal>
  78. );
  79. }
  80. }