Files
dashboard/components/mobile/OperatorTasksScreen.tsx

84 lines
3.0 KiB
TypeScript

import React from 'react';
import { Alert, Screen, AlertSeverity } from '../../types';
import { MobileBottomNav } from './MobileLayout';
interface OperatorTasksScreenProps {
tasks: Alert[];
onNavigate: (screen: Screen) => void;
}
const getTaskFromAlert = (alert: Alert) => {
let taskTitle = 'Tugas Tidak Dikenal';
let icon = 'fa-question-circle';
const locationMatch = alert.message.match(/di (.*?)(?:\(|$)/);
const location = locationMatch?.[1]?.trim() || 'Lokasi tidak diketahui';
if (alert.message.toLowerCase().includes('mortalitas')) {
taskTitle = 'Tangani Mortalitas';
icon = 'fa-skull-crossbones text-red-600';
} else if (alert.message.toLowerCase().includes('kepadatan')) {
taskTitle = 'Periksa Kepadatan';
icon = 'fa-users text-yellow-600';
} else if (alert.message.toLowerCase().includes('suhu')) {
taskTitle = 'Cek Suhu Kandang';
icon = 'fa-temperature-high text-red-600';
} else if (alert.message.toLowerCase().includes('offline')) {
taskTitle = 'Periksa Sensor Offline';
icon = 'fa-satellite-dish text-yellow-600';
}
return { title: taskTitle, icon, location };
};
const TaskCard: React.FC<{ alert: Alert }> = ({ alert }) => {
const { title, icon, location } = getTaskFromAlert(alert);
const isCritical = alert.severity === AlertSeverity.CRITICAL;
return (
<div
className={`bg-white rounded-lg shadow-sm border-l-4 ${isCritical ? 'border-red-500' : 'border-yellow-500'}`}
>
<div className="p-3">
<div className="flex items-start space-x-3">
<i className={`fa-solid ${icon} text-xl w-6 text-center mt-1`}></i>
<div className="flex-grow">
<p className="font-bold text-gray-800">{title}</p>
<p className="text-xs text-gray-500">
<i className="fa-solid fa-location-dot mr-1.5"></i>
{location}
</p>
</div>
</div>
</div>
<div className="px-3 pb-2 flex justify-end">
<button className="text-xs bg-green-600 text-white font-semibold px-3 py-1 rounded-full hover:bg-green-700">
Selesai
</button>
</div>
</div>
);
};
const OperatorTasksScreen: React.FC<OperatorTasksScreenProps> = ({ tasks, onNavigate }) => (
<div className="bg-gray-50 h-full">
<div className="p-3 pt-8 h-full overflow-y-auto pb-16">
<h1 className="text-xl font-bold text-gray-800">Tugas Hari Ini</h1>
<p className="text-xs text-gray-500 mb-3">Tugas dibuat otomatis dari notifikasi kritis.</p>
<div className="space-y-3 mt-4">
{tasks.length > 0 ? (
tasks.map((task) => <TaskCard key={task.id} alert={task} />)
) : (
<div className="text-center text-gray-500 pt-16">
<i className="fa-solid fa-check-double text-4xl text-green-500"></i>
<p className="mt-2 font-semibold">Semua tugas selesai!</p>
</div>
)}
</div>
</div>
<MobileBottomNav active="home" onNavigate={onNavigate} />
</div>
);
export default OperatorTasksScreen;