From 0d7b57fb508ad81b96aecd1d671c389c45900602 Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Thu, 24 Apr 2025 13:18:56 -0700 Subject: [PATCH] Added DB integration for missions --- apps/dispatch/app/_store/missionsStore.ts | 3 +- .../dispatch/_components/map/ContextMenu.tsx | 6 +- .../dispatch/_components/navbar/Navbar.tsx | 9 +- .../_components/pannel/MissionForm.tsx | 147 ++++++++++++++---- grafana/grafana.db | Bin 1122304 -> 1122304 bytes .../database/prisma/schema/mission.prisma | 1 + 6 files changed, 130 insertions(+), 36 deletions(-) diff --git a/apps/dispatch/app/_store/missionsStore.ts b/apps/dispatch/app/_store/missionsStore.ts index 03d368d7..505a57e6 100644 --- a/apps/dispatch/app/_store/missionsStore.ts +++ b/apps/dispatch/app/_store/missionsStore.ts @@ -29,6 +29,7 @@ export const useMissionsStore = create((set) => ({ missionPatientInfo: "Test", missionStationIds: [], createdUserId: "1", + hpgMissionString: null, missionLog: [], missionStationUserIds: [], hpgLocationLat: 52.520008, @@ -49,7 +50,7 @@ export const useMissionsStore = create((set) => ({ }, body: JSON.stringify(mission), }); - if (!res.ok) return undefined; + if (!res.ok) return new Error("Failed to create mission"); const data = await res.json(); set((state) => ({ missions: [...state.missions, data] })); return data; diff --git a/apps/dispatch/app/dispatch/_components/map/ContextMenu.tsx b/apps/dispatch/app/dispatch/_components/map/ContextMenu.tsx index e71fe9a1..cd9ab2b9 100644 --- a/apps/dispatch/app/dispatch/_components/map/ContextMenu.tsx +++ b/apps/dispatch/app/dispatch/_components/map/ContextMenu.tsx @@ -58,6 +58,7 @@ export const ContextMenu = () => { road: string; state: string; city: string; + town: string; }; display_name: string; importance: number; @@ -71,11 +72,12 @@ export const ContextMenu = () => { place_rank: number; type: string; }; + console.log(data); setMissionFormValues({ addressLat: contextMenu.lat, addressLng: contextMenu.lng, - addressCity: data.address.city, - addressStreet: `${data.address.road}, ${data.address.house_number}`, + addressCity: data.address.city || data.address.town, + addressStreet: `${data.address.road}, ${data.address.house_number || "keine HN"}`, addressZip: data.address.postcode, state: "draft", }); diff --git a/apps/dispatch/app/dispatch/_components/navbar/Navbar.tsx b/apps/dispatch/app/dispatch/_components/navbar/Navbar.tsx index bdd617c4..ee5f1236 100644 --- a/apps/dispatch/app/dispatch/_components/navbar/Navbar.tsx +++ b/apps/dispatch/app/dispatch/_components/navbar/Navbar.tsx @@ -6,6 +6,7 @@ import { Audio } from "./_components/Audio"; import { useState } from "react"; import { ExitIcon, ExternalLinkIcon } from "@radix-ui/react-icons"; import { Chat } from "./_components/Chat"; +import Link from "next/link"; export default function Navbar() { const [isDark, setIsDark] = useState(false); @@ -42,9 +43,11 @@ export default function Navbar() { - + + + diff --git a/apps/dispatch/app/dispatch/_components/pannel/MissionForm.tsx b/apps/dispatch/app/dispatch/_components/pannel/MissionForm.tsx index 55e8a558..18d7b0cd 100644 --- a/apps/dispatch/app/dispatch/_components/pannel/MissionForm.tsx +++ b/apps/dispatch/app/dispatch/_components/pannel/MissionForm.tsx @@ -1,25 +1,49 @@ "use client"; -import React, { use, useEffect, useState } from "react"; +import React, { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; -import { BellRing, BookmarkPlus, Trash2 } from "lucide-react"; +import { BellRing, BookmarkPlus } from "lucide-react"; import { Select } from "_components/Select"; -import { Keyword, Station } from "@repo/db"; +import { Keyword, KEYWORD_CATEGORY, missionType, Station } from "@repo/db"; import { getKeywords, getStations } from "dispatch/_components/pannel/action"; import { MissionOptionalDefaults, MissionOptionalDefaultsSchema, } from "@repo/db/zod"; import { usePannelStore } from "_store/pannelStore"; +import { useSession } from "next-auth/react"; +import { toast } from "react-hot-toast"; +import { useMissionsStore } from "_store/missionsStore"; export const MissionForm = () => { + const createMission = useMissionsStore((state) => state.createMission); + const session = useSession(); + const defaultFormValues = React.useMemo( + () => + ({ + createdUserId: session.data?.user.id, + type: "primär", + addressOSMways: [], + hpgFireEngineState: null, + hpgAmbulanceState: null, + hpgPoliceState: null, + hpgMissionString: null, + missionLog: [], + }) as Partial, + [session.data?.user.id], + ); + const form = useForm({ resolver: zodResolver(MissionOptionalDefaultsSchema), - defaultValues: {}, + defaultValues: defaultFormValues, }); - const { missionFormValues, setMissionFormValues } = usePannelStore( - (state) => state, - ); + const { missionFormValues } = usePannelStore((state) => state); + + useEffect(() => { + if (session.data?.user.id) { + form.setValue("createdUserId", session.data.user.id); + } + }, [session.data?.user.id, form]); /* const formValues = form.watch(); useEffect(() => { @@ -30,9 +54,12 @@ export const MissionForm = () => { useEffect(() => { if (missionFormValues) { - form.reset(missionFormValues); + form.reset({ + ...missionFormValues, + ...defaultFormValues, + }); } - }, [missionFormValues, form]); + }, [missionFormValues, form, defaultFormValues]); const [stations, setStations] = useState([]); const [keywords, setKeywords] = useState([]); @@ -46,12 +73,10 @@ export const MissionForm = () => { }); }, []); - const onSubmit = (data: MissionOptionalDefaults) => { - console.log({ - ...data, - }); - }; - + console.log( + form.watch("missionKeywordName"), + form.watch("missionKeywordAbbreviation"), + ); console.log(form.formState.errors); return ( @@ -127,6 +152,12 @@ export const MissionForm = () => { - form.setValue("missionKeyword", e.target.value as string) - } + onChange={(e) => { + form.setValue( + "missionKeywordCategory", + e.target.value as string, + ); + form.setValue("missionKeywordName", null); + form.setValue("missionKeywordAbbreviation", null); + form.setValue("hpgMissionString", null); + }} + defaultValue="default" > - {keywords.map((keyword) => ( - + {Object.keys(KEYWORD_CATEGORY).map((use) => ( + ))} + )} @@ -195,9 +272,19 @@ export const MissionForm = () => { diff --git a/grafana/grafana.db b/grafana/grafana.db index 4bc765bbcab7528a6ce6fb235a1671b7699e564f..95443699517e8495c7e4313ff1f45dd2b17a63a4 100644 GIT binary patch delta 87 zcmZoT;L>owWr8&0iHS1Kj3*isS`!#s6PQ{Pm|GKAS`%1X6WCf4*taHdl0mPg@%mu{UK+FTgygowWr8&0{)sZqjQblCS`!#s6PQ{Pm|GKAS`%1X6WCf4*taHdl