diff --git a/apps/dispatch-server/routes/mission.ts b/apps/dispatch-server/routes/mission.ts index acb5c6f0..7d9f0494 100644 --- a/apps/dispatch-server/routes/mission.ts +++ b/apps/dispatch-server/routes/mission.ts @@ -257,6 +257,9 @@ router.post("/:id/hpg-validation-result", async (req, res) => { type: "hpg-validation", status: "success", message: `HPG Validierung erfolgreich`, + data: { + mission: newMission, + }, } as NotificationPayload); if (result.alertWhenValid) { @@ -268,6 +271,9 @@ router.post("/:id/hpg-validation-result", async (req, res) => { type: "hpg-validation", status: "failed", message: result.state, + data: { + mission: newMission, + }, } as NotificationPayload); } res.json({ diff --git a/apps/dispatch/app/(app)/dispatch/_components/StationSelect.tsx b/apps/dispatch/app/(app)/dispatch/_components/StationSelect.tsx index 6d1e11a5..b03f406e 100644 --- a/apps/dispatch/app/(app)/dispatch/_components/StationSelect.tsx +++ b/apps/dispatch/app/(app)/dispatch/_components/StationSelect.tsx @@ -5,10 +5,10 @@ import { Select } from "_components/Select"; import { getConnectedAircraftsAPI } from "_querys/aircrafts"; import { getStationsAPI } from "_querys/stations"; import { Ambulance, FireExtinguisher, Radio, Siren } from "lucide-react"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { FieldValues } from "react-hook-form"; -type MissionStationsSelectProps = { +type MissionStationsSelectProps = { selectedStations?: number[]; className?: string; menuPlacement?: "top" | "bottom" | "auto"; // Added menuPlacement prop for better control @@ -27,7 +27,7 @@ type MissionStationsSelectProps = { isMulti?: boolean; }; -export function StationsSelect({ +export function StationsSelect({ onChange, selectedStations, vehicleStates, @@ -35,7 +35,7 @@ export function StationsSelect({ isMulti = true, menuPlacement = "bottom", filterSelected = false, -}: MissionStationsSelectProps) { +}: MissionStationsSelectProps) { const { data: connectedAircrafts } = useQuery({ queryKey: ["aircrafts"], queryFn: () => getConnectedAircraftsAPI(), @@ -47,11 +47,21 @@ export function StationsSelect({ const [value, setValue] = useState(selectedStations?.map((id) => String(id)) || []); + useEffect(() => { + setValue([ + ...(selectedStations || []).map((id) => String(id)), + ...(vehicleStates.hpgAmbulanceState !== HpgState.NOT_REQUESTED ? ["RTW"] : []), + ...(vehicleStates.hpgFireEngineState !== HpgState.NOT_REQUESTED ? ["FW"] : []), + ...(vehicleStates.hpgPoliceState !== HpgState.NOT_REQUESTED ? ["POL"] : []), + ]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [selectedStations, vehicleStates]); + // Helper to check if a station is a vehicle and its state is NOT_REQUESTED const stationsOptions = [ ...(stations?.map((station) => ({ label: station.bosCallsign, - value: station.id, + value: String(station.id), type: "station" as const, isOnline: !!connectedAircrafts?.find((a) => a.stationId === station.id), })) || []), @@ -78,7 +88,7 @@ export function StationsSelect({ if (!filterSelected) return true; // If filterSelected is false, include all stations // Filter out selected stations if filterSelectedStations is true if (s.type === "station") { - return !selectedStations?.includes(s.value); + return !selectedStations?.map(String)?.includes(s.value); } // If the station is a vehicle, we need to check its state if (s.type === "vehicle") { diff --git a/apps/dispatch/app/(app)/dispatch/_components/pannel/MissionForm.tsx b/apps/dispatch/app/(app)/dispatch/_components/pannel/MissionForm.tsx index fd6c2a17..1b272c4e 100644 --- a/apps/dispatch/app/(app)/dispatch/_components/pannel/MissionForm.tsx +++ b/apps/dispatch/app/(app)/dispatch/_components/pannel/MissionForm.tsx @@ -21,7 +21,6 @@ import { startHpgValidation, } from "_querys/missions"; import { getKeywordsAPI } from "_querys/keywords"; -import { getStationsAPI } from "_querys/stations"; import { useMapStore } from "_store/mapStore"; import { getConnectedAircraftsAPI } from "_querys/aircrafts"; import { HPGValidationRequired } from "_helpers/hpgValidationRequired"; @@ -197,7 +196,7 @@ export const MissionForm = () => { } return newMission; }; - console.log(form.formState.errors); + console.log(form.watch("missionStationIds")); return (
{/* Koorinaten Section */} @@ -282,12 +281,12 @@ export const MissionForm = () => { className="select select-primary select-bordered w-full mb-4" onChange={(e) => { form.setValue("type", e.target.value as missionType); - if (e.target.value === "sekundär") { - form.setValue("missionKeywordName", KEYWORD_CATEGORY.Z_SONSTIGES); - form.setValue("missionKeywordAbbreviation", "VL_S"); - form.setValue("hpgMissionString", "Verlegung:4_1_1_1-4_1"); + if (e.target.value === "primary") { + form.setValue("missionKeywordName", null as any); + form.setValue("missionKeywordAbbreviation", null as any); + form.setValue("hpgMissionString", null); } else { - form.setValue("missionKeywordCategory", "V_VERLEGUNG"); + form.setValue("missionKeywordCategory", KEYWORD_CATEGORY.V_VERLEGUNG); form.setValue("missionKeywordAbbreviation", null as any); form.setValue("hpgMissionString", null); } diff --git a/apps/dispatch/app/(app)/pilot/page.tsx b/apps/dispatch/app/(app)/pilot/page.tsx index 3ddc0808..f83c31d3 100644 --- a/apps/dispatch/app/(app)/pilot/page.tsx +++ b/apps/dispatch/app/(app)/pilot/page.tsx @@ -16,15 +16,15 @@ const Map = dynamic(() => import("_components/map/Map"), { ssr: false, }); -const DispatchPage = () => { +const PilotPage = () => { const { connectedAircraft, status } = usePilotConnectionStore((state) => state); const { data: ownAircraftArray = [] } = useQuery({ - queryKey: ["aircrafts", connectedAircraft?.id], + queryKey: ["own-aircraft", connectedAircraft?.id], queryFn: () => getAircraftsAPI({ id: connectedAircraft?.id, }), - refetchInterval: 1000, + refetchInterval: 10000, }); const ownAircraft = ownAircraftArray[0]; const simulatorConnected = ownAircraft ? checkSimulatorConnected(ownAircraft) : false; @@ -73,6 +73,6 @@ const DispatchPage = () => { ); }; -DispatchPage.displayName = "DispatchPage"; +PilotPage.displayName = "DispatchPage"; -export default DispatchPage; +export default PilotPage; diff --git a/apps/dispatch/app/_components/QueryProvider.tsx b/apps/dispatch/app/_components/QueryProvider.tsx index 562d4b64..d2dc6f84 100644 --- a/apps/dispatch/app/_components/QueryProvider.tsx +++ b/apps/dispatch/app/_components/QueryProvider.tsx @@ -59,6 +59,7 @@ export function QueryProvider({ children }: { children: ReactNode }) { const handleNotification = (notification: NotificationPayload) => { switch (notification.type) { case "hpg-validation": + console.log("hpg-validation notification received", notification); toast.custom( (t) => , { diff --git a/apps/dispatch/app/_components/map/AircraftMarker.tsx b/apps/dispatch/app/_components/map/AircraftMarker.tsx index a4414c82..b89bfe67 100644 --- a/apps/dispatch/app/_components/map/AircraftMarker.tsx +++ b/apps/dispatch/app/_components/map/AircraftMarker.tsx @@ -110,7 +110,7 @@ const AircraftPopupContent = ({ />
handleTabChange("aircraft")} > - - {aircraft.Station.bosCallsign} + + {aircraft.Station.bosCallsign.length > 20 + ? aircraft.Station.bosCallsignShort + : aircraft.Station.bosCallsign} + +
- {aircraft.Station.bosUse} + {aircraft.Station.bosUse === "DUAL_USE" && "(dual use)"} + {aircraft.Station.bosUse === "PRIMARY" && "(primär)"} + {aircraft.Station.bosUse === "SECONDARY" && "(sekundär)"}
Einsatz
- {mission?.publicId || "Kein aktiver Einsatz"} + {mission?.publicId || "kein Einsatz"}
queryKey: ["stations"], queryFn: () => getStationsAPI(), }); - console.log("StationsLayer: stations", stations); const [selectedStations, setSelectedStations] = useState([]); const attributionText = ""; @@ -306,14 +305,6 @@ const WindfarmOutlineLayer = () => { export const BaseMaps = () => { const map = useMap(); - const isPannelOpen = usePannelStore((state) => state.isOpen); - - useEffect(() => { - setTimeout(() => { - map.invalidateSize(); - }, 600); - }, [isPannelOpen]); - return ( diff --git a/apps/dispatch/app/api/aircrafts/route.ts b/apps/dispatch/app/api/aircrafts/route.ts index dcef0f1d..47f4eb12 100644 --- a/apps/dispatch/app/api/aircrafts/route.ts +++ b/apps/dispatch/app/api/aircrafts/route.ts @@ -3,6 +3,11 @@ import { Prisma, prisma } from "@repo/db"; export async function GET(request: NextRequest): Promise { try { + const config = await prisma.config.findFirst({ + orderBy: { + createdAt: "desc", + }, + }); const filter = JSON.parse( new URL(request.url).searchParams.get("filter") || "{}", ) as Prisma.ConnectedAircraftWhereInput; @@ -16,9 +21,15 @@ export async function GET(request: NextRequest): Promise { Station: true, }, }); - return NextResponse.json(connectedAircraft, { - status: 200, - }); + return NextResponse.json( + connectedAircraft.map((a) => ({ + ...a, + posH145active: config?.disableHPG ? false : a.posH145active, + })), + { + status: 200, + }, + ); } catch (error) { console.error(error); return NextResponse.json({ error: "Failed to fetch Aircrafts" }, { status: 500 });