DeleteAttachmentModal.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React from 'react';
  2. import { Button, Modal } from 'react-bootstrap';
  3. import Icon from '../Common/Icon';
  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. <p className="attachment-delete-image">
  17. <span>
  18. {attachment.originalName} uploaded by <User user={attachment.creator} username />
  19. </span>
  20. <img src={attachment.url} />
  21. </p>
  22. );
  23. }
  24. return (
  25. <p className="attachment-delete-file">
  26. <Icon name="file-o" />
  27. </p>
  28. );
  29. }
  30. render() {
  31. const attachment = this.props.attachmentToDelete;
  32. if (attachment === null) {
  33. return null;
  34. }
  35. const inUse = this.props.inUse;
  36. const props = Object.assign({}, this.props);
  37. delete props.onAttachmentDeleteClickedConfirm;
  38. delete props.attachmentToDelete;
  39. delete props.inUse;
  40. let renderAttachment = this.renderByFileFormat(attachment);
  41. return (
  42. <Modal {...props} className="attachment-delete-modal" bsSize="large" aria-labelledby="contained-modal-title-lg">
  43. <Modal.Header closeButton>
  44. <Modal.Title id="contained-modal-title-lg">Delete attachment?</Modal.Title>
  45. </Modal.Header>
  46. <Modal.Body>
  47. {renderAttachment}
  48. </Modal.Body>
  49. <Modal.Footer>
  50. <Button onClick={this._onDeleteConfirm} bsStyle="danger">Delete!</Button>
  51. </Modal.Footer>
  52. </Modal>
  53. );
  54. }
  55. }