FPSMS-frontend
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

234 wiersze
6.7 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, arrayToDateTimeString } 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. type?: "dashboard" | "qc";
  23. items: EscalationResult[];
  24. };
  25. const EscalationLogTable: React.FC<Props> = ({
  26. type = "dashboard", items
  27. }) => {
  28. const { t } = useTranslation("dashboard");
  29. const CARD_HEADER = t("stock in escalation list")
  30. const pathname = usePathname();
  31. const router = useRouter();
  32. const [selectedId, setSelectedId] = useState<number | null>(null);
  33. const navigateTo = useCallback(
  34. (item: EscalationResult) => {
  35. setSelectedId(item.id);
  36. console.log(pathname)
  37. router.replace(`/po/edit?id=${item.poId}&polId=${item.polId}&stockInLineId=${item.stockInLineId}`);
  38. },
  39. [router, pathname]
  40. );
  41. const onRowClick = useCallback((item: EscalationResult) => {
  42. router.push(`/po/edit?id=${item.poId}&selectedIds=${item.poId}&polId=${item.polId}&stockInLineId=${item.stockInLineId}`);
  43. }, [router])
  44. // const handleKeyDown = useCallback(
  45. // (e: React.KeyboardEvent, item: EscalationResult) => {
  46. // if (e.key === 'Enter' || e.key === ' ') {
  47. // e.preventDefault();
  48. // navigateTo(item);
  49. // }
  50. // },
  51. // [navigateTo]
  52. // );
  53. const base_col = useMemo<Column<EscalationResult>[]>(
  54. () => [
  55. {
  56. name: "qcFailCount",
  57. label: t("QC Fail Count"),
  58. align: "right",
  59. headerAlign: "right",
  60. sx: { width: "10%", minWidth: 120 },
  61. renderCell: (params) => {
  62. return `${params.qcFailCount} / ${params.qcTotalCount}`
  63. }
  64. },
  65. {
  66. name: "reason",
  67. label: t("Reason"),
  68. sx: { width: "30%", minWidth: 150 },
  69. },
  70. {
  71. name: "status",
  72. label: t("escalationStatus"),
  73. sx: { width: "10%", minWidth: 150 },
  74. renderCell: (params) => {
  75. return t(params.status);
  76. // return t(`${params.status}`);
  77. }
  78. },
  79. ], [])
  80. const columns_dashboard = useMemo<Column<EscalationResult>[]>(
  81. () => [
  82. {
  83. name: "poCode",
  84. label: t("Po Code"),
  85. align: "left",
  86. headerAlign: "left",
  87. sx: { width: "15%", minWidth: 100 },
  88. },
  89. {
  90. name: "recordDate",
  91. label: t("escalated date"),
  92. align: "right",
  93. headerAlign: "right",
  94. sx: { width: "10%", minWidth: 100 },
  95. renderCell: (params) => {
  96. return arrayToDateString(params.recordDate);
  97. }
  98. },
  99. {
  100. name: "itemName",
  101. label: t("Item Name"),
  102. align: "left",
  103. headerAlign: "left",
  104. sx: { width: "15%", minWidth: 100 },
  105. },
  106. {
  107. name: "acceptedQty",
  108. label: t("Received Qty"),
  109. align: "right",
  110. headerAlign: "right",
  111. sx: { width: "5%", minWidth: 100 },
  112. },
  113. {
  114. name: "purchaseUomDesc",
  115. label: t("Purchase UoM"),
  116. sx: { width: "15%", minWidth: 120 },
  117. },
  118. {
  119. name: "dnDate",
  120. label: t("DN Date"),
  121. sx: { width: "10%", minWidth: 120 },
  122. renderCell: (params) => {
  123. return params.dnDate ? arrayToDateString(params.dnDate) : "N/A"
  124. }
  125. },
  126. ...base_col
  127. ], [])
  128. const columns_qc = useMemo<Column<EscalationResult>[]>(
  129. () => [
  130. {
  131. name: "handler",
  132. label: t("Responsible for handling colleagues"),
  133. sx: { width: "20%", minWidth: 200, maxWidth: 500 },
  134. renderCell: (params) => {
  135. const department = params.handlerDepartment;
  136. const name = params.handlerName;
  137. const title = params.handlerTitle;
  138. return (
  139. (department ? `${department} - ` : "") + name + (title ? ` (${title})` : "")
  140. );
  141. }
  142. },
  143. {
  144. name: "recordDate",
  145. label: t("escalated date"),
  146. align: "right",
  147. headerAlign: "right",
  148. sx: { width: "10%", minWidth: 100 },
  149. renderCell: (params) => {
  150. return arrayToDateString(params.recordDate);
  151. }
  152. },
  153. {
  154. name: "acceptedQty",
  155. label: t("Received Qty"),
  156. align: "right",
  157. headerAlign: "right",
  158. sx: { width: "5%", minWidth: 100 },
  159. },
  160. {
  161. name: "purchaseUomDesc",
  162. label: t("Purchase UoM"),
  163. sx: { width: "15%", minWidth: 120 },
  164. },
  165. ...base_col
  166. ], [])
  167. const getColumnByType = (type : Props['type']) => {
  168. switch (type) {
  169. case "qc": return columns_qc;
  170. default: return columns_dashboard;
  171. }
  172. }
  173. {/* return (
  174. <TableContainer component={Paper}>
  175. <Table aria-label="Two column navigable table" size="small">
  176. <TableHead>
  177. <TableRow>
  178. <TableCell>{t("Purchase Order Code")}</TableCell>
  179. <TableCell>{t("Item Name")}</TableCell>
  180. <TableCell>{t("Escalation Level")}</TableCell>
  181. <TableCell>{t("Reason")}</TableCell>
  182. </TableRow>
  183. </TableHead>
  184. <TableBody>
  185. {items.map((item) => {
  186. const selected = selectedId === item.id;
  187. return (
  188. <TableRow
  189. key={item.id}
  190. hover
  191. selected={selected}
  192. onClick={() => navigateTo(item)}
  193. // onKeyDown={(e) => handleKeyDown(e, item)}
  194. tabIndex={0}
  195. sx={{ cursor: 'pointer' }}
  196. // aria-label={`${item.name}, ${item.detail}`}
  197. >
  198. <TableCell component="th" scope="row">
  199. {item.poCode}
  200. </TableCell>
  201. <TableCell>{item.itemName}</TableCell>
  202. <TableCell>{item.escalationLevel}</TableCell>
  203. <TableCell>{item.reason}</TableCell>
  204. </TableRow>
  205. );
  206. })}
  207. </TableBody>
  208. </Table>
  209. </TableContainer>
  210. );*/}
  211. return (
  212. <SearchResults
  213. onRowClick={onRowClick}
  214. items={items}
  215. columns={getColumnByType(type)}
  216. isAutoPaging={false}
  217. />
  218. )
  219. };
  220. export default EscalationLogTable;