ShareLinkList.jsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import { withUnstatedContainers } from './UnstatedUtils';
  5. import AppContainer from '../services/AppContainer';
  6. const ShareLinkList = (props) => {
  7. function deleteLinkHandler(shareLinkId) {
  8. if (props.onClickDeleteButton == null) {
  9. return;
  10. }
  11. props.onClickDeleteButton(shareLinkId);
  12. }
  13. function renderShareLinks() {
  14. return (
  15. <>
  16. {props.shareLinks.map(shareLink => (
  17. <tr>
  18. <td>{shareLink.link}</td>
  19. <td>{shareLink.expiration}</td>
  20. <td>{shareLink.description}</td>
  21. <td>
  22. <button className="btn btn-outline-warning" type="button" onClick={() => deleteLinkHandler(shareLink._id)}>
  23. <i className="icon-trash"></i>Delete
  24. </button>
  25. </td>
  26. </tr>
  27. ))}
  28. </>
  29. );
  30. }
  31. return (
  32. <div className="table-responsive">
  33. <table className="table table-bordered">
  34. <thead>
  35. <tr>
  36. <th>Link</th>
  37. <th>Expiration</th>
  38. <th>Description</th>
  39. <th>Order</th>
  40. </tr>
  41. </thead>
  42. <tbody>
  43. {renderShareLinks()}
  44. </tbody>
  45. </table>
  46. </div>
  47. );
  48. };
  49. const ShareLinkListWrapper = withUnstatedContainers(ShareLinkList, [AppContainer]);
  50. ShareLinkList.propTypes = {
  51. t: PropTypes.func.isRequired, // i18next
  52. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  53. shareLinks: PropTypes.array.isRequired,
  54. onClickDeleteButton: PropTypes.func,
  55. };
  56. export default withTranslation()(ShareLinkListWrapper);