DeleteAttachmentModal.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. renderByFileFormat(attachment) {
  14. if (attachment.fileFormat.match(/image\/.+/i)) {
  15. return (
  16. <div className="attachment-delete-image">
  17. <p>
  18. {attachment.originalName} uploaded by <User user={attachment.creator} username />
  19. </p>
  20. <img src={attachment.url} />
  21. </div>
  22. );
  23. }
  24. return (
  25. <p className="attachment-delete-file">
  26. <i className="fa fa-file-o"></i>
  27. </p>
  28. );
  29. }
  30. render() {
  31. const attachment = this.props.attachmentToDelete;
  32. if (attachment === null) {
  33. return null;
  34. }
  35. const props = Object.assign({}, this.props);
  36. delete props.onAttachmentDeleteClickedConfirm;
  37. delete props.attachmentToDelete;
  38. delete props.inUse;
  39. delete props.deleting;
  40. delete props.deleteError;
  41. let deletingIndicator = '';
  42. if (this.props.deleting) {
  43. deletingIndicator = <Icon name="spinner" spin />;
  44. }
  45. if (this.props.deleteError) {
  46. deletingIndicator = <p>{this.props.deleteError}</p>;
  47. }
  48. let renderAttachment = this.renderByFileFormat(attachment);
  49. return (
  50. <Modal {...props} className="attachment-delete-modal" bsSize="large" aria-labelledby="contained-modal-title-lg">
  51. <Modal.Header closeButton>
  52. <Modal.Title id="contained-modal-title-lg">Delete attachment?</Modal.Title>
  53. </Modal.Header>
  54. <Modal.Body>
  55. {renderAttachment}
  56. </Modal.Body>
  57. <Modal.Footer>
  58. {deletingIndicator}
  59. <Button onClick={this._onDeleteConfirm} bsStyle="danger"
  60. disabled={this.props.deleting}>Delete!</Button>
  61. </Modal.Footer>
  62. </Modal>
  63. );
  64. }
  65. }