fix: Update map with tables fixes
This commit is contained in:
@@ -66,17 +66,41 @@ class RouteStore {
|
||||
});
|
||||
};
|
||||
|
||||
routeStations: Record<string, any[]> = {};
|
||||
|
||||
getRoute = async (id: number) => {
|
||||
if (this.route[id]) return this.route[id];
|
||||
const response = await authInstance.get(`/route/${id}`);
|
||||
const stations = await authInstance.get(`/route/${id}/station`);
|
||||
|
||||
runInAction(() => {
|
||||
this.route[id] = response.data;
|
||||
this.routeStations[id] = stations.data;
|
||||
});
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
setRouteStations = (routeId: number, stationId: number, data: any) => {
|
||||
console.log(
|
||||
this.routeStations[routeId],
|
||||
stationId,
|
||||
this.routeStations[routeId].find((station) => station.id === stationId)
|
||||
);
|
||||
this.routeStations[routeId] = this.routeStations[routeId]?.map((station) =>
|
||||
station.id === stationId ? { ...station, ...data } : station
|
||||
);
|
||||
};
|
||||
|
||||
saveRouteStations = async (routeId: number, stationId: number) => {
|
||||
await authInstance.patch(`/route/${routeId}/station`, {
|
||||
...this.routeStations[routeId]?.find(
|
||||
(station) => station.id === stationId
|
||||
),
|
||||
station_id: stationId,
|
||||
});
|
||||
};
|
||||
|
||||
editRouteData = {
|
||||
carrier: "",
|
||||
carrier_id: 0,
|
||||
@@ -112,6 +136,21 @@ class RouteStore {
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
copyRouteAction = async (id: number) => {
|
||||
const response = await authInstance.post(`/route/${id}/copy`);
|
||||
console.log(response);
|
||||
|
||||
runInAction(() => {
|
||||
this.routes.data = [...this.routes.data, response.data];
|
||||
});
|
||||
};
|
||||
|
||||
selectedStationId = 0;
|
||||
|
||||
setSelectedStationId = (id: number) => {
|
||||
this.selectedStationId = id;
|
||||
};
|
||||
}
|
||||
|
||||
export const routeStore = new RouteStore();
|
||||
|
||||
Reference in New Issue
Block a user