FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

151 lines
4.2 KiB

  1. "use client"
  2. import { Box, Card, CardActionArea, CardContent, CardHeader, Grid, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Typography } from "@mui/material";
  3. import { useRouter } from "next/navigation";
  4. import { useCallback, useMemo, useState } from "react";
  5. import { usePathname } from "next/navigation";
  6. import { useTranslation } from "react-i18next";
  7. import { EscalationResult } from "@/app/api/escalation";
  8. import { Column } from "@/components/SearchResults";
  9. import SearchResults from "@/components/SearchResults/SearchResults";
  10. import { arrayToDateString } from "@/app/utils/formatUtil";
  11. export type IQCItems = {
  12. id: number;
  13. poId: number;
  14. polId: number;
  15. stockInLineId: number;
  16. poCode: string
  17. itemName: string
  18. escalationLevel: string
  19. reason: string
  20. };
  21. type Props = {
  22. items: EscalationResult[];
  23. };
  24. const EscalationLogTable: React.FC<Props> = ({
  25. items
  26. }) => {
  27. const { t } = useTranslation("dashboard");
  28. const CARD_HEADER = t("stock in escalation list")
  29. const pathname = usePathname();
  30. const router = useRouter();
  31. const [selectedId, setSelectedId] = useState<number | null>(null);
  32. const navigateTo = useCallback(
  33. (item: EscalationResult) => {
  34. setSelectedId(item.id);
  35. console.log(pathname)
  36. router.replace(`/po/edit?id=${item.poId}&polId=${item.polId}&stockInLineId=${item.stockInLineId}`);
  37. },
  38. [router, pathname]
  39. );
  40. const onRowClick = useCallback((item: EscalationResult) => {
  41. router.push(`/po/edit?id=${item.poId}&selectedIds=${item.poId}&polId=${item.polId}&stockInLineId=${item.stockInLineId}`);
  42. }, [router])
  43. // const handleKeyDown = useCallback(
  44. // (e: React.KeyboardEvent, item: EscalationResult) => {
  45. // if (e.key === 'Enter' || e.key === ' ') {
  46. // e.preventDefault();
  47. // navigateTo(item);
  48. // }
  49. // },
  50. // [navigateTo]
  51. // );
  52. const columns = useMemo<Column<EscalationResult>[]>(
  53. () => [
  54. {
  55. name: "handler",
  56. label: t("Responsible for handling colleagues")
  57. },
  58. {
  59. name: "acceptedQty",
  60. label: t("Received Qty"),
  61. align: "right",
  62. headerAlign: "right"
  63. },
  64. {
  65. name: "purchaseUomDesc",
  66. label: t("Purchase UoM")
  67. },
  68. {
  69. name: "dnDate",
  70. label: t("DN Date"),
  71. renderCell: (params) => {
  72. return params.dnDate ? arrayToDateString(params.dnDate) : "N/A"
  73. }
  74. },
  75. {
  76. name: "qcTotalCount",
  77. label: t("QC Completed Count"),
  78. align: "right",
  79. headerAlign: "right"
  80. },
  81. {
  82. name: "qcFailCount",
  83. label: t("QC Fail Count"),
  84. align: "right",
  85. headerAlign: "right"
  86. },
  87. {
  88. name: "reason",
  89. label: t("Reason"),
  90. },
  91. ], [])
  92. {/* return (
  93. <TableContainer component={Paper}>
  94. <Table aria-label="Two column navigable table" size="small">
  95. <TableHead>
  96. <TableRow>
  97. <TableCell>{t("Purchase Order Code")}</TableCell>
  98. <TableCell>{t("Item Name")}</TableCell>
  99. <TableCell>{t("Escalation Level")}</TableCell>
  100. <TableCell>{t("Reason")}</TableCell>
  101. </TableRow>
  102. </TableHead>
  103. <TableBody>
  104. {items.map((item) => {
  105. const selected = selectedId === item.id;
  106. return (
  107. <TableRow
  108. key={item.id}
  109. hover
  110. selected={selected}
  111. onClick={() => navigateTo(item)}
  112. // onKeyDown={(e) => handleKeyDown(e, item)}
  113. tabIndex={0}
  114. sx={{ cursor: 'pointer' }}
  115. // aria-label={`${item.name}, ${item.detail}`}
  116. >
  117. <TableCell component="th" scope="row">
  118. {item.poCode}
  119. </TableCell>
  120. <TableCell>{item.itemName}</TableCell>
  121. <TableCell>{item.escalationLevel}</TableCell>
  122. <TableCell>{item.reason}</TableCell>
  123. </TableRow>
  124. );
  125. })}
  126. </TableBody>
  127. </Table>
  128. </TableContainer>
  129. );*/}
  130. return (
  131. <SearchResults
  132. onRowClick={onRowClick}
  133. items={items}
  134. columns={columns}
  135. isAutoPaging={false}
  136. />
  137. )
  138. };
  139. export default EscalationLogTable;