'use client'; /** * LogForm Component * E3.S2: Quick entry form met categorie, tijd, tekst en overdracht checkbox */ import { useState, useTransition } from 'react'; import { format } from 'date-fns'; import { Loader2, Plus, Pill, Utensils, User, AlertTriangle, FileText, } from 'lucide-react'; import { NURSING_LOG_CATEGORIES, CATEGORY_CONFIG, type NursingLogCategory, } from '@/lib/types/nursing-log'; interface LogFormProps { patientId: string; onSuccess: () => void; } // Icon mapping const CATEGORY_ICONS: Record> = { medicatie: Pill, adl: Utensils, gedrag: User, incident: AlertTriangle, observatie: FileText, }; export function LogForm({ patientId, onSuccess }: LogFormProps) { const [category, setCategory] = useState('observatie'); const [content, setContent] = useState(''); const [time, setTime] = useState(format(new Date(), 'HH:mm')); const [includeInHandover, setIncludeInHandover] = useState(false); const [error, setError] = useState(null); const [isPending, startTransition] = useTransition(); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (!content.trim()) { setError('Vul een notitie in'); return; } if (content.length > 500) { setError('Notitie mag maximaal 500 karakters bevatten'); return; } setError(null); // Build timestamp from date and time const today = new Date(); const [hours, minutes] = time.split(':').map(Number); today.setHours(hours, minutes, 0, 0); const timestamp = today.toISOString(); startTransition(async () => { try { const response = await fetch('/api/nursing-logs', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ patient_id: patientId, category, content: content.trim(), timestamp, include_in_handover: includeInHandover, }), }); if (!response.ok) { const data = await response.json(); throw new Error(data.error || 'Opslaan mislukt'); } // Reset form setContent(''); setTime(format(new Date(), 'HH:mm')); setIncludeInHandover(false); setCategory('observatie'); onSuccess(); } catch (err) { console.error('Failed to create log:', err); setError(err instanceof Error ? err.message : 'Opslaan mislukt'); } }); }; const charactersLeft = 500 - content.length; const selectedConfig = CATEGORY_CONFIG[category]; return (

Nieuwe notitie

{/* Category Selection */}
{NURSING_LOG_CATEGORIES.map((cat) => { const config = CATEGORY_CONFIG[cat]; const Icon = CATEGORY_ICONS[cat]; const isSelected = category === cat; return ( ); })}
{/* Time Input */}
setTime(e.target.value)} className="w-full sm:w-32 rounded-lg border border-slate-200 px-3 py-2 text-sm focus:border-teal-500 focus:ring-2 focus:ring-teal-100 outline-none" />
{/* Content Textarea */}