fix: khách mời join vào tour thông qua link mời
This commit is contained in:
@@ -59,6 +59,8 @@ export const JoinTourPage: React.FC<JoinTourPageProps> = ({ onLoginSuccess, onGo
|
||||
|
||||
setSuccessMsg(data.message || 'Bạn đã tham gia tour thành công!');
|
||||
setTourId(data.tourId);
|
||||
// Đợi 500ms để đảm bảo các thay đổi cache ở backend hoàn tất trước khi tiếp tục
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
localStorage.removeItem('pendingInviteToken');
|
||||
} catch (err: any) {
|
||||
setError(err.message || 'Đã xảy ra lỗi.');
|
||||
|
||||
@@ -51,9 +51,22 @@ export const useTourStore = create<TourState>((set, get) => ({
|
||||
fetchTour: async (id: string) => {
|
||||
const token = localStorage.getItem('token');
|
||||
try {
|
||||
const response = await fetch(`/api/v1/tours/${id}`, {
|
||||
let response = await fetch(`/api/v1/tours/${id}`, {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
// Thử lại một lần nếu gặp lỗi 403 hoặc 401 (có thể do cache vai trò cũ chưa được cập nhật)
|
||||
if (response.status === 403 || response.status === 401) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
const retryResponse = await fetch(`/api/v1/tours/${id}`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Cache-Control': 'no-cache'
|
||||
}
|
||||
});
|
||||
if (retryResponse.ok) {
|
||||
response = retryResponse;
|
||||
}
|
||||
}
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const data = await response.json();
|
||||
// ...existing role detection...
|
||||
|
||||
Reference in New Issue
Block a user