ShareLinkList.jsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. const ShareLinkList = (props) => {
  8. function deleteLinkHandler(shareLinkId) {
  9. if (props.onClickDeleteButton == null) {
  10. return;
  11. }
  12. props.onClickDeleteButton(shareLinkId);
  13. }
  14. function renderShareLinks() {
  15. return (
  16. <>
  17. {props.shareLinks.map(shareLink => (
  18. <tr key={shareLink._id}>
  19. <td>{shareLink._id}</td>
  20. <td>{shareLink.expiredAt && <span>{dateFnsFormat(new Date(shareLink.expiredAt), 'yyyy-MM-dd HH:mm')}</span>}</td>
  21. <td>{shareLink.description}</td>
  22. <td>
  23. <button className="btn btn-outline-warning" type="button" onClick={() => deleteLinkHandler(shareLink._id)}>
  24. <i className="icon-trash"></i>Delete
  25. </button>
  26. </td>
  27. </tr>
  28. ))}
  29. </>
  30. );
  31. }
  32. return (
  33. <div className="table-responsive">
  34. <table className="table table-bordered">
  35. <thead>
  36. <tr>
  37. <th>Link</th>
  38. <th>Expiration</th>
  39. <th>Description</th>
  40. <th>Order</th>
  41. </tr>
  42. </thead>
  43. <tbody>
  44. {renderShareLinks()}
  45. </tbody>
  46. </table>
  47. </div>
  48. );
  49. };
  50. /**
  51. * Wrapper component for using unstated
  52. */
  53. const ShareLinkListWrapper = withUnstatedContainers(ShareLinkList, [AppContainer]);
  54. ShareLinkList.propTypes = {
  55. t: PropTypes.func.isRequired, // i18next
  56. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  57. shareLinks: PropTypes.array.isRequired,
  58. onClickDeleteButton: PropTypes.func,
  59. export default withTranslation()(ShareLinkListWrapper);