ShareLinkList.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React from 'react';
  2. import * as toastr from 'toastr';
  3. import { withTranslation } from 'react-i18next';
  4. import { createSubscribedElement } from './UnstatedUtils';
  5. import AppContainer from '../services/AppContainer';
  6. import CopyDropdown from './Page/CopyDropdown';
  7. const ShareLinkList = (props) => {
  8. function deleteLinkHandler(shareLink) {
  9. try {
  10. // call api
  11. toastr.success(`Successfully deleted ${shareLink._id}`);
  12. }
  13. catch (err) {
  14. toastr.error(new Error(`Failed to delete ${shareLink._id}`));
  15. }
  16. }
  17. function GetShareLinkList() {
  18. // dummy data
  19. const dummyDate = new Date().toString();
  20. const shareLinks = [
  21. {
  22. _id: '507f1f77bcf86cd799439011', link: '/507f1f77bcf86cd799439011', expiration: dummyDate, description: 'foobar',
  23. },
  24. {
  25. _id: '52fcebd19a5c4ea066dbfa12', link: '/52fcebd19a5c4ea066dbfa12', expiration: dummyDate, description: 'test',
  26. },
  27. {
  28. _id: '54759eb3c090d83494e2d804', link: '/54759eb3c090d83494e2d804', expiration: dummyDate, description: 'hoge',
  29. },
  30. {
  31. _id: '5349b4ddd2781d08c09890f3', link: '/5349b4ddd2781d08c09890f3', expiration: dummyDate, description: 'fuga',
  32. },
  33. {
  34. _id: '5349b4ddd2781d08c09890f4', link: '/5349b4ddd2781d08c09890f4', expiration: dummyDate, description: 'piyo',
  35. },
  36. ];
  37. return (
  38. <>
  39. {shareLinks.map(shareLink => (
  40. <tr>
  41. <td>
  42. {shareLink.link}
  43. <CopyDropdown isShareLinkMode="true" shareLink={shareLink} />
  44. </td>
  45. <td>{shareLink.expiration}</td>
  46. <td>{shareLink.description}</td>
  47. <td>
  48. <button className="btn btn-outline-warning" type="button" onClick={() => deleteLinkHandler(shareLink)}>
  49. <i className="icon-trash"></i>Delete
  50. </button>
  51. </td>
  52. </tr>
  53. ))}
  54. </>
  55. );
  56. }
  57. return (
  58. <div className="table-responsive">
  59. <table className="table table-bordered">
  60. <thead>
  61. <tr>
  62. <th>Link</th>
  63. <th>Expiration</th>
  64. <th>Description</th>
  65. <th>Order</th>
  66. </tr>
  67. </thead>
  68. <tbody>
  69. <GetShareLinkList />
  70. </tbody>
  71. </table>
  72. </div>
  73. );
  74. };
  75. const ShareLinkListWrapper = (props) => {
  76. return createSubscribedElement(ShareLinkList, props, [AppContainer]);
  77. };
  78. export default withTranslation()(ShareLinkListWrapper);