ShareLinkList.jsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 className="d-flex justify-content-between align-items-center">
  22. <span>{shareLink._id}</span>
  23. <CopyDropdown isShareLinkMode="true" shareLinkId={shareLink._id} pagePath={props.pagePath} pageId={shareLink.relatedPage} />
  24. </td>
  25. <td>{shareLink.expiredAt && <span>{dateFnsFormat(new Date(shareLink.expiredAt), 'yyyy-MM-dd HH:mm')}</span>}</td>
  26. <td>{shareLink.description}</td>
  27. <td>
  28. <button className="btn btn-outline-warning" type="button" onClick={() => deleteLinkHandler(shareLink._id)}>
  29. <i className="icon-trash"></i>{t('Delete')}
  30. </button>
  31. </td>
  32. </tr>
  33. ))}
  34. </>
  35. );
  36. }
  37. return (
  38. <div className="table-responsive">
  39. <table className="table table-bordered">
  40. <thead>
  41. <tr>
  42. <th>{t('share_links.Share Link')}</th>
  43. <th>{t('share_links.expire')}</th>
  44. <th>{t('share_links.description')}</th>
  45. <th></th>
  46. </tr>
  47. </thead>
  48. <tbody>
  49. {renderShareLinks()}
  50. </tbody>
  51. </table>
  52. </div>
  53. );
  54. };
  55. const ShareLinkListWrapper = withUnstatedContainers(ShareLinkList, [AppContainer]);
  56. ShareLinkList.propTypes = {
  57. t: PropTypes.func.isRequired, // i18next
  58. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  59. pagePath: PropTypes.string.isRequired,
  60. shareLinks: PropTypes.array.isRequired,
  61. onClickDeleteButton: PropTypes.func,
  62. };
  63. export default withTranslation()(ShareLinkListWrapper);