Sửa hiển thị điểm đầu và điểm cuối của chặng

This commit is contained in:
2026-06-14 09:28:33 +07:00
parent ed437cdb0f
commit 14bf43487e
17 changed files with 189 additions and 12 deletions
+14
View File
@@ -13,6 +13,7 @@ interface TourState {
updateTour: (id: string, data: any) => Promise<void>;
deleteTour: (id: string) => Promise<void>;
addLeg: (tourId: string, data: any) => Promise<void>;
initializeLegs: (tourId: string, count: number) => Promise<void>;
updateLeg: (legId: string, data: any) => Promise<void>;
deleteLeg: (legId: string) => Promise<void>;
addLocation: (tourId: string, locationData: any) => Promise<void>;
@@ -115,6 +116,19 @@ export const useTourStore = create<TourState>((set, get) => ({
if (!response.ok) throw new Error('Lỗi khi thêm chặng');
get().fetchTour(tourId);
},
initializeLegs: async (tourId: string, count: number) => {
const API_BASE = `http://${window.location.hostname}:3001`;
const response = await fetch(`${API_BASE}/api/v1/tours/${tourId}/legs/batch`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${localStorage.getItem('token')}`
},
body: JSON.stringify({ count }),
});
if (!response.ok) throw new Error('Lỗi khi khởi tạo chặng');
await get().fetchTour(tourId);
},
updateLeg: async (legId: string, data: any) => {
const API_BASE = `http://${window.location.hostname}:3001`;
const response = await fetch(`${API_BASE}/api/v1/legs/${legId}`, {