Fixed StationSelectBug, Fixed HPGNotificationGuf, see #45
This commit is contained in:
@@ -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<T extends FieldValues> = {
|
||||
type MissionStationsSelectProps = {
|
||||
selectedStations?: number[];
|
||||
className?: string;
|
||||
menuPlacement?: "top" | "bottom" | "auto"; // Added menuPlacement prop for better control
|
||||
@@ -27,7 +27,7 @@ type MissionStationsSelectProps<T extends FieldValues> = {
|
||||
isMulti?: boolean;
|
||||
};
|
||||
|
||||
export function StationsSelect<T extends FieldValues>({
|
||||
export function StationsSelect({
|
||||
onChange,
|
||||
selectedStations,
|
||||
vehicleStates,
|
||||
@@ -35,7 +35,7 @@ export function StationsSelect<T extends FieldValues>({
|
||||
isMulti = true,
|
||||
menuPlacement = "bottom",
|
||||
filterSelected = false,
|
||||
}: MissionStationsSelectProps<T>) {
|
||||
}: MissionStationsSelectProps) {
|
||||
const { data: connectedAircrafts } = useQuery({
|
||||
queryKey: ["aircrafts"],
|
||||
queryFn: () => getConnectedAircraftsAPI(),
|
||||
@@ -47,11 +47,21 @@ export function StationsSelect<T extends FieldValues>({
|
||||
|
||||
const [value, setValue] = useState<string[]>(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<T extends FieldValues>({
|
||||
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") {
|
||||
|
||||
@@ -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 (
|
||||
<form className="space-y-4">
|
||||
{/* 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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user