import { useEffect, useMemo, useState } from "react"; import { Modal, Box, Text, Flex, Button, ScrollArea, Checkbox, } from "@mantine/core"; import type { TLine, TStation } from "../../untils/types"; import type { Socket } from "socket.io-client"; interface Props { listLines: TLine[]; setListLines: (lines: React.SetStateAction) => void; socket: Socket | null; station: TStation | undefined; } interface PropsLines { id: number | undefined; checked: boolean; pid?: string; sn?: string; vid?: string; lineNumber?: number; } export default function ModalConfirmRunPhysical({ listLines, setListLines, socket, station, }: Props) { const user = useMemo(() => { return localStorage.getItem("user") && typeof localStorage.getItem("user") === "string" ? JSON.parse(localStorage.getItem("user") || "") : null; }, []); const [dataLines, setDataLines] = useState([]); const [isDisabled, setIsDisabled] = useState(false); useEffect(() => { if (listLines) { setDataLines(() => listLines .filter((line) => line.id) .map((line) => ({ id: line.id, lineNumber: line?.lineNumber, pid: line?.inventory?.pid, sn: line?.inventory?.sn, vid: line?.inventory?.vid, checked: true, })), ); } }, [listLines]); return ( 0} onClose={() => { setListLines([]); setDataLines([]); }} closeOnClickOutside={false} closeOnEscape={false} centered title="Confirm Run Test Ports" > {dataLines.map((line, i) => ( setDataLines( dataLines.map((el) => el.id === line.id ? { ...el, checked: e.target.checked, } : el, ), ) } /> Line: {line.lineNumber} PID: {line.pid || ""} SN: {line.sn || ""} VID: {line.vid || ""} ))} ); }