diff --git a/src/app/quickaction-dashboard/page.tsx b/src/app/quickaction-dashboard/page.tsx index 09222af..af7394c 100644 --- a/src/app/quickaction-dashboard/page.tsx +++ b/src/app/quickaction-dashboard/page.tsx @@ -40,6 +40,7 @@ export default function QuickActionDashboardPage() { const [isTutorialOpen, setIsTutorialOpen] = useState(false) const [currentTutorialStep, setCurrentTutorialStep] = useState(1) const [hasSeenTutorial, setHasSeenTutorial] = useState(false) + const forceOpenRef = useRef(false) useEffect(() => { setIsClient(true) @@ -69,7 +70,11 @@ export default function QuickActionDashboardPage() { useEffect(() => { if (!isClient) return if (loading || !userStatus) return - if (allDone) smoothReplace('/dashboard') // CHANGED + + const urlParams = new URLSearchParams(window.location.search) + const forceOpen = urlParams.get('tutorial') === 'true' + + if (allDone && !forceOpen) smoothReplace('/dashboard') }, [isClient, loading, userStatus, allDone, smoothReplace]) // NEW: decide which tutorial step to start on @@ -86,8 +91,23 @@ export default function QuickActionDashboardPage() { // CHANGED: single auto-open mechanism (works even if tutorial_seen exists) useEffect(() => { if (!isClient) return + const urlParams = new URLSearchParams(window.location.search) + const forceOpen = urlParams.get('tutorial') === 'true' + + if (forceOpen && !forceOpenRef.current && !isTutorialOpen) { + // Open immediately to avoid dashboard flash; step will be corrected once status loads + setCurrentTutorialStep(1) + setIsTutorialOpen(true) + forceOpenRef.current = true + return + } + if (loading || !userStatus) return - if (allDone) return // NEW: avoid tutorial flash during redirect + + if (isTutorialOpen && forceOpenRef.current) { + setCurrentTutorialStep(getNextTutorialStep()) + } + if (isTutorialOpen) return const uid = @@ -100,9 +120,6 @@ export default function QuickActionDashboardPage() { const tokenSuffix = (accessToken || '').slice(-12) || 'no-token' const sessionKey = `pp:tutorialShown:${uid}:${tokenSuffix}` - - const urlParams = new URLSearchParams(window.location.search) - const forceOpen = urlParams.get('tutorial') === 'true' if (forceOpen) { window.history.replaceState({}, '', window.location.pathname) } @@ -180,7 +197,8 @@ export default function QuickActionDashboardPage() { setIsTutorialOpen(false) localStorage.setItem('tutorial_seen', 'true') setHasSeenTutorial(true) - }, []) + if (allDone) smoothReplace('/dashboard') + }, [allDone, smoothReplace]) const nextTutorialStep = useCallback(() => { setCurrentTutorialStep(prev => prev + 1) diff --git a/src/app/quickaction-dashboard/register-additional-information/company/page.tsx b/src/app/quickaction-dashboard/register-additional-information/company/page.tsx index 49f4fb8..dd2419d 100644 --- a/src/app/quickaction-dashboard/register-additional-information/company/page.tsx +++ b/src/app/quickaction-dashboard/register-additional-information/company/page.tsx @@ -306,17 +306,9 @@ export default function CompanyAdditionalInformationPage() { // Refresh user status to update profile completion state await refreshStatus() - // Redirect to next step after short delay + // Redirect back to tutorial modal after short delay setTimeout(() => { - // Check if we came from tutorial - const urlParams = new URLSearchParams(window.location.search) - const fromTutorial = urlParams.get('tutorial') === 'true' - - if (fromTutorial) { - router.push('/quickaction-dashboard?tutorial=true') - } else { - router.push('/quickaction-dashboard/register-sign-contract/company') - } + router.push('/quickaction-dashboard?tutorial=true') }, 1500) } catch (error: any) { diff --git a/src/app/quickaction-dashboard/register-additional-information/personal/page.tsx b/src/app/quickaction-dashboard/register-additional-information/personal/page.tsx index e1328d1..f12c21d 100644 --- a/src/app/quickaction-dashboard/register-additional-information/personal/page.tsx +++ b/src/app/quickaction-dashboard/register-additional-information/personal/page.tsx @@ -387,17 +387,9 @@ export default function PersonalAdditionalInformationPage() { // Refresh user status to update profile completion state await refreshStatus() - // Redirect to next step after short delay + // Redirect back to tutorial modal after short delay setTimeout(() => { - // Check if we came from tutorial - const urlParams = new URLSearchParams(window.location.search) - const fromTutorial = urlParams.get('tutorial') === 'true' - - if (fromTutorial) { - router.push('/quickaction-dashboard?tutorial=true') - } else { - router.push('/quickaction-dashboard/register-sign-contract/personal') - } + router.push('/quickaction-dashboard?tutorial=true') }, 1500) } catch (error: any) { diff --git a/src/app/quickaction-dashboard/register-email-verify/page.tsx b/src/app/quickaction-dashboard/register-email-verify/page.tsx index cfcb70c..bd046b8 100644 --- a/src/app/quickaction-dashboard/register-email-verify/page.tsx +++ b/src/app/quickaction-dashboard/register-email-verify/page.tsx @@ -236,15 +236,7 @@ export default function EmailVerifyPage() { message: 'Your email has been verified successfully.' }) await refreshStatus() - setTimeout(() => { - const urlParams = new URLSearchParams(window.location.search) - const fromTutorial = urlParams.get('tutorial') === 'true' - if (fromTutorial) { - window.location.href = '/quickaction-dashboard?tutorial=true' - } else { - window.location.href = '/quickaction-dashboard' - } - }, 2000) + window.location.href = '/quickaction-dashboard?tutorial=true' } else { const msg = data.error || 'Verification failed. Please try again.' setError(msg) diff --git a/src/app/quickaction-dashboard/register-sign-contract/company/page.tsx b/src/app/quickaction-dashboard/register-sign-contract/company/page.tsx index 75e0427..21f8286 100644 --- a/src/app/quickaction-dashboard/register-sign-contract/company/page.tsx +++ b/src/app/quickaction-dashboard/register-sign-contract/company/page.tsx @@ -277,9 +277,9 @@ export default function CompanySignContractPage() { // Refresh user status to update contract signed state await refreshStatus() - // Redirect to main dashboard after short delay + // Redirect back to tutorial modal after short delay setTimeout(() => { - router.push('/dashboard') + router.push('/quickaction-dashboard?tutorial=true') }, 2000) } catch (error: unknown) { diff --git a/src/app/quickaction-dashboard/register-sign-contract/personal/page.tsx b/src/app/quickaction-dashboard/register-sign-contract/personal/page.tsx index 8ee3f66..8f56e2b 100644 --- a/src/app/quickaction-dashboard/register-sign-contract/personal/page.tsx +++ b/src/app/quickaction-dashboard/register-sign-contract/personal/page.tsx @@ -314,9 +314,9 @@ export default function PersonalSignContractPage() { // Refresh user status to update contract signed state await refreshStatus() - // Redirect to main dashboard after short delay + // Redirect back to tutorial modal after short delay setTimeout(() => { - router.push('/dashboard') + router.push('/quickaction-dashboard?tutorial=true') }, 2000) } catch (error: unknown) { diff --git a/src/app/quickaction-dashboard/register-upload-id/company/hooks/useCompanyUploadId.ts b/src/app/quickaction-dashboard/register-upload-id/company/hooks/useCompanyUploadId.ts index 9b0ece5..1b1d35e 100644 --- a/src/app/quickaction-dashboard/register-upload-id/company/hooks/useCompanyUploadId.ts +++ b/src/app/quickaction-dashboard/register-upload-id/company/hooks/useCompanyUploadId.ts @@ -149,16 +149,7 @@ export function useCompanyUploadId() { await refreshStatus() setTimeout(() => { - // Check if we came from tutorial - const urlParams = new URLSearchParams(window.location.search) - const fromTutorial = urlParams.get('tutorial') === 'true' - - if (fromTutorial) { - window.location.href = '/quickaction-dashboard?tutorial=true' - } else { - // keep same redirect as page used before - window.location.href = '/quickaction-dashboard/register-additional-information' - } + window.location.href = '/quickaction-dashboard?tutorial=true' }, 1500) } catch (err: any) { console.error('Company ID upload error:', err) diff --git a/src/app/quickaction-dashboard/register-upload-id/personal/hooks/usePersonalUploadId.ts b/src/app/quickaction-dashboard/register-upload-id/personal/hooks/usePersonalUploadId.ts index 4ce45c8..94ff7c7 100644 --- a/src/app/quickaction-dashboard/register-upload-id/personal/hooks/usePersonalUploadId.ts +++ b/src/app/quickaction-dashboard/register-upload-id/personal/hooks/usePersonalUploadId.ts @@ -165,15 +165,7 @@ export function usePersonalUploadId() { }) await refreshStatus() setTimeout(() => { - // Check if we came from tutorial - const urlParams = new URLSearchParams(window.location.search) - const fromTutorial = urlParams.get('tutorial') === 'true' - - if (fromTutorial) { - window.location.href = '/quickaction-dashboard?tutorial=true' - } else { - window.location.href = '/quickaction-dashboard' - } + window.location.href = '/quickaction-dashboard?tutorial=true' }, 2000) } else { const msg = data.message || 'Upload failed. Please try again.'