Attachment.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import User from '../User/User';
  4. export default class Attachment extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this._onAttachmentDeleteClicked = this._onAttachmentDeleteClicked.bind(this);
  8. }
  9. iconNameByFormat(format) {
  10. if (format.match(/image\/.+/i)) {
  11. return 'icon-picture';
  12. }
  13. return 'icon-doc';
  14. }
  15. _onAttachmentDeleteClicked(event) {
  16. this.props.onAttachmentDeleteClicked(this.props.attachment);
  17. }
  18. render() {
  19. const attachment = this.props.attachment;
  20. const formatIcon = this.iconNameByFormat(attachment.fileFormat);
  21. let fileInUse = '';
  22. if (this.props.inUse) {
  23. fileInUse = <span className="attachment-in-use label label-info">In Use</span>;
  24. }
  25. const fileType = <span className="attachment-filetype label label-default">{attachment.fileFormat}</span>;
  26. const btnDownload = (this.props.isUserLoggedIn)
  27. ? (
  28. <a className="attachment-download" href={attachment.downloadPathProxied}>
  29. <i className="icon-cloud-download" />
  30. </a>
  31. )
  32. : '';
  33. const btnTrash = (this.props.isUserLoggedIn)
  34. ? (
  35. /* eslint-disable-next-line */
  36. <a className="text-danger attachment-delete" onClick={this._onAttachmentDeleteClicked}>
  37. <i className="icon-trash" />
  38. </a>
  39. )
  40. : '';
  41. return (
  42. <li className="attachment">
  43. <User user={attachment.creator} />
  44. <a href={attachment.filePathProxied}><i className={formatIcon}></i> {attachment.originalName}</a>
  45. {fileType}
  46. {fileInUse}
  47. {btnDownload}
  48. {btnTrash}
  49. </li>
  50. );
  51. }
  52. }
  53. Attachment.propTypes = {
  54. attachment: PropTypes.object.isRequired,
  55. inUse: PropTypes.bool.isRequired,
  56. onAttachmentDeleteClicked: PropTypes.func.isRequired,
  57. isUserLoggedIn: PropTypes.bool.isRequired,
  58. };
  59. Attachment.defaultProps = {
  60. };