import { Space, Table, Tooltip } from "antd"; import moment from "moment"; import { useCompanyData } from "../../Hooks/Companies"; import { useCustomerData } from "../../Hooks/Customers"; import { useUserData } from "../../Hooks/Users"; import { updateController } from "../../API/LayoutApi/update"; import { QueryObserverResult, RefetchOptions, RefetchQueryFilters, } from "react-query"; import { TUpdate } from "../../types/Update/TUpdate"; import { useEffect, useState } from "react"; // @ts-ignore import tagIcon from "../../assets/tagIcon.png"; // @ts-ignore import pin from "../../assets/pinicon.png"; // @ts-ignore import unpin from "../../assets/unpinicon.png"; // @ts-ignore import zippy from "../../assets/zippyicon.svg"; // @ts-ignore import evo from "../../assets/evoicon.png"; // @ts-ignore import zeelog from "../../assets/zeelogicon.svg"; // @ts-ignore import ontime from "../../assets/ontimeicon.svg"; // @ts-ignore import tt from "../../assets/tticon.svg"; const UpdateTable = ({ data = [], isLoading, refetch, }: { data: TUpdate[] | undefined; isLoading?: boolean; refetch: ( options?: (RefetchOptions & RefetchQueryFilters) | undefined ) => Promise>; }) => { const CompanyData = useCompanyData({}); const CustomerData = useCustomerData({}); const AdminData = useUserData({}); const [isTextSelected, setIsTextSelected] = useState(false); useEffect(() => { const handleSelectionChange = () => { const selection = window.getSelection(); setIsTextSelected(selection !== null && selection.toString() !== ""); }; document.addEventListener("selectionchange", handleSelectionChange); return () => { document.removeEventListener("selectionchange", handleSelectionChange); }; }, []); const Row = (record: TUpdate, event: any) => { if (isTextSelected) { return; } if (event.target.classList.contains("ant-table-cell")) { document.location.replace(`/#/updates/${record.id}`); } }; const getImageSource = (source: string) => { switch (source) { case "Zippy": return zippy; case "EVO": return evo; case "Ontime": return ontime; case "Zeelog": return zeelog; case "TT": return tt; default: return tt; } }; return (
({ onClick: (event) => Row(record, event), })} dataSource={data?.map((u, i) => ({ no: i + 1, ...u, company_name: CompanyData?.data?.find( (company: any) => company.id === u.company_id )?.name, customer_name: CustomerData?.data?.find( (customer: any) => customer.id === u.customer_id )?.name, in_charge_name: AdminData?.data?.find( (admin: any) => admin.id === u.provider_id )?.username, executor_name: AdminData?.data?.find( (admin: any) => admin.id === u.executor_id )?.username, created: moment(u?.created_at, "YYYY-MM-DD HH:mm:ss").format( "DD.MM.YYYY HH:mm" ), action: { ...u }, }))} columns={[ { title: , dataIndex: "no", width: "4%", }, { title: "Company", dataIndex: "company", ellipsis: { showTitle: false, }, width: "10%", render: (text: any, record: any) => (
{text?.source && ( )} {text?.name}
), }, { title: "Driver", dataIndex: "customer", ellipsis: { showTitle: false, }, width: "10%", render: (item: { name: string }) => ( {item?.name} ), }, { title: "Created by", dataIndex: "provider ", ellipsis: { showTitle: false, }, responsive: ["xl"], width: "10%", render: (note: string) => ( {note} ), }, { title: "Completed by", dataIndex: "executor", ellipsis: { showTitle: false, }, responsive: ["lg"], width: "10%", render: (note: string) => ( {note} ), }, { title: "Status", dataIndex: "status", ellipsis: { showTitle: false, }, width: "10%", render: (status: string) => ( {status === "Done" &&

Done

} {status === "Checking" && (

Checking

)} {status === "New" &&

New

} {status === "Setup" &&

Setup

} {status === "Paper" &&

Paper

}
), }, { title: "Note", dataIndex: "note", width: "10%", ellipsis: { showTitle: false, }, render: (note: string) => ( {note} ), }, { title: "Solution", dataIndex: "solution", width: "10%", responsive: ["lg"], ellipsis: { showTitle: false, }, render: (note: string) => ( {note} ), }, { title: "Created at", dataIndex: "created", ellipsis: { showTitle: false, }, responsive: ["xxl"], width: "10%", render: (note: string) => ( {note} ), }, { title: "Actions", dataIndex: "action", width: "8%", render: (record: TUpdate) => { return (
{record.status !== "Done" && ( {record.is_pinned ? ( ) : ( )} )}
); }, }, ]} rowClassName={(record, index) => index % 2 === 0 ? "odd-row" : "even-row" } loading={isLoading} size="small" /> ); }; export default UpdateTable;