TableLaporan.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import Datatable from "@/components/Tables/Datatable";
  2. import { Button } from "reactstrap";
  3. import Link from "next/link";
  4. import moment from "moment";
  5. import 'moment/min/locales';
  6. moment.locale('id');
  7. function TableLaporan({ listData, to, linkName, status = false, noBy = false }) {
  8. const getLabelSanksi = (arrayOfObjects, property) => {
  9. if (arrayOfObjects?.length === 0) {
  10. return undefined;
  11. }
  12. // let data = null
  13. let maxValue = arrayOfObjects[0][property];
  14. for (let i = 1; i < arrayOfObjects.length; i++) {
  15. if (arrayOfObjects[i][property] > maxValue) {
  16. maxValue = arrayOfObjects[i][property];
  17. // data = arrayOfObjects[i]
  18. }
  19. // else {
  20. // data = arrayOfObjects[i]
  21. // }
  22. }
  23. return maxValue;
  24. }
  25. return (
  26. <div className="card b ">
  27. <div className="card-body card-over">
  28. {listData && (
  29. <Datatable options={{ responsive: false, ordering: true }}>
  30. <table className="table w-100" data-order='[[0, "desc"]]'>
  31. <thead>
  32. <tr>
  33. <th>No.Laporan</th>
  34. <th>No.Sanksi</th>
  35. <th>Deskripsi Laporan</th>
  36. {<th>Sanksi Berupa</th>}
  37. {/* {!noBy && <th>Dibuat Oleh</th>} */}
  38. {/* <th>Created</th> */}
  39. <th>Aksi</th>
  40. </tr>
  41. </thead>
  42. <tbody>
  43. {listData.map((data) => {
  44. return (
  45. <tr key={data._id}>
  46. <td>
  47. {/* <td>{data.no_laporan}</td> */}
  48. <div className="media align-items-center">
  49. <div className="media-body d-flex">
  50. <div>
  51. <p style={{ display: "none" }}>{data.createdAt}</p>
  52. <h4>{data.laporan.no_laporan}</h4>
  53. <p>{moment(data.createdAt).format("DD-MMMM-YYYY")}</p>
  54. </div>
  55. </div>
  56. </div>
  57. </td>
  58. <td>
  59. <h4>{data.no_sanksi}</h4>
  60. </td>
  61. <td className="col-md-6">
  62. <div>
  63. <h4 className="m-0">{data.laporan.pt.nama}</h4>
  64. <p>{data.laporan.keterangan.length > 100 ? data.laporan.keterangan.substring(0, 100) + "..." : data.laporan.keterangan}</p>
  65. </div>
  66. </td>
  67. <td className="col-md-5">
  68. <div>
  69. <h4>
  70. Sanksi Administratif : {getLabelSanksi(data.sanksi, "level") === 3 ? "Berat" : getLabelSanksi(data.sanksi, "level") === 2 ? "Sedang" : "Ringan"}
  71. </h4>
  72. <p>{data.keterangan.length > 100 ? data.keterangan.substring(0, 100) + "..." : data.keterangan}</p>
  73. </div>
  74. </td>
  75. {!noBy && <td>{data.user.isPrivate ? "" : data.user.nama}</td>}
  76. <td>
  77. <div className="ml-auto">
  78. <Link
  79. href={{
  80. pathname: to,
  81. query: { id: data?._id },
  82. }}
  83. >
  84. <Button className="btn-login" color>
  85. <span className="font-color-white">
  86. {linkName}
  87. </span>
  88. </Button>
  89. </Link>
  90. </div>
  91. </td>
  92. </tr>
  93. );
  94. })}
  95. </tbody>
  96. </table>
  97. </Datatable>
  98. )}
  99. </div>
  100. </div>
  101. );
  102. }
  103. export default TableLaporan;