From a905872f256910c32d57b6b20b385f9895f9d3ea Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Tue, 22 Jul 2025 11:06:00 -0700 Subject: [PATCH] Fix Station-Select --- .../dispatch/_components/StationSelect.tsx | 27 ++++++++++++------- .../navbar/_components/Connection.tsx | 2 +- .../app/_components/map/MapAdditionals.tsx | 3 +++ .../app/_components/map/MissionMarkers.tsx | 22 +++++++-------- .../map/_components/MissionMarkerTabs.tsx | 11 +++++--- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/apps/dispatch/app/(app)/dispatch/_components/StationSelect.tsx b/apps/dispatch/app/(app)/dispatch/_components/StationSelect.tsx index f435050e..7c685caa 100644 --- a/apps/dispatch/app/(app)/dispatch/_components/StationSelect.tsx +++ b/apps/dispatch/app/(app)/dispatch/_components/StationSelect.tsx @@ -45,16 +45,9 @@ export function StationsSelect({ queryFn: () => getStationsAPI(), }); - const [value, setValue] = useState(selectedStations?.map((id) => String(id)) || []); - - useEffect(() => { - setValue([ - ...(selectedStations || []).map((id) => String(id)), - ...(vehicleStates.hpgAmbulanceState !== HpgState.NOT_REQUESTED || undefined ? ["RTW"] : []), - ...(vehicleStates.hpgFireEngineState !== HpgState.NOT_REQUESTED || undefined ? ["FW"] : []), - ...(vehicleStates.hpgPoliceState !== HpgState.NOT_REQUESTED || undefined ? ["POL"] : []), - ]); - }, [selectedStations, vehicleStates]); + const [value, setValue] = useState( + selectedStations?.map((id) => String(id)) || [], + ); // Helper to check if a station is a vehicle and its state is NOT_REQUESTED const stationsOptions = [ @@ -101,6 +94,20 @@ export function StationsSelect({ return true; }); + useEffect(() => { + if (isMulti) { + setValue([ + ...(selectedStations || []).map((id) => String(id)), + ...(vehicleStates.hpgAmbulanceState !== HpgState.NOT_REQUESTED || undefined ? ["RTW"] : []), + ...(vehicleStates.hpgFireEngineState !== HpgState.NOT_REQUESTED || undefined ? ["FW"] : []), + ...(vehicleStates.hpgPoliceState !== HpgState.NOT_REQUESTED || undefined ? ["POL"] : []), + ]); + } else { + console.log("clear selected stations"); + setValue(null); + } + }, [selectedStations, vehicleStates, isMulti]); + return ( { const { isOpen, missionFormValues } = usePannelStore((state) => state); + const dispatcherConnectionState = useDispatchConnectionStore((state) => state.status); const { data: missions = [] } = useQuery({ queryKey: ["missions"], queryFn: () => @@ -32,6 +34,7 @@ export const MapAdditionals = () => { m.hpgValidationState === "POSITION_AMANDED" && m.state === "draft" && m.hpgLocationLat && + dispatcherConnectionState === "connected" && m.hpgLocationLng, ); diff --git a/apps/dispatch/app/_components/map/MissionMarkers.tsx b/apps/dispatch/app/_components/map/MissionMarkers.tsx index 36d2a8bc..3dee1d2e 100644 --- a/apps/dispatch/app/_components/map/MissionMarkers.tsx +++ b/apps/dispatch/app/_components/map/MissionMarkers.tsx @@ -82,7 +82,7 @@ const MissionPopupContent = ({ return ( <>
{ setOpenMissionMarker({ open: [], @@ -95,7 +95,7 @@ const MissionPopupContent = ({
{mission.state === "draft" && (
{ className="min-w-[320px] flex-1" isMulti={false} onChange={(v) => { + console.log("Selected Station:", v); setSelectedStation({ selectedStationId: v?.selectedStationIds[0], - hpgAmbulanceState: mission.hpgAmbulanceState || HpgState.NOT_REQUESTED, - hpgFireEngineState: mission.hpgFireEngineState || HpgState.NOT_REQUESTED, - hpgPoliceState: mission.hpgPoliceState || HpgState.NOT_REQUESTED, + hpgAmbulanceState: + v.hpgAmbulanceState || mission.hpgAmbulanceState || HpgState.NOT_REQUESTED, + hpgFireEngineState: + v.hpgFireEngineState || mission.hpgFireEngineState || HpgState.NOT_REQUESTED, + hpgPoliceState: + v.hpgPoliceState || mission.hpgPoliceState || HpgState.NOT_REQUESTED, }); }} selectedStations={mission.missionStationIds} @@ -548,6 +552,7 @@ const Rettungsmittel = ({ mission }: { mission: Mission }) => {