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
+26 -4
View File
@@ -41,11 +41,24 @@ export const useTourStore = create<TourState>((set, get) => ({
setMapCenter: (pos) => set({ mapCenter: pos }),
fetchTour: async (id: string) => {
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();
// Lấy role từ danh sách participants (dữ liệu mẫu từ seed)
const role = data.participants?.[0]?.role || 'VIEWER_ONLY';
// Xác định role của người dùng hiện tại dựa trên thông tin trong JWT
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: any) => 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({
@@ -57,7 +70,16 @@ export const useTourStore = create<TourState>((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 });
},