From 69b71b07793c278747c07912511767ec2ffc9a68 Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Wed, 21 May 2025 09:15:13 -0700 Subject: [PATCH] nachalarmieren tab complete --- apps/dispatch-server/routes/mission.ts | 4 +- .../_components/map/SearchElements.tsx | 1 - .../map/_components/MissionMarkerTabs.tsx | 139 +++++++++++++++--- .../_components/pannel/MissionForm.tsx | 21 ++- apps/dispatch/app/querys/missions.ts | 13 +- grafana/grafana.db | Bin 1122304 -> 1122304 bytes 6 files changed, 151 insertions(+), 27 deletions(-) diff --git a/apps/dispatch-server/routes/mission.ts b/apps/dispatch-server/routes/mission.ts index f57df72f..3775b449 100644 --- a/apps/dispatch-server/routes/mission.ts +++ b/apps/dispatch-server/routes/mission.ts @@ -51,8 +51,6 @@ router.put("/", async (req, res) => { }, }); - console.log("missionsTodayCount", missionsTodayCount); - const date = new Date(); const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are zero-based @@ -107,6 +105,7 @@ router.delete("/:id", async (req, res) => { router.post("/:id/send-alert", async (req, res) => { const { id } = req.params; + const { stationId } = req.body as { stationId?: number }; try { const mission = await prisma.mission.findUnique({ where: { id: Number(id) }, @@ -136,6 +135,7 @@ router.post("/:id/send-alert", async (req, res) => { }); for (const aircraft of connectedAircrafts) { + if (stationId && stationId !== aircraft.stationId) continue; console.log(`Sending mission to: station:${aircraft.stationId}`); io.to(`station:${aircraft.stationId}`).emit("mission-alert", { ...mission, diff --git a/apps/dispatch/app/dispatch/_components/map/SearchElements.tsx b/apps/dispatch/app/dispatch/_components/map/SearchElements.tsx index 33a1b103..45f95c9f 100644 --- a/apps/dispatch/app/dispatch/_components/map/SearchElements.tsx +++ b/apps/dispatch/app/dispatch/_components/map/SearchElements.tsx @@ -46,7 +46,6 @@ export const SearchElements = () => { useEffect(() => { if (ref.current) { ref.current.on("click", () => { - console.log("click"); const center = ref.current?.getBounds().getCenter(); if (center && searchPopup?.elementId !== element.wayID) { setSearchPopup({ diff --git a/apps/dispatch/app/dispatch/_components/map/_components/MissionMarkerTabs.tsx b/apps/dispatch/app/dispatch/_components/map/_components/MissionMarkerTabs.tsx index 6c48ea27..5aea4cfc 100644 --- a/apps/dispatch/app/dispatch/_components/map/_components/MissionMarkerTabs.tsx +++ b/apps/dispatch/app/dispatch/_components/map/_components/MissionMarkerTabs.tsx @@ -1,5 +1,5 @@ "use client"; -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import { FMS_STATUS_TEXT_COLORS } from "../AircraftMarker"; import { toast } from "react-hot-toast"; import { @@ -17,7 +17,6 @@ import { User, SmartphoneNfc, CheckCheck, - ArrowRight, Cross, } from "lucide-react"; import { @@ -52,7 +51,7 @@ const Einsatzdetails = ({ mission }: { mission: Mission }) => { }); const sendAlertMutation = useMutation({ mutationKey: ["missions"], - mutationFn: sendMissionAPI, + mutationFn: (id: number) => sendMissionAPI(id, {}), onError: (error) => { console.error(error); toast.error("Fehler beim Alarmieren"); @@ -225,23 +224,71 @@ const Patientdetails = ({ mission }: { mission: Mission }) => { }; const Rettungsmittel = ({ mission }: { mission: Mission }) => { + const queryClient = useQueryClient(); + const [selectedStation, setSelectedStation] = useState< + Station | "ambulance" | "police" | "firebrigade" | null + >(null); const { data: conenctedAircrafts } = useQuery({ queryKey: ["aircrafts"], queryFn: getConnectedAircraftsAPI, }); - const { data: stations } = useQuery({ - queryKey: ["mission", "stations-mission", mission.id], - queryFn: () => - getStationsAPI({ - id: { - in: mission.missionStationIds, - }, - }), + const updateMissionMutation = useMutation({ + mutationKey: ["missions", "stations-mission", mission.id], + mutationFn: ({ + id, + missionEdit, + }: { + id: number; + missionEdit: Prisma.MissionUpdateInput; + }) => editMissionAPI(id, missionEdit), + + onError: (error) => { + console.error(error); + toast.error("Fehler beim Speichern"); + }, + onSuccess: () => { + // Cache invalidieren → Query wird neu ausgeführt + queryClient.invalidateQueries({ + queryKey: ["missions"], + }); + }, }); + const { data: missionStations, refetch: refetchMissionStationIds } = useQuery( + { + queryKey: ["stations-mission", mission.id], + queryFn: () => + getStationsAPI({ + id: { + in: mission.missionStationIds, + }, + }), + }, + ); + useEffect(() => { + refetchMissionStationIds(); + }, [mission.missionStationIds, refetchMissionStationIds]); + + const { data: allStations } = useQuery({ + queryKey: ["stations"], + queryFn: () => getStationsAPI(), + }); + + useEffect(() => { + if (allStations) { + const stationsNotItMission = allStations.filter( + (s) => !mission.missionStationIds.includes(s.id), + ); + if (stationsNotItMission[0]) { + setSelectedStation(stationsNotItMission[0]); + } + } + }, [allStations, mission.missionStationIds]); + const sendAlertMutation = useMutation({ mutationKey: ["missions"], - mutationFn: sendMissionAPI, + mutationFn: ({ id, stationId }: { id: number; stationId?: number }) => + sendMissionAPI(id, { stationId }), onError: (error) => { console.error(error); toast.error("Fehler beim Alarmieren"); @@ -264,7 +311,7 @@ const Rettungsmittel = ({ mission }: { mission: Mission }) => {