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

65 lines
2.5 KiB
TypeScript

import React from 'react';
import { SensorWeightSummary } from '../../types.ts';
import { formatWeight } from '../../utils/weightUtils';
interface SensorWeightSummaryProps {
sensors: SensorWeightSummary[];
}
const SensorWeightSummaryComponent: React.FC<SensorWeightSummaryProps> = ({ sensors }) => {
return (
<div className="bg-white p-6 rounded-xl shadow-sm h-full flex flex-col">
<h2 className="text-xl font-bold mb-4">Statistik per Sensor Timbangan</h2>
{sensors.length > 0 ? (
<div className="space-y-3 overflow-y-auto flex-grow pr-2">
{sensors.map((sensor) => (
<div
key={sensor.device_id}
className="p-3 rounded-lg border border-gray-200 hover:border-red-300 hover:bg-gray-50/70 transition-all"
>
<div className="flex justify-between items-start mb-2">
<h3 className="font-semibold text-gray-800">{sensor.device_name}</h3>
</div>
<div className="grid grid-cols-2 gap-2 text-sm">
<div>
<span className="text-gray-500">Total Berat:</span>
<p className="font-semibold text-gray-800">
{formatWeight(sensor.total_weight_actual, { preservePrecision: true })}
</p>
</div>
<div>
<span className="text-gray-500">Jumlah Ayam:</span>
<p className="font-semibold text-gray-800">{sensor.chicken_count} ekor</p>
</div>
</div>
{/* Optional: Show average weight */}
<div className="mt-2 pt-2 border-t border-gray-100">
<span className="text-xs text-gray-500">Rata-rata: </span>
<span className="text-xs font-medium text-gray-700">
{formatWeight(sensor.avg_weight_actual, {
suffix: '/ekor',
preservePrecision: true,
})}
</span>
</div>
</div>
))}
</div>
) : (
<div className="flex-grow flex items-center justify-center">
<div className="text-center py-10">
<i className="fa-solid fa-scale-unbalanced-flip text-5xl text-gray-300 mb-3"></i>
<p className="text-gray-500">Tidak ada data sensor tersedia</p>
<p className="text-sm text-gray-400 mt-1">Pilih tanggal untuk melihat statistik</p>
</div>
</div>
)}
</div>
);
};
export default SensorWeightSummaryComponent;