98 lines
3.1 KiB
TypeScript
98 lines
3.1 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { VetVisit } from '../../types';
|
|
|
|
interface VisitNotesModalProps {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
visit: VetVisit;
|
|
onSave: (updatedVisit: VetVisit) => void;
|
|
}
|
|
|
|
const VisitNotesModal: React.FC<VisitNotesModalProps> = ({ isOpen, onClose, visit, onSave }) => {
|
|
const [notes, setNotes] = useState(visit.notes || '');
|
|
const [isEditing, setIsEditing] = useState(false);
|
|
|
|
const handleSave = () => {
|
|
onSave({ ...visit, notes });
|
|
setIsEditing(false);
|
|
};
|
|
|
|
if (!isOpen) return null;
|
|
|
|
return (
|
|
<div
|
|
className="fixed inset-0 bg-black bg-opacity-60 flex justify-center items-center z-50 p-4"
|
|
onClick={onClose}
|
|
>
|
|
<div
|
|
className="bg-white rounded-xl shadow-2xl w-full max-w-2xl"
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
<div className="p-6">
|
|
<div className="flex justify-between items-center mb-4">
|
|
<div>
|
|
<h2 className="text-2xl font-bold text-gray-800">Catatan Kunjungan</h2>
|
|
<p className="text-sm text-gray-500">
|
|
{visit.coopName} - {visit.scheduledTime.toLocaleDateString('id-ID')}
|
|
</p>
|
|
</div>
|
|
<button
|
|
type="button"
|
|
onClick={onClose}
|
|
className="text-gray-400 hover:text-gray-600 text-2xl"
|
|
>
|
|
×
|
|
</button>
|
|
</div>
|
|
<div className="bg-gray-50 p-4 rounded-lg min-h-[200px] max-h-[50vh] overflow-y-auto">
|
|
{isEditing ? (
|
|
<textarea
|
|
value={notes}
|
|
onChange={(e) => setNotes(e.target.value)}
|
|
className="w-full h-48 p-2 border border-gray-300 rounded-md"
|
|
/>
|
|
) : (
|
|
<p className="text-gray-700 whitespace-pre-wrap">{notes || 'Tidak ada catatan.'}</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<div className="bg-gray-100 px-6 py-4 rounded-b-xl flex justify-end space-x-3">
|
|
{isEditing ? (
|
|
<>
|
|
<button
|
|
onClick={() => setIsEditing(false)}
|
|
className="bg-gray-200 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-300 font-medium"
|
|
>
|
|
Batal
|
|
</button>
|
|
<button
|
|
onClick={handleSave}
|
|
className="bg-red-600 text-white px-4 py-2 rounded-lg hover:bg-red-700 font-medium shadow-sm"
|
|
>
|
|
Simpan Catatan
|
|
</button>
|
|
</>
|
|
) : (
|
|
<>
|
|
<button
|
|
onClick={() => setIsEditing(true)}
|
|
className="bg-white border border-gray-300 text-gray-800 px-4 py-2 rounded-lg hover:bg-gray-100 font-medium"
|
|
>
|
|
<i className="fa-solid fa-pencil mr-2"></i> Edit
|
|
</button>
|
|
<button
|
|
onClick={onClose}
|
|
className="bg-red-600 text-white px-4 py-2 rounded-lg hover:bg-red-700 font-medium"
|
|
>
|
|
Tutup
|
|
</button>
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default VisitNotesModal;
|