110 lines
4.1 KiB
TypeScript
110 lines
4.1 KiB
TypeScript
import React from 'react';
|
|
import { VetVisit, VetVisitStatus } from '../../types';
|
|
|
|
interface VisitLogTableProps {
|
|
visits: VetVisit[];
|
|
onViewNotes: (visit: VetVisit) => void;
|
|
onEditVisit: (visit: VetVisit) => void;
|
|
selectedDate: Date | null;
|
|
onClearFilter: () => void;
|
|
}
|
|
|
|
const statusConfig: { [key in VetVisitStatus]: { text: string; color: string } } = {
|
|
Scheduled: { text: 'Terjadwal', color: 'bg-blue-100 text-blue-700' },
|
|
Completed: { text: 'Selesai', color: 'bg-green-100 text-green-700' },
|
|
Canceled: { text: 'Dibatalkan', color: 'bg-gray-200 text-gray-700' },
|
|
Missed: { text: 'Terlewat', color: 'bg-red-100 text-red-700' },
|
|
};
|
|
|
|
const VisitLogTable: React.FC<VisitLogTableProps> = ({
|
|
visits,
|
|
onViewNotes,
|
|
onEditVisit,
|
|
selectedDate,
|
|
onClearFilter,
|
|
}) => {
|
|
const sortedVisits = [...visits].sort(
|
|
(a, b) => b.scheduledTime.getTime() - a.scheduledTime.getTime()
|
|
);
|
|
|
|
return (
|
|
<div className="bg-white p-6 rounded-xl shadow-sm">
|
|
<div className="flex justify-between items-center mb-4">
|
|
<h2 className="text-xl font-bold text-gray-800">
|
|
{selectedDate
|
|
? `Kunjungan pada ${selectedDate.toLocaleDateString('id-ID')}`
|
|
: 'Log Riwayat Kunjungan'}
|
|
</h2>
|
|
{selectedDate && (
|
|
<button onClick={onClearFilter} className="text-sm text-blue-600 hover:underline">
|
|
Tampilkan Semua
|
|
</button>
|
|
)}
|
|
</div>
|
|
<div className="overflow-x-auto">
|
|
<table className="min-w-full text-sm">
|
|
<thead className="bg-gray-100 text-left text-gray-600">
|
|
<tr>
|
|
<th className="p-3 font-semibold">Tanggal & Waktu</th>
|
|
<th className="p-3 font-semibold">Kandang</th>
|
|
<th className="p-3 font-semibold">Dokter Hewan</th>
|
|
<th className="p-3 font-semibold">Status</th>
|
|
<th className="p-3 font-semibold text-right">Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody className="divide-y divide-gray-100">
|
|
{sortedVisits.map((visit) => {
|
|
const config = statusConfig[visit.status];
|
|
return (
|
|
<tr key={visit.id} className="hover:bg-gray-50">
|
|
<td className="p-3 text-gray-700">
|
|
{visit.scheduledTime.toLocaleString('id-ID', {
|
|
dateStyle: 'medium',
|
|
timeStyle: 'short',
|
|
})}
|
|
</td>
|
|
<td className="p-3 font-semibold text-gray-800">{visit.coopName}</td>
|
|
<td className="p-3 text-gray-600">{visit.vetName}</td>
|
|
<td className="p-3">
|
|
<span
|
|
className={`px-2 py-0.5 rounded-full font-medium text-xs ${config.color}`}
|
|
>
|
|
{config.text}
|
|
</span>
|
|
</td>
|
|
<td className="p-3 text-right space-x-3">
|
|
{visit.notes && (
|
|
<button
|
|
onClick={() => onViewNotes(visit)}
|
|
className="text-blue-600 hover:text-blue-800 font-semibold"
|
|
title="Lihat Catatan"
|
|
>
|
|
<i className="fa-solid fa-file-alt"></i>
|
|
</button>
|
|
)}
|
|
<button
|
|
onClick={() => onEditVisit(visit)}
|
|
className="text-gray-500 hover:text-gray-800 font-semibold"
|
|
title="Edit Kunjungan"
|
|
>
|
|
<i className="fa-solid fa-pencil"></i>
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
);
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
{sortedVisits.length === 0 && (
|
|
<div className="text-center py-10 text-gray-500">
|
|
<i className="fa-solid fa-calendar-times text-3xl text-gray-300"></i>
|
|
<p className="mt-2">Tidak ada kunjungan untuk tanggal yang dipilih.</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default VisitLogTable;
|