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") {
|
||||
|
||||
Reference in New Issue
Block a user