Fix Station-Select
This commit is contained in:
@@ -45,16 +45,9 @@ export function StationsSelect({
|
||||
queryFn: () => getStationsAPI(),
|
||||
});
|
||||
|
||||
const [value, setValue] = useState<string[]>(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<string[] | string | null>(
|
||||
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 (
|
||||
<Select
|
||||
className={className}
|
||||
|
||||
Reference in New Issue
Block a user