Thêm tính năng trong mục 4.1 của ARCHITECTURE.md

This commit is contained in:
2026-06-13 20:14:52 +07:00
parent b54707823c
commit c51ddc34c7
13 changed files with 343 additions and 60 deletions
+15 -3
View File
@@ -7,7 +7,7 @@ interface TourState {
userRole: string | null;
setTour: (tour: any) => void;
updateLegs: (legs: any[]) => void;
optimizeRouting: () => Promise<void>;
optimizeRouting: (legId: string) => Promise<void>;
fetchTour: (id: string) => Promise<void>;
fetchPublicTours: () => Promise<void>;
}
@@ -34,7 +34,19 @@ export const useTourStore = create<TourState>((set, get) => ({
const data = await response.json();
set({ publicTours: data });
},
optimizeRouting: async () => {
// Logic gọi API /api/v1/routing/optimize và cập nhật lại state
optimizeRouting: async (legId: string) => {
const API_BASE = `http://${window.location.hostname}:3001`;
const response = await fetch(`${API_BASE}/api/v1/routing/optimize/${legId}`, {
method: 'POST'
});
const { locations, totalDistance } = await response.json();
const { currentTour } = get();
if (currentTour) {
const updatedLegs = currentTour.legs.map((l: any) =>
l.id === legId ? { ...l, locations: locations, totalDistance: totalDistance } : l
);
set({ currentTour: { ...currentTour, legs: updatedLegs }, legs: updatedLegs });
}
},
}));