DeleteAttachmentModal.jsx 2.5 KB

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