ShareLinkList.jsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import { toastSuccess, toastError } from '../util/apiNotification';
  5. import { withUnstatedContainers } from './UnstatedUtils';
  6. import AppContainer from '../services/AppContainer';
  7. const ShareLinkList = (props) => {
  8. const { t, appContainer } = props;
  9. async function deleteLinkHandler(shareLinkId) {
  10. try {
  11. const res = await appContainer.apiv3Delete(`/share-links/${shareLinkId}`);
  12. const { deletedShareLink } = res.data;
  13. toastSuccess(t('remove_share_link_success', { shareLinkId: deletedShareLink._id }));
  14. }
  15. catch (err) {
  16. toastError(err);
  17. }
  18. }
  19. function GetShareLinkList() {
  20. // dummy data
  21. const dummyDate = new Date().toString();
  22. const shareLinks = [
  23. {
  24. _id: '507f1f77bcf86cd799439011', link: '/507f1f77bcf86cd799439011', expiration: dummyDate, description: 'foobar',
  25. },
  26. {
  27. _id: '52fcebd19a5c4ea066dbfa12', link: '/52fcebd19a5c4ea066dbfa12', expiration: dummyDate, description: 'test',
  28. },
  29. {
  30. _id: '54759eb3c090d83494e2d804', link: '/54759eb3c090d83494e2d804', expiration: dummyDate, description: 'hoge',
  31. },
  32. {
  33. _id: '5349b4ddd2781d08c09890f3', link: '/5349b4ddd2781d08c09890f3', expiration: dummyDate, description: 'fuga',
  34. },
  35. {
  36. _id: '5349b4ddd2781d08c09890f4', link: '/5349b4ddd2781d08c09890f4', expiration: dummyDate, description: 'piyo',
  37. },
  38. ];
  39. return (
  40. <>
  41. {shareLinks.map(shareLink => (
  42. <tr>
  43. <td>{shareLink.link}</td>
  44. <td>{shareLink.expiration}</td>
  45. <td>{shareLink.description}</td>
  46. <td>
  47. <button className="btn btn-outline-warning" type="button" onClick={() => deleteLinkHandler(shareLink._id)}>
  48. <i className="icon-trash"></i>Delete
  49. </button>
  50. </td>
  51. </tr>
  52. ))}
  53. </>
  54. );
  55. }
  56. return (
  57. <div className="table-responsive">
  58. <table className="table table-bordered">
  59. <thead>
  60. <tr>
  61. <th>Link</th>
  62. <th>Expiration</th>
  63. <th>Description</th>
  64. <th>Order</th>
  65. </tr>
  66. </thead>
  67. <tbody>
  68. <GetShareLinkList />
  69. </tbody>
  70. </table>
  71. </div>
  72. );
  73. };
  74. const ShareLinkListWrapper = withUnstatedContainers(ShareLinkList, [AppContainer]);
  75. ShareLinkList.propTypes = {
  76. t: PropTypes.func.isRequired, // i18next
  77. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  78. };
  79. export default withTranslation()(ShareLinkListWrapper);