TableLaporan.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/locale/id';
  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; // Return undefined for empty arrays
  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>Deskripcasdasi Laporan</th>
  36. {status && <th>Status</th>}
  37. {!noBy && <th>Dibuat Oleh</th>}
  38. {/* <th>Created</th> */}
  39. <th></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 className=" col-md-3">
  59. <div>
  60. <h4>{data.no_sanksi}</h4>
  61. </div>
  62. </td>
  63. <td className=" col-md-6">
  64. <div>
  65. <h4 className="m-0">{data.laporan.pt.nama.length > 64 ? data.laporan.pt.nama.substring(0, 64) + "..." : data.laporan.pt.nama}</h4>
  66. <p>{data.laporan.keterangan}</p>
  67. </div>
  68. </td>
  69. <td className=" col-md-5">
  70. <div>
  71. <h4 className="m-0">{data.laporan.role_data === "dikti" ? "Ditindaklanjuti DIKTI" : "Delegasi Ke LLDIKTI"}</h4>
  72. {/* {data.pelanggaran.map((e) => (<h2 className="w-105">Sanksi Administratif: {e.label_sanksi}</h2>))} */}
  73. Sanksi Administratif : {getLabelSanksi(data.sanksi, "level") === 3 ? "Berat" : getLabelSanksi(data.sanksi, "level") === 2 ? "Sedang" : "Ringan"}
  74. </div>
  75. </td>
  76. {!noBy && <td>{data.user.isPrivate ? "" : data.user.nama}</td>}
  77. <td>
  78. <div className="ml-auto">
  79. <Link
  80. href={{
  81. pathname: to,
  82. query: { id: data._id },
  83. }}
  84. >
  85. <Button className="btn-login" color>
  86. <span className="font-color-white">
  87. {linkName}
  88. </span>
  89. </Button>
  90. </Link>
  91. </div>
  92. </td>
  93. </tr>
  94. );
  95. })}
  96. </tbody>
  97. </table>
  98. </Datatable>
  99. )}
  100. </div>
  101. </div>
  102. );
  103. }
  104. export default TableLaporan;