Attachment.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import UserPicture from '../User/UserPicture';
  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. <span className="mr-1 attachment-userpicture">
  44. <UserPicture user={attachment.creator} size="sm"></UserPicture>
  45. </span>
  46. <a href={attachment.filePathProxied}><i className={formatIcon}></i> {attachment.originalName}</a>
  47. {fileType}
  48. {fileInUse}
  49. {btnDownload}
  50. {btnTrash}
  51. </li>
  52. );
  53. }
  54. }
  55. Attachment.propTypes = {
  56. attachment: PropTypes.object.isRequired,
  57. inUse: PropTypes.bool.isRequired,
  58. onAttachmentDeleteClicked: PropTypes.func.isRequired,
  59. isUserLoggedIn: PropTypes.bool.isRequired,
  60. };
  61. Attachment.defaultProps = {
  62. };