"use client" import { Box, Card, CardActionArea, CardContent, CardHeader, Grid, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Typography } from "@mui/material"; import { useRouter } from "next/navigation"; import { useCallback, useMemo, useState } from "react"; import { usePathname } from "next/navigation"; import { useTranslation } from "react-i18next"; import { EscalationResult } from "@/app/api/escalation"; import { Column } from "@/components/SearchResults"; import SearchResults from "@/components/SearchResults/SearchResults"; import { arrayToDateString, arrayToDateTimeString } from "@/app/utils/formatUtil"; export type IQCItems = { id: number; poId: number; polId: number; stockInLineId: number; poCode: string itemName: string escalationLevel: string reason: string }; type Props = { type?: "dashboard" | "qc"; items: EscalationResult[]; }; const EscalationLogTable: React.FC = ({ type = "dashboard", items }) => { const { t } = useTranslation("dashboard"); const CARD_HEADER = t("stock in escalation list") const pathname = usePathname(); const router = useRouter(); const [selectedId, setSelectedId] = useState(null); const navigateTo = useCallback( (item: EscalationResult) => { setSelectedId(item.id); console.log(pathname) router.replace(`/po/edit?id=${item.poId}&polId=${item.polId}&stockInLineId=${item.stockInLineId}`); }, [router, pathname] ); const onRowClick = useCallback((item: EscalationResult) => { router.push(`/po/edit?id=${item.poId}&selectedIds=${item.poId}&polId=${item.polId}&stockInLineId=${item.stockInLineId}`); }, [router]) // const handleKeyDown = useCallback( // (e: React.KeyboardEvent, item: EscalationResult) => { // if (e.key === 'Enter' || e.key === ' ') { // e.preventDefault(); // navigateTo(item); // } // }, // [navigateTo] // ); const base_col = useMemo[]>( () => [ { name: "qcFailCount", label: t("QC Fail Count"), align: "right", headerAlign: "right", sx: { width: "10%", minWidth: 120 }, renderCell: (params) => { return `${params.qcFailCount} / ${params.qcTotalCount}` } }, { name: "reason", label: t("Reason"), sx: { width: "30%", minWidth: 150 }, }, { name: "status", label: t("escalationStatus"), sx: { width: "10%", minWidth: 150 }, renderCell: (params) => { return t(params.status); // return t(`${params.status}`); } }, ], []) const columns_dashboard = useMemo[]>( () => [ { name: "poCode", label: t("Po Code"), align: "left", headerAlign: "left", sx: { width: "15%", minWidth: 100 }, }, { name: "recordDate", label: t("escalated date"), align: "right", headerAlign: "right", sx: { width: "10%", minWidth: 100 }, renderCell: (params) => { return arrayToDateString(params.recordDate); } }, { name: "itemName", label: t("Item Name"), align: "left", headerAlign: "left", sx: { width: "15%", minWidth: 100 }, }, { name: "acceptedQty", label: t("Received Qty"), align: "right", headerAlign: "right", sx: { width: "5%", minWidth: 100 }, }, { name: "purchaseUomDesc", label: t("Purchase UoM"), sx: { width: "15%", minWidth: 120 }, }, { name: "dnDate", label: t("DN Date"), sx: { width: "10%", minWidth: 120 }, renderCell: (params) => { return params.dnDate ? arrayToDateString(params.dnDate) : "N/A" } }, ...base_col ], []) const columns_qc = useMemo[]>( () => [ { name: "handler", label: t("Responsible for handling colleagues"), sx: { width: "20%", minWidth: 200, maxWidth: 500 }, renderCell: (params) => { const department = params.handlerDepartment; const name = params.handlerName; const title = params.handlerTitle; return ( (department ? `${department} - ` : "") + name + (title ? ` (${title})` : "") ); } }, { name: "recordDate", label: t("escalated date"), align: "right", headerAlign: "right", sx: { width: "10%", minWidth: 100 }, renderCell: (params) => { return arrayToDateString(params.recordDate); } }, { name: "acceptedQty", label: t("Received Qty"), align: "right", headerAlign: "right", sx: { width: "5%", minWidth: 100 }, }, { name: "purchaseUomDesc", label: t("Purchase UoM"), sx: { width: "15%", minWidth: 120 }, }, ...base_col ], []) const getColumnByType = (type : Props['type']) => { switch (type) { case "qc": return columns_qc; default: return columns_dashboard; } } {/* return ( {t("Purchase Order Code")} {t("Item Name")} {t("Escalation Level")} {t("Reason")} {items.map((item) => { const selected = selectedId === item.id; return ( navigateTo(item)} // onKeyDown={(e) => handleKeyDown(e, item)} tabIndex={0} sx={{ cursor: 'pointer' }} // aria-label={`${item.name}, ${item.detail}`} > {item.poCode} {item.itemName} {item.escalationLevel} {item.reason} ); })}
);*/} return ( ) }; export default EscalationLogTable;