Files
Alberto-Audrix 32a36cceff
CI / lint-and-test (push) Canceled after 0s
first commit
2026-07-28 08:55:05 +07:00

96 lines
3.7 KiB
TypeScript

import React from 'react';
import { NetworkDevice, NetworkDeviceType } from '../../types';
const deviceConfig: { [key in NetworkDeviceType]: { icon: string; color: string } } = {
[NetworkDeviceType.ROUTER]: { icon: 'fa-route', color: 'text-blue-500' },
[NetworkDeviceType.SWITCH]: { icon: 'fa-network-wired', color: 'text-green-600' },
[NetworkDeviceType.ACCESS_POINT]: { icon: 'fa-wifi', color: 'text-purple-500' },
};
const statusConfig: {
[key in NetworkDevice['status']]: { text: string; bg: string; pulse: boolean };
} = {
online: { text: 'Online', bg: 'bg-green-500', pulse: true },
offline: { text: 'Offline', bg: 'bg-red-500', pulse: false },
degraded: { text: 'Terdegradasi', bg: 'bg-yellow-500', pulse: true },
};
const Stat: React.FC<{ icon: string; value: string; label: string }> = ({ icon, value, label }) => (
<div className="flex items-center space-x-2">
<i className={`fa-solid ${icon} text-gray-400 w-4 text-center`}></i>
<span className="text-xs text-gray-500">{label}:</span>
<span className="text-xs font-semibold text-gray-700">{value}</span>
</div>
);
const BandwidthBar: React.FC<{ usage: number }> = ({ usage }) => {
const color = usage > 90 ? 'bg-red-500' : usage > 75 ? 'bg-yellow-500' : 'bg-green-500';
return (
<div className="w-full bg-gray-200 rounded-full h-2.5">
<div className={`${color} h-2.5 rounded-full`} style={{ width: `${usage}%` }}></div>
</div>
);
};
interface NetworkDeviceCardProps {
device: NetworkDevice;
locationName: string;
}
const NetworkDeviceCard: React.FC<NetworkDeviceCardProps> = ({ device, locationName }) => {
const config = deviceConfig[device.type];
const status = statusConfig[device.status];
return (
<div className="bg-gray-50 rounded-lg shadow-sm border border-gray-200 p-4 space-y-3">
<div className="flex justify-between items-start">
<div>
<h4 className="font-bold text-gray-800 truncate" title={device.name}>
{device.name}
</h4>
<p className={`text-sm font-semibold ${config.color}`}>{device.type}</p>
</div>
<span
className={`flex items-center text-xs font-semibold text-white px-2 py-0.5 rounded-full ${status.bg}`}
>
{status.pulse && (
<span
className={`w-2 h-2 rounded-full mr-1.5 bg-white/70 ${device.status === 'degraded' ? 'animate-ping' : 'animate-pulse'}`}
></span>
)}
{status.text}
</span>
</div>
<div className="text-xs text-gray-600 space-y-1 bg-white p-2 rounded-md">
<p title={locationName}>
<i className="fa-solid fa-location-dot w-4 text-gray-400"></i> {locationName}
</p>
<p>
<i className="fa-solid fa-network-wired w-4 text-gray-400"></i> {device.ipAddress}
</p>
<p>
<i className="fa-solid fa-fingerprint w-4 text-gray-400"></i> {device.macAddress}
</p>
</div>
<div className="grid grid-cols-2 gap-2 pt-2 border-t">
<Stat icon="fa-stopwatch" label="Latensi" value={`${device.latency} ms`} />
<Stat icon="fa-arrow-down" label="Traffic In" value={`${device.trafficIn} Mbps`} />
<Stat icon="fa-clock" label="Uptime" value={device.uptime} />
<Stat icon="fa-arrow-up" label="Traffic Out" value={`${device.trafficOut} Mbps`} />
</div>
<div className="pt-2">
<div className="flex justify-between items-center mb-1">
<p className="text-xs font-medium text-gray-600">Penggunaan Bandwidth</p>
<p className="text-xs font-bold text-gray-800">{device.bandwidthUsage}%</p>
</div>
<BandwidthBar usage={device.bandwidthUsage} />
</div>
</div>
);
};
export default NetworkDeviceCard;