'use client' import * as React from 'react' import { useActionState } from 'react' import { useFormStatus } from 'react-dom' import { AlertCircle, ChevronDown } from 'lucide-react' import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert' import { Button } from '@/components/ui/button' import { Checkbox } from '@/components/ui/checkbox' import { Input } from '@/components/ui/input' import { Select } from '@/components/ui/select' import { Textarea } from '@/components/ui/textarea' import { Feld } from '@/components/feld' import { DAUER_SCHNELLWAHL, KONTAKT_ARTEN, KONTAKT_ARTEN_SCHNELLWAHL, KONTAKT_ART_BESCHRIFTUNG, } from '@/lib/validierung/kontakte' import { protokollSpeichern, type KontaktZustand } from '@/server/actions/kontakte' import { cn } from '@/lib/utils' /** * Die Schnellerfassung. * * Sie muss am Handy in unter 20 Sekunden zu bedienen sein - im Flur des * Pflegeheims, direkt nach dem Besuch, mit einer Hand. Deshalb: * * - Das Datum ist auf heute vorbelegt. * - Die Art ist eine Knopfreihe, kein Auswahlmenue. * - Die Dauer hat vier Schnellwahlen und daneben ein freies Feld. * - Ein Haekchen fuer den persoenlichen Kontakt - die Angabe, auf die es * im Jahresbericht nach § 1863 BGB ankommt. * - Ein grosses Freitextfeld. * * Alles Weitere steckt eingeklappt in "Weitere Angaben". Speichern ist der * einzige auffaellige Knopf auf der Seite. */ export type ProtokollWerte = { id: string datum: string art: string dauerMinuten: number | null gespraechspartner: string | null mitBetreuter: boolean kontaktId: string | null vorgangId: string | null inhalt: string | null wuensche: string | null folgeaufgaben: string | null } export type Auswahleintrag = { id: string; bezeichnung: string } const ANFANG: KontaktZustand = {} /** Die uebrigen Arten, die nicht in der grossen Reihe stehen. */ const WEITERE_ARTEN = KONTAKT_ARTEN.filter( (art) => !(KONTAKT_ARTEN_SCHNELLWAHL as readonly string[]).includes(art), ) export function ProtokollErfassung({ betreuteId, heute, kontakte, vorgaenge, protokoll, weiter, }: { betreuteId: string /** Vorbelegung fuer das Datumsfeld im Format JJJJ-MM-TT. */ heute: string kontakte: Auswahleintrag[] vorgaenge: Auswahleintrag[] protokoll?: ProtokollWerte /** Wohin nach dem Speichern? Muss ein Pfad dieser Anwendung sein. */ weiter?: string }) { const [zustand, aktion] = useActionState(protokollSpeichern, ANFANG) const vorgabeDauer = zustand.werte?.dauerMinuten ?? (protokoll?.dauerMinuten !== null && protokoll?.dauerMinuten !== undefined ? String(protokoll.dauerMinuten) : '') const [dauer, setDauer] = React.useState(vorgabeDauer) const vorgabeArt = zustand.werte?.art ?? protokoll?.art ?? 'BESUCH' const vorgabeDatum = zustand.werte?.datum ?? protokoll?.datum ?? heute const vorgabeMitBetreuter = zustand.werte !== undefined ? zustand.werte.mitBetreuter === 'on' : (protokoll?.mitBetreuter ?? false) const mehrOffen = Boolean( protokoll?.gespraechspartner || protokoll?.kontaktId || protokoll?.vorgangId || protokoll?.wuensche || protokoll?.folgeaufgaben || zustand.felder?.gespraechspartner || zustand.felder?.kontaktId || zustand.felder?.vorgangId, ) return (
{protokoll && } {weiter && } {zustand.fehler && ( )} {/* --- Datum ---------------------------------------------------------- */} {/* --- Art als Knopfreihe --------------------------------------------- */}
Wie fand der Kontakt statt?
{KONTAKT_ARTEN_SCHNELLWAHL.map((art) => ( ))}
{WEITERE_ARTEN.map((art) => ( ))}
{zustand.felder?.art && (

{zustand.felder.art}

)}
{/* --- Dauer ---------------------------------------------------------- */}
Wie lange? (optional)
{DAUER_SCHNELLWAHL.map((minuten) => { const gewaehlt = dauer === String(minuten) return ( ) })} setDauer(e.target.value)} aria-invalid={zustand.felder?.dauerMinuten ? true : undefined} />
{zustand.felder?.dauerMinuten && (

{zustand.felder.dauerMinuten}

)}
{/* --- Persoenlicher Kontakt ------------------------------------------ */} {/* --- Freitext -------------------------------------------------------- */}