From f6e4449f68cf11f0327c9bf7ff794924d88cdc3d Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Wed, 23 Apr 2025 19:01:26 -0700 Subject: [PATCH] added mission fields --- apps/dispatch/app/_store/missionsStore.ts | 41 ++--- apps/dispatch/app/api/mission/route.ts | 22 ++- .../_components/pannel/MissionForm.tsx | 144 ++++++++---------- .../app/dispatch/_components/pannel/action.ts | 15 ++ grafana/grafana.db | Bin 1122304 -> 1122304 bytes .../database/prisma/json/MissionVehicleLog.ts | 24 +++ packages/database/prisma/json/OSMway.ts | 8 + .../database/prisma/schema/keyword.prisma | 2 +- .../database/prisma/schema/mission.prisma | 48 +++++- .../database/prisma/schema/station.prisma | 2 + packages/database/prisma/schema/user.prisma | 3 + packages/eslint-config/base.js | 2 +- 12 files changed, 198 insertions(+), 113 deletions(-) create mode 100644 apps/dispatch/app/dispatch/_components/pannel/action.ts create mode 100644 packages/database/prisma/json/MissionVehicleLog.ts create mode 100644 packages/database/prisma/json/OSMway.ts diff --git a/apps/dispatch/app/_store/missionsStore.ts b/apps/dispatch/app/_store/missionsStore.ts index 3b965ada..0e07a46a 100644 --- a/apps/dispatch/app/_store/missionsStore.ts +++ b/apps/dispatch/app/_store/missionsStore.ts @@ -1,4 +1,4 @@ -import { Prisma } from "@repo/db"; +import { Mission, Prisma } from "@repo/db"; import { MissionOptionalDefaults } from "@repo/db/zod"; import { create } from "zustand"; @@ -6,29 +6,29 @@ interface MissionStore { missions: MissionOptionalDefaults[]; setMissions: (missions: MissionOptionalDefaults[]) => void; getMissions: () => Promise; + createMission: (mission: MissionOptionalDefaults) => Promise; setMission: (mission: MissionOptionalDefaults) => void; } export const useMissionsStore = create((set) => ({ - missions: [ - { - state: "draft", - id: "01250325", - addressLat: 52.520008, - addressLng: 13.404954, - addressStreet: "Alexanderplatz", - addressCity: "Berlin", - addressZip: "10178", - missionAdditionalInfo: "Additional info", - missionCategory: "AB_Atmung", - missionKeyword: "Zunehmende Beschwerden", - missionSummary: "AB1_0", - missionPatientInfo: "M/10", - }, - ], + missions: [], setMissions: (missions) => set({ missions }), + createMission: async (mission) => { + const res = await fetch("/api/mission", { + method: "PUT", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(mission), + }); + if (!res.ok) return undefined; + const data = await res.json(); + set((state) => ({ missions: [...state.missions, data] })); + return data; + }, getMissions: async () => { const res = await fetch("/api/mission", { + method: "POST", headers: { "Content-Type": "application/json", }, @@ -62,3 +62,10 @@ export const useMissionsStore = create((set) => ({ } }), })); + +useMissionsStore + .getState() + .getMissions() + .then(() => { + console.log("Missions loaded"); + }); diff --git a/apps/dispatch/app/api/mission/route.ts b/apps/dispatch/app/api/mission/route.ts index 0992ef67..5059e8af 100644 --- a/apps/dispatch/app/api/mission/route.ts +++ b/apps/dispatch/app/api/mission/route.ts @@ -1,14 +1,24 @@ import { Prisma, prisma } from "@repo/db"; import { NextRequest, NextResponse } from "next/server"; -export const GET = (req: NextRequest) => { - const filter = req.nextUrl.searchParams.get("filter") as - | Prisma.MissionWhereInput - | undefined; +export const POST = async (req: NextRequest) => { + console.log(req.body); + const body = await req.json(); + console.log(body); - const missions = prisma.mission.findMany({ - where: filter, + const missions = await prisma.mission.findMany({ + where: (body.filter as Prisma.MissionWhereInput) || {}, }); return NextResponse.json(missions); }; + +export const PUT = async (req: NextRequest) => { + const body = await req.json(); + + const newMission = await prisma.mission.create({ + data: body, + }); + + return NextResponse.json(newMission); +}; diff --git a/apps/dispatch/app/dispatch/_components/pannel/MissionForm.tsx b/apps/dispatch/app/dispatch/_components/pannel/MissionForm.tsx index 95f39d37..24424bf1 100644 --- a/apps/dispatch/app/dispatch/_components/pannel/MissionForm.tsx +++ b/apps/dispatch/app/dispatch/_components/pannel/MissionForm.tsx @@ -1,11 +1,13 @@ "use client"; -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import { useForm, Controller } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; -import { MissionSchema } from "@repo/db/zod"; import { BellRing, BookmarkPlus, Trash2 } from "lucide-react"; import { Select } from "_components/Select"; +import { Keyword, Station } from "@repo/db"; +import { getKeywords, getStations } from "dispatch/_components/pannel/action"; +import { MissionCreateInputSchema } from "@repo/db/zod"; const clearBtn = () => { return ( @@ -15,59 +17,35 @@ const clearBtn = () => { ); }; -const missionFormSchema = MissionSchema.pick({ - addressLat: true, - addressLng: true, - addressStreet: true, - addressCity: true, - addressZip: true, - missionCategory: true, - missionKeyword: true, - missionAdditionalInfo: true, - missionPatientInfo: true, -}); +export const MissionForm = () => { + type MissionFormValues = z.infer; -type MissionFormValues = z.infer; - -const dummyRettungsmittel = [ - "RTW", - "Feuerwehr", - "Polizei", - "Christoph 31", - "Christoph 100", - "Christoph Berlin", - "Christophorus 1", -]; - -export const MissionForm: React.FC = () => { - const [missionCategory, setMissionCategory] = useState<"PRIMÄR" | "SEKUNDÄR">( - "PRIMÄR", - ); - const [missionKeyword, setMissionKeyword] = useState< - "AB_ATMUNG" | "C_BLUTUNG" - >("AB_ATMUNG"); - const [missionType, setMissionType] = useState<"typ1" | "typ2" | "typ3">( - "typ1", - ); - const [selectedRettungsmittel, setSelectedRettungsmittel] = useState< - { label: string; value: string }[] - >([]); const form = useForm({ - resolver: zodResolver(missionFormSchema), - defaultValues: { - addressLat: 0, - addressLng: 0, - missionCategory: "PRIMÄR", - }, + resolver: zodResolver(MissionCreateInputSchema), + defaultValues: {}, }); + const [stations, setStations] = useState([]); + const [keywords, setKeywords] = useState([]); + + useEffect(() => { + console.log("useEffect"); + getKeywords().then((data) => { + setKeywords(data); + }); + getStations().then((data) => { + setStations(data); + }); + }, []); + const onSubmit = (data: MissionFormValues) => { console.log({ ...data, - rettungsmittel: selectedRettungsmittel.map((item) => item.value), }); }; + console.log(form.formState.errors); + return (
{/* Koorinaten Section */} @@ -78,13 +56,13 @@ export const MissionForm: React.FC = () => { type="text" {...form.register("addressLat")} className="input input-sm input-neutral input-bordered w-full" - readOnly + disabled /> @@ -128,9 +106,9 @@ export const MissionForm: React.FC = () => { label={""} isMulti form={form} - options={dummyRettungsmittel.map((key, val) => ({ - label: key, - value: val, + options={stations.map((s) => ({ + label: s.bosCallsign, + value: s.id, }))} /> @@ -139,45 +117,49 @@ export const MissionForm: React.FC = () => {

Einsatzdaten

- - + {form.watch("type") === "primär" && ( + <> + + + + )}