ShareLinkList.jsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 '~/client/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
  25. pagePath={shareLink.relatedPage.path}
  26. dropdownToggleId={`copydropdown-${shareLink._id}`}
  27. pageId={shareLink._id}
  28. isShareLinkMode
  29. >
  30. Copy Link
  31. </CopyDropdown>
  32. </div>
  33. </td>
  34. {props.isAdmin && <td><a href={shareLink.relatedPage.path}>{shareLink.relatedPage.path}</a></td>}
  35. <td>{shareLink.expiredAt && <span>{dateFnsFormat(new Date(shareLink.expiredAt), 'yyyy-MM-dd HH:mm')}</span>}</td>
  36. <td>{shareLink.description}</td>
  37. <td>
  38. <button className="btn btn-outline-warning" type="button" onClick={() => deleteLinkHandler(shareLink._id)}>
  39. <i className="icon-trash"></i>{t('Delete')}
  40. </button>
  41. </td>
  42. </tr>
  43. ))}
  44. </>
  45. );
  46. }
  47. return (
  48. <div className="table-responsive">
  49. <table className="table table-bordered">
  50. <thead>
  51. <tr>
  52. <th>{t('share_links.Share Link')}</th>
  53. {props.isAdmin && <th>{t('share_links.Page Path')}</th>}
  54. <th>{t('share_links.expire')}</th>
  55. <th>{t('share_links.description')}</th>
  56. <th></th>
  57. </tr>
  58. </thead>
  59. <tbody>
  60. {renderShareLinks()}
  61. </tbody>
  62. </table>
  63. </div>
  64. );
  65. };
  66. /**
  67. * Wrapper component for using unstated
  68. */
  69. const ShareLinkListWrapper = withUnstatedContainers(ShareLinkList, [AppContainer]);
  70. ShareLinkList.propTypes = {
  71. t: PropTypes.func.isRequired, // i18next
  72. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  73. shareLinks: PropTypes.array.isRequired,
  74. onClickDeleteButton: PropTypes.func,
  75. isAdmin: PropTypes.bool,
  76. };
  77. export default withTranslation()(ShareLinkListWrapper);