2
0

DeleteAttachmentModal.js 2.3 KB

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