import React from 'react' import { Skeleton } from '../../molecules/Skeleton' import { getPlatformIcon, prioritizeCurrentDevice } from './helpers' import { Divider, Text } from '../../atoms' import { getGlobalStyle } from '../../../utils' import styles from './styles.module.css' /** * Device interface aligned with backend GraphQL schema */ interface Device { dId: string deviceId: string deviceName: string platform: string shortName?: string | null locationFormat?: string | null family?: string | null os?: string | null model?: string | null ip?: string | null isBot?: boolean | null dState: number userId: string locationFormation?: string | null createdAt: string updatedAt: string } interface IDevicesProps { data: Device[] deviceId: string | null loading: boolean } /** * Format date into a human-readable string * @param {string} date - ISO date string * @returns {string} Formatted date */ const formatDate = (date: string): string => { try { return new Intl.DateTimeFormat('es-ES', { dateStyle: 'short', timeStyle: 'short' }).format(new Date(date)) } catch { return date } } /** * DeviceCard component to display a single device * @param {Device} device - Device object * @param {string | null} currentDeviceId - ID of current device * @returns {JSX.Element} Rendered device card */ const DeviceCard: React.FC<{ device: Device, currentDeviceId: string | null }> = ({ device, currentDeviceId }) => (
  • {getPlatformIcon(device.platform as 'win32' | 'Tablet' | 'Mobile' | 'Unknown')}
    {device.deviceName} - {device.platform} {currentDeviceId === device.deviceId && ( Dispositivo actual )}
    {/* Device details */} {(typeof device.shortName === 'string' && device.shortName.trim() !== '') && ( {device.shortName} )} {(typeof device.locationFormat === 'string' && device.locationFormat.trim() !== '') && ( {device.locationFormat} )} {(typeof device.family === 'string' && device.family.trim() !== '') && ( Familia: {device.family} )} {(typeof device.model === 'string' && device.model.trim() !== '') && ( Modelo: {device.model} )} {(typeof device.os === 'string' && device.os.trim() !== '') && ( OS: {device.os} )} {(typeof device.ip === 'string' && device.ip.trim() !== '') && ( IP: {device.ip} )} {device.isBot === true && 🤖 Bot detectado} {formatDate(device.createdAt)}
  • ) /** * Devices component to display a list of devices. * * @param {Array} data - Array of device objects. * @param {string|null} deviceId - ID of the current device. * @param {boolean} loading - Loading state for the component. * @returns {JSX.Element} Rendered Devices component. */ export const Devices: React.FC = ({ data = [], deviceId = null, loading = false }) => { if (loading) { return (
    ) } const prioritizedData = prioritizeCurrentDevice(data, deviceId ?? '') return ( ) }