Bổ sung tính năng cập nhật tiền của địa điểm bị lỗi trùng cổng

This commit is contained in:
2026-06-14 12:24:53 +07:00
parent 58087a4b37
commit 65a9b39966
11 changed files with 115 additions and 47 deletions
+27 -3
View File
@@ -12,9 +12,24 @@ export const useTourStore = create((set, get) => ({
setMapCenter: (pos) => set({ mapCenter: pos }),
fetchTour: async (id) => {
const API_BASE = `http://${window.location.hostname}:3001`;
const response = await fetch(`${API_BASE}/api/v1/tours/${id}`);
const token = localStorage.getItem('token');
const response = await fetch(`${API_BASE}/api/v1/tours/${id}`, {
headers: { 'Authorization': `Bearer ${token}` }
});
const data = await response.json();
const role = data.participants?.[0]?.role || 'VIEWER_ONLY';
let role = 'VIEWER_ONLY';
if (token) {
try {
const payload = JSON.parse(atob(token.split('.')[1]));
const currentUserId = payload.sub;
const participant = data.participants?.find((p) => p.userId === currentUserId);
if (participant)
role = participant.role;
}
catch (e) {
console.error("Lỗi khi xác định vai trò người dùng:", e);
}
}
const legs = data.legs || [];
set({
currentTour: data,
@@ -25,7 +40,16 @@ export const useTourStore = create((set, get) => ({
},
fetchPublicTours: async () => {
const API_BASE = `http://${window.location.hostname}:3001`;
const response = await fetch(`${API_BASE}/api/v1/tours/explore`);
const token = localStorage.getItem('token');
if (!token)
return;
const response = await fetch(`${API_BASE}/api/v1/tours/explore`, {
headers: {
'Authorization': `Bearer ${token}`
}
});
if (!response.ok)
return;
const data = await response.json();
set({ publicTours: data });
},