diff --git a/frontend/src/store/useTourStore.ts b/frontend/src/store/useTourStore.ts index 5b6de67..f017b90 100644 --- a/frontend/src/store/useTourStore.ts +++ b/frontend/src/store/useTourStore.ts @@ -10,6 +10,7 @@ interface TourState { setTour: (tour: any) => void; updateLegs: (legs: any[]) => void; createTour: (tourData: any) => Promise; + updateTourDetails: (tourId: string, data: any) => Promise; updateTour: (id: string, data: any) => Promise; deleteTour: (id: string) => Promise; addLeg: (tourId: string, data: any) => Promise; @@ -106,6 +107,23 @@ export const useTourStore = create((set, get) => ({ await get().fetchPublicTours(); return tour; }, + updateTourDetails: async (tourId: string, data: any) => { + const API_BASE = `http://${window.location.hostname}:3001`; + const token = localStorage.getItem('token'); + const response = await fetch(`${API_BASE}/api/v1/tours/${tourId}`, { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}` + }, + body: JSON.stringify(data), + }); + + if (!response.ok) { + const errorData = await response.json().catch(() => ({})); + throw new Error(errorData.message || errorData.error || 'Lỗi khi cập nhật thông tin tour'); + } + }, updateTour: async (id: string, data: any) => { const API_BASE = `http://${window.location.hostname}:3001`; const response = await fetch(`${API_BASE}/api/v1/tours/${id}`, {