import Table from "@mui/material/Table"; import TableBody from "@mui/material/TableBody"; import TableCell from "@mui/material/TableCell"; import TableContainer from "@mui/material/TableContainer"; import TableHead from "@mui/material/TableHead"; import TableRow from "@mui/material/TableRow"; import Paper from "@mui/material/Paper"; import { Check, RotateCcw, Send, X } from "lucide-react"; import { authInstance, devicesStore, Modal, snapshotStore, vehicleStore, } from "@shared"; import { useEffect, useState } from "react"; import { observer } from "mobx-react-lite"; import { Button, Checkbox } from "@mui/material"; const formatDate = (dateString: string | undefined) => { if (!dateString) return "Нет данных"; try { const date = new Date(dateString); return new Intl.DateTimeFormat("ru-RU", { day: "2-digit", month: "2-digit", year: "numeric", hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false, }).format(date); } catch (error) { console.error("Error formatting date:", error); return "Некорректная дата"; } }; function createData( uuid: string, online: boolean, lastUpdate: string, gps: boolean, media: boolean, connection: boolean ) { return { uuid, online, lastUpdate, gps, media, connection }; } const rows = (devices: any[], vehicles: any[]) => { return devices.map((device) => { const { device_status } = vehicles.find( (v) => v?.device_status?.device_uuid === device ); const findVehicle = vehicles.find((v) => v?.vehicle?.uuid === device); console.log(findVehicle); return createData( findVehicle?.vehicle?.tail_number ?? "1243000", device_status?.online, device_status?.last_update, device_status?.gps_ok, device_status?.media_service_ok, device_status?.is_connected ); }); }; export const DevicesTable = observer(() => { const { devices, getDevices, uuid, setSelectedDevice, sendSnapshotModalOpen, toggleSendSnapshotModal, } = devicesStore; const { snapshots, getSnapshots } = snapshotStore; const { vehicles, getVehicles } = vehicleStore; const [selectedDevices, setSelectedDevices] = useState([]); useEffect(() => { const fetchData = async () => { await getVehicles(); await getDevices(); await getSnapshots(); }; fetchData(); }, []); const handleSendSnapshot = (uuid: string) => { setSelectedDevice(uuid); toggleSendSnapshotModal(); }; const handleReloadStatus = async (uuid: string) => { setSelectedDevice(uuid); await authInstance.post(`/devices/${uuid}/request-status`); await getDevices(); }; const handleSelectDevice = (event: React.ChangeEvent) => { if (event.target.checked) { setSelectedDevices([...selectedDevices, event.target.value]); } else { setSelectedDevices( selectedDevices.filter((device) => device !== event.target.value) ); } }; const handleSendSnapshotAction = async (uuid: string, snapshotId: string) => { await authInstance.post(`/devices/${uuid}/force-snapshot`, { snapshot_id: snapshotId, }); await getDevices(); }; return ( <>
Бортовой номер Онлайн Последнее обновление ГПС Медиа-данные Подключение Перезапросить {rows(devices, vehicles).map((row) => ( {row?.uuid} {row?.online ? ( ) : ( )} {formatDate(row?.lastUpdate)} {row?.gps ? ( ) : ( )} {row?.media ? ( ) : ( )} {row?.connection ? ( ) : ( )} ))}

Выбрать снапшот

{snapshots && snapshots.map((snapshot) => ( ))}
); });