feat: tính năng chia sẻ khẩn cấp
This commit is contained in:
+30
-9
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { LandingPage } from './pages/LandingPage';
|
||||
import { ExploreMap } from './pages/ExploreMap';
|
||||
import { TourDetailPage } from './pages/TourDetailPage';
|
||||
@@ -7,30 +7,32 @@ import { MyPhotosPage } from './pages/MyPhotosPage';
|
||||
import { MyNotePage } from './pages/MyNotePage';
|
||||
import { JoinTourPage } from './pages/JoinTourPage';
|
||||
import { MemberDashboard } from './pages/MemberDashboard';
|
||||
import { useTourStore } from './store/useTourStore';
|
||||
import { ShareJourneyPage } from './pages/ShareJourneyPage';
|
||||
import { ConfirmProvider } from './hooks/useConfirm';
|
||||
import { NotificationProvider } from './hooks/useNotification';
|
||||
|
||||
function App() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const viewTourId = params.get('viewTour');
|
||||
const pathParts = window.location.pathname.split('/');
|
||||
const isJourneyShare = pathParts[1] === 'journey' && pathParts[2];
|
||||
const journeyTokenVal = isJourneyShare ? pathParts[2] : null;
|
||||
|
||||
const [user, setUser] = useState<any>(null);
|
||||
const [currentPage, setCurrentPage] = useState<'landing' | 'dashboard' | 'explore' | 'tourDetail' | 'signup' | 'myPhotos' | 'notes' | 'joinTour'>(
|
||||
viewTourId ? 'tourDetail' : (window.location.pathname === '/join-tour' || params.has('token') ? 'joinTour' : 'landing')
|
||||
const [shareJourneyToken, setShareJourneyToken] = useState<string | null>(journeyTokenVal);
|
||||
const [currentPage, setCurrentPage] = useState<'landing' | 'dashboard' | 'explore' | 'tourDetail' | 'signup' | 'myPhotos' | 'notes' | 'joinTour' | 'shareJourney'>(
|
||||
journeyTokenVal ? 'shareJourney' : (viewTourId ? 'tourDetail' : (window.location.pathname === '/join-tour' || params.has('token') ? 'joinTour' : 'landing'))
|
||||
);
|
||||
const [currentTourId, setCurrentTourId] = useState<string | null>(viewTourId);
|
||||
const [isPublicTourView, setIsPublicTourView] = useState(!!viewTourId);
|
||||
const [previousPage, setPreviousPage] = useState<'explore' | 'dashboard' | 'landing'>('explore');
|
||||
|
||||
// Lấy action từ store
|
||||
const fetchTour = useTourStore(state => state.fetchTour);
|
||||
const fetchPublicTourDetails = useTourStore(state => state.fetchPublicTourDetails);
|
||||
|
||||
useEffect(() => {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const viewTourId = params.get('viewTour');
|
||||
const isJoinTour = window.location.pathname === '/join-tour' || params.has('token');
|
||||
const pathParts = window.location.pathname.split('/');
|
||||
const journeyToken = pathParts[1] === 'journey' && pathParts[2] ? pathParts[2] : null;
|
||||
|
||||
// Khôi phục thông tin đăng nhập nếu có
|
||||
const token = localStorage.getItem('token');
|
||||
@@ -46,7 +48,10 @@ function App() {
|
||||
}
|
||||
}
|
||||
|
||||
if (isJoinTour) {
|
||||
if (journeyToken) {
|
||||
setShareJourneyToken(journeyToken);
|
||||
setCurrentPage('shareJourney');
|
||||
} else if (isJoinTour) {
|
||||
setCurrentPage('joinTour');
|
||||
} else if (viewTourId) {
|
||||
setCurrentPage('tourDetail');
|
||||
@@ -139,6 +144,13 @@ function App() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleGoToHome = () => {
|
||||
window.history.pushState({}, '', '/');
|
||||
setShareJourneyToken(null);
|
||||
const loggedIn = !!localStorage.getItem('token');
|
||||
setCurrentPage(loggedIn ? 'dashboard' : 'landing');
|
||||
};
|
||||
|
||||
return (
|
||||
<ConfirmProvider>
|
||||
<NotificationProvider>
|
||||
@@ -211,6 +223,15 @@ function App() {
|
||||
);
|
||||
}
|
||||
|
||||
if (currentPage === 'shareJourney') {
|
||||
return (
|
||||
<ShareJourneyPage
|
||||
token={shareJourneyToken!}
|
||||
onGoToHome={handleGoToHome}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <LandingPage onContinue={() => setCurrentPage('explore')} onGoToSignup={() => setCurrentPage('signup')} onGoToMap={() => setCurrentPage('explore')} onLoginSuccess={handleLoginSuccess} isInitialSetup={false} />;
|
||||
})()}
|
||||
</NotificationProvider>
|
||||
|
||||
Reference in New Issue
Block a user