import { Marker, Popup } from 'react-leaflet' import L from 'leaflet' import { Link } from '@tanstack/react-router' import type { FleetDevice } from '@/lib/api' import { formatUptime } from '@/lib/utils' interface DeviceMarkerProps { device: FleetDevice tenantId: string } const STATUS_COLORS: Record = { online: '#22c55e', // green-500 offline: '#ef4444', // red-500 unknown: '#eab308', // yellow-500 } function getStatusColor(status: string): string { return STATUS_COLORS[status] ?? STATUS_COLORS.unknown } function createMarkerIcon(status: string): L.DivIcon { const color = getStatusColor(status) return L.divIcon({ className: '', // Remove default leaflet-div-icon styling html: `
`, iconSize: [14, 14], iconAnchor: [7, 7], popupAnchor: [0, -10], }) } const statusLabels: Record = { online: 'Online', offline: 'Offline', unknown: 'Unknown', } export function DeviceMarker({ device, tenantId }: DeviceMarkerProps) { if (device.latitude == null || device.longitude == null) return null const icon = createMarkerIcon(device.status) const statusColor = getStatusColor(device.status) const statusLabel = statusLabels[device.status] ?? device.status // In super_admin "all" mode, tenantId may be empty — fall back to device's own tenant_id const resolvedTenantId = tenantId || device.tenant_id return (
{device.hostname}
IP: {device.ip_address}
{device.model &&
Model: {device.model}
}
Uptime: {formatUptime(device.uptime_seconds)}
Status: {statusLabel}
View Details → Config Editor →
) }