diff --git a/ApiCore-Frontend/proxy.ts b/ApiCore-Frontend/proxy.ts index 60d2189..970ac5e 100644 --- a/ApiCore-Frontend/proxy.ts +++ b/ApiCore-Frontend/proxy.ts @@ -22,5 +22,5 @@ export function proxy(request: NextRequest) { } export const config = { - matcher: ["/login", "/settings/:path*"], + matcher: ["/login", "/settings/:path*", "/apiaries/:path*"], }; diff --git a/ApiCore-Frontend/src/app/(app)/apiaries/[id]/apiary-edit-card.tsx b/ApiCore-Frontend/src/app/(app)/apiaries/[id]/apiary-edit-card.tsx new file mode 100644 index 0000000..3fd30e3 --- /dev/null +++ b/ApiCore-Frontend/src/app/(app)/apiaries/[id]/apiary-edit-card.tsx @@ -0,0 +1,111 @@ +"use client"; + +import { FormEvent, useState } from "react"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { deactivateApiary, updateApiary } from "@/lib/apiaries/api"; +import { Apiary } from "@/lib/apiaries/types"; +import { Button } from "@/components/ui/button"; +import { Badge } from "@/components/ui/badge"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Textarea } from "@/components/ui/textarea"; +import { + Card, + CardContent, + CardHeader, + CardTitle, +} from "@/components/ui/card"; + +export function ApiaryEditCard({ apiary }: { apiary: Apiary }) { + const queryClient = useQueryClient(); + const [name, setName] = useState(apiary.name); + const [location, setLocation] = useState(apiary.location ?? ""); + const [address, setAddress] = useState(apiary.address ?? ""); + const [notes, setNotes] = useState(apiary.notes ?? ""); + + const updateMutation = useMutation({ + mutationFn: () => + updateApiary(apiary.id, { + name, + location: location || undefined, + address: address || undefined, + notes: notes || undefined, + }), + onSuccess: () => { + void queryClient.invalidateQueries({ queryKey: ["apiaries"] }); + }, + }); + + const deactivateMutation = useMutation({ + mutationFn: () => deactivateApiary(apiary.id), + onSuccess: () => { + void queryClient.invalidateQueries({ queryKey: ["apiaries"] }); + }, + }); + + function handleSubmit(event: FormEvent) { + event.preventDefault(); + updateMutation.mutate(); + } + + return ( + + + {apiary.name} + + {apiary.status === "ACTIVE" ? "Aktiv" : "Inaktiv"} + + + +
+
+ + setName(event.target.value)} + /> +
+
+ + setLocation(event.target.value)} + /> +
+
+ + setAddress(event.target.value)} + /> +
+
+ +