ShareLinkList.jsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import dateFnsFormat from 'date-fns/format';
  5. import { withUnstatedContainers } from './UnstatedUtils';
  6. import AppContainer from '../services/AppContainer';
  7. import CopyDropdown from './Page/CopyDropdown';
  8. const ShareLinkList = (props) => {
  9. const { t } = props;
  10. function deleteLinkHandler(shareLinkId) {
  11. if (props.onClickDeleteButton == null) {
  12. return;
  13. }
  14. props.onClickDeleteButton(shareLinkId);
  15. }
  16. function renderShareLinks() {
  17. return (
  18. <>
  19. {props.shareLinks.map(shareLink => (
  20. <tr key={shareLink._id}>
  21. <td>
  22. <div className="d-flex">
  23. <span className="mr-auto my-auto">{shareLink._id}</span>
  24. <CopyDropdown isShareLinkMode pagePath={shareLink.relatedPage.path} pageId={shareLink._id} />
  25. </div>
  26. </td>
  27. {props.isAdmin && <td><a href={shareLink.relatedPage.path}>{shareLink.relatedPage.path}</a></td>}
  28. <td>{shareLink.expiredAt && <span>{dateFnsFormat(new Date(shareLink.expiredAt), 'yyyy-MM-dd HH:mm')}</span>}</td>
  29. <td>{shareLink.description}</td>
  30. <td>
  31. <button className="btn btn-outline-warning" type="button" onClick={() => deleteLinkHandler(shareLink._id)}>
  32. <i className="icon-trash"></i>{t('Delete')}
  33. </button>
  34. </td>
  35. </tr>
  36. ))}
  37. </>
  38. );
  39. }
  40. return (
  41. <div className="table-responsive">
  42. <table className="table table-bordered">
  43. <thead>
  44. <tr>
  45. <th>{t('share_links.Share Link')}</th>
  46. {props.isAdmin && <th>{t('share_links.Page Path')}</th>}
  47. <th>{t('share_links.expire')}</th>
  48. <th>{t('share_links.description')}</th>
  49. <th></th>
  50. </tr>
  51. </thead>
  52. <tbody>
  53. {renderShareLinks()}
  54. </tbody>
  55. </table>
  56. </div>
  57. );
  58. };
  59. /**
  60. * Wrapper component for using unstated
  61. */
  62. const ShareLinkListWrapper = withUnstatedContainers(ShareLinkList, [AppContainer]);
  63. ShareLinkList.propTypes = {
  64. t: PropTypes.func.isRequired, // i18next
  65. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  66. shareLinks: PropTypes.array.isRequired,
  67. onClickDeleteButton: PropTypes.func,
  68. isAdmin: PropTypes.bool,
  69. };
  70. export default withTranslation()(ShareLinkListWrapper);