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

73 lines
2.0 KiB
TypeScript

import React, { useMemo } from 'react';
import { NetworkDevice } from '../../types';
interface NetworkStatsProps {
devices: NetworkDevice[];
}
const StatCard: React.FC<{ label: string; value: string; icon: string; color: string }> = ({
label,
value,
icon,
color,
}) => (
<div className="bg-white p-4 rounded-lg shadow-sm flex items-center space-x-4">
<div className={`text-2xl p-3 rounded-full bg-opacity-10 ${color}`}>
<i className={`fa-solid ${icon}`}></i>
</div>
<div>
<p className="text-gray-600 text-sm font-medium">{label}</p>
<p className="text-2xl font-bold text-gray-800">{value}</p>
</div>
</div>
);
const NetworkStats: React.FC<NetworkStatsProps> = ({ devices }) => {
const stats = useMemo(() => {
const onlineDevices = devices.filter((d) => d.status === 'online');
const totalTraffic = onlineDevices.reduce((sum, d) => sum + d.trafficIn + d.trafficOut, 0);
const avgLatency =
onlineDevices.length > 0
? onlineDevices.reduce((sum, d) => sum + d.latency, 0) / onlineDevices.length
: 0;
return {
total: devices.length,
online: onlineDevices.length,
avgLatency: avgLatency.toFixed(1),
totalTraffic: totalTraffic.toFixed(2),
};
}, [devices]);
return (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<StatCard
label="Total Perangkat"
value={`${stats.total}`}
icon="fa-server"
color="text-blue-500 bg-blue-500"
/>
<StatCard
label="Perangkat Online"
value={`${stats.online}`}
icon="fa-circle-check"
color="text-green-500 bg-green-500"
/>
<StatCard
label="Latensi Rata-rata"
value={`${stats.avgLatency} ms`}
icon="fa-stopwatch"
color="text-yellow-500 bg-yellow-500"
/>
<StatCard
label="Total Lalu Lintas"
value={`${stats.totalTraffic} Mbps`}
icon="fa-exchange-alt"
color="text-purple-500 bg-purple-500"
/>
</div>
);
};
export default NetworkStats;