diff --git a/ApiCore-Frontend/src/app/(app)/colonies/[id]/colony-inspections.tsx b/ApiCore-Frontend/src/app/(app)/colonies/[id]/colony-inspections.tsx new file mode 100644 index 0000000..9e34cf8 --- /dev/null +++ b/ApiCore-Frontend/src/app/(app)/colonies/[id]/colony-inspections.tsx @@ -0,0 +1,53 @@ +"use client"; + +import Link from "next/link"; +import { useQuery } from "@tanstack/react-query"; +import { fetchColonyInspections } from "@/lib/inspections/api"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; + +export function ColonyInspectionsCard({ colonyId }: { colonyId: string }) { + const { data: inspections, isLoading } = useQuery({ + queryKey: ["colonies", colonyId, "inspections"], + queryFn: () => fetchColonyInspections(colonyId), + }); + + return ( + + + Durchsichten + + + + {isLoading ?

Lädt…

: null} + {!isLoading && (!inspections || inspections.length === 0) ? ( +

Noch keine Durchsicht dokumentiert.

+ ) : null} + {inspections?.map((inspection) => ( +
+

+ {new Date(inspection.date).toLocaleDateString("de-DE")} +

+

+ {inspection.colonyStrength !== null + ? `${inspection.colonyStrength} Waben` + : "Stärke unbekannt"} + {inspection.queenSeen !== null + ? ` · Königin ${inspection.queenSeen ? "gesehen" : "nicht gesehen"}` + : ""} +

+ {inspection.healthIssues ?

Gesundheit: {inspection.healthIssues}

: null} + {inspection.varroaIssues ?

Varroa: {inspection.varroaIssues}

: null} + {inspection.measures ?

Maßnahmen: {inspection.measures}

: null} +
+ ))} +
+
+ ); +} diff --git a/ApiCore-Frontend/src/app/(app)/colonies/[id]/page.tsx b/ApiCore-Frontend/src/app/(app)/colonies/[id]/page.tsx index 3edbaff..096d573 100644 --- a/ApiCore-Frontend/src/app/(app)/colonies/[id]/page.tsx +++ b/ApiCore-Frontend/src/app/(app)/colonies/[id]/page.tsx @@ -6,6 +6,7 @@ import { fetchColony } from "@/lib/colonies/api"; import { ColonyEditCard } from "./colony-edit-card"; import { ColonyActions } from "./colony-actions"; import { ColonyHistoryCard } from "./colony-history"; +import { ColonyInspectionsCard } from "./colony-inspections"; export default function ColonyDetailPage() { const params = useParams<{ id: string }>(); @@ -29,6 +30,7 @@ export default function ColonyDetailPage() {
+
); diff --git a/ApiCore-Frontend/src/app/(app)/inspections/new/page.tsx b/ApiCore-Frontend/src/app/(app)/inspections/new/page.tsx new file mode 100644 index 0000000..14ecbb9 --- /dev/null +++ b/ApiCore-Frontend/src/app/(app)/inspections/new/page.tsx @@ -0,0 +1,209 @@ +"use client"; + +import { FormEvent, useState } from "react"; +import { useRouter, useSearchParams } from "next/navigation"; +import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; +import { fetchColonies } from "@/lib/colonies/api"; +import { createInspection } from "@/lib/inspections/api"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Textarea } from "@/components/ui/textarea"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; + +function todayIsoDate(): string { + return new Date().toISOString().slice(0, 10); +} + +export default function NewInspectionPage() { + const router = useRouter(); + const searchParams = useSearchParams(); + const queryClient = useQueryClient(); + + const { data: colonies } = useQuery({ + queryKey: ["colonies"], + queryFn: fetchColonies, + }); + const activeColonies = colonies?.filter((colony) => colony.status === "ACTIVE") ?? []; + + const [colonyId, setColonyId] = useState(searchParams.get("colonyId") ?? ""); + const [date, setDate] = useState(todayIsoDate()); + const [colonyStrength, setColonyStrength] = useState(""); + const [queenSeen, setQueenSeen] = useState(false); + const [queenCellsPresent, setQueenCellsPresent] = useState(false); + const [feedStatusOk, setFeedStatusOk] = useState(true); + const [healthIssues, setHealthIssues] = useState(""); + const [varroaIssues, setVarroaIssues] = useState(""); + const [measures, setMeasures] = useState(""); + const [notes, setNotes] = useState(""); + const [error, setError] = useState(null); + + const mutation = useMutation({ + mutationFn: createInspection, + onSuccess: (inspection) => { + void queryClient.invalidateQueries({ + queryKey: ["colonies", inspection.colonyId, "inspections"], + }); + router.push(`/colonies/${inspection.colonyId}`); + }, + onError: () => { + setError("Durchsicht konnte nicht gespeichert werden."); + }, + }); + + function handleSubmit(event: FormEvent) { + event.preventDefault(); + setError(null); + if (!colonyId) { + setError("Bitte ein Volk auswählen."); + return; + } + mutation.mutate({ + colonyId, + date: new Date(date).toISOString(), + colonyStrength: colonyStrength ? Number(colonyStrength) : undefined, + queenSeen, + queenCellsPresent, + feedStatus: feedStatusOk ? "ausreichend" : "niedrig", + healthIssues: healthIssues || undefined, + varroaIssues: varroaIssues || undefined, + measures: measures || undefined, + notes: notes || undefined, + }); + } + + return ( +
+ + + Neue Durchsicht + + +
+
+ + +
+
+ + setDate(event.target.value)} + /> +
+
+ + setColonyStrength(event.target.value)} + /> +
+
+ + + +
+
+ + setVarroaIssues(event.target.value)} + /> +
+
+ + setHealthIssues(event.target.value)} + /> +
+
+ +