diff --git a/src/features/kontakte/components/contact-card.tsx b/src/features/kontakte/components/contact-card.tsx new file mode 100644 index 0000000..9861f9a --- /dev/null +++ b/src/features/kontakte/components/contact-card.tsx @@ -0,0 +1,56 @@ +import { Badge } from "@/shared/components/ui/badge"; +import { Card, CardContent } from "@/shared/components/ui/card"; +import type { KontaktErgebnis } from "@/shared/db/schema"; +import { ERGEBNIS_LABELS } from "@/shared/lib/constants"; + +interface ContactCardProps { + id: number; + name: string; + stadt: string | null; + letzterKontakt: string | null; + letztesErgebnis: string | null; + kontakteGesamt: number; +} + +const ergebnisVariant: Record< + KontaktErgebnis, + "default" | "secondary" | "destructive" | "outline" +> = { + zusage: "default", + warteliste: "secondary", + absage: "destructive", + keine_antwort: "outline", +}; + +export function ContactCard({ + name, + stadt, + letzterKontakt, + letztesErgebnis, + kontakteGesamt, +}: ContactCardProps) { + return ( + + +
+

{name}

+ {stadt &&

{stadt}

} +

+ {kontakteGesamt} Kontakt{kontakteGesamt !== 1 ? "e" : ""} + {letzterKontakt && <> · Letzter: {letzterKontakt}} +

+
+ {letztesErgebnis && ( + + {ERGEBNIS_LABELS[letztesErgebnis as KontaktErgebnis] ?? + letztesErgebnis} + + )} +
+
+ ); +} diff --git a/src/features/kontakte/components/contact-form.tsx b/src/features/kontakte/components/contact-form.tsx new file mode 100644 index 0000000..b82f610 --- /dev/null +++ b/src/features/kontakte/components/contact-form.tsx @@ -0,0 +1,249 @@ +import { useForm } from "@tanstack/react-form"; +import { Link, useNavigate } from "@tanstack/react-router"; +import { createKontakt, createTherapeut } from "@/features/kontakte/hooks"; +import { Button } from "@/shared/components/ui/button"; +import { Separator } from "@/shared/components/ui/separator"; +import type { KontaktErgebnis, KontaktKanal } from "@/shared/db/schema"; +import { kontaktErgebnisEnum, kontaktKanalEnum } from "@/shared/db/schema"; +import { ERGEBNIS_LABELS, KANAL_LABELS } from "@/shared/lib/constants"; + +function todayISO() { + const d = new Date(); + const y = d.getFullYear(); + const m = String(d.getMonth() + 1).padStart(2, "0"); + const day = String(d.getDate()).padStart(2, "0"); + return `${y}-${m}-${day}`; +} + +export function ContactForm() { + const navigate = useNavigate(); + + const form = useForm({ + defaultValues: { + name: "", + stadt: "", + telefon: "", + email: "", + datum: todayISO(), + kanal: "telefon" as KontaktKanal, + ergebnis: "keine_antwort" as KontaktErgebnis, + notiz: "", + }, + onSubmit: async ({ value }) => { + if (!value.name.trim()) return; + + const therapeutId = await createTherapeut({ + name: value.name.trim(), + adresse: "", + plz: "", + stadt: value.stadt.trim(), + telefon: value.telefon.trim(), + email: value.email.trim(), + website: "", + therapieform: "", + }); + + await createKontakt({ + therapeut_id: therapeutId, + datum: value.datum, + kanal: value.kanal, + ergebnis: value.ergebnis, + notiz: value.notiz.trim() || "", + }); + + navigate({ to: "/kontakte" }); + }, + }); + + const inputClasses = + "flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"; + + return ( +
{ + e.preventDefault(); + e.stopPropagation(); + form.handleSubmit(); + }} + className="space-y-6" + > +

Neuer Kontakt

+ +
+

Therapeut:in

+ + + {(field) => ( +
+ + field.handleChange(e.target.value)} + onBlur={field.handleBlur} + /> +
+ )} +
+ + + {(field) => ( +
+ + field.handleChange(e.target.value)} + onBlur={field.handleBlur} + /> +
+ )} +
+ + + {(field) => ( +
+ + field.handleChange(e.target.value)} + onBlur={field.handleBlur} + /> +
+ )} +
+ + + {(field) => ( +
+ + field.handleChange(e.target.value)} + onBlur={field.handleBlur} + /> +
+ )} +
+
+ + + +
+

Kontaktversuch

+ + + {(field) => ( +
+ + field.handleChange(e.target.value)} + onBlur={field.handleBlur} + /> +
+ )} +
+ + + {(field) => ( +
+ + +
+ )} +
+ + + {(field) => ( +
+ + +
+ )} +
+ + + {(field) => ( +
+ +