fix tut flow

This commit is contained in:
seaznCode 2026-01-18 23:20:02 +01:00
parent 329a71931b
commit 75f4257a69
8 changed files with 35 additions and 58 deletions

View File

@ -40,6 +40,7 @@ export default function QuickActionDashboardPage() {
const [isTutorialOpen, setIsTutorialOpen] = useState(false) const [isTutorialOpen, setIsTutorialOpen] = useState(false)
const [currentTutorialStep, setCurrentTutorialStep] = useState(1) const [currentTutorialStep, setCurrentTutorialStep] = useState(1)
const [hasSeenTutorial, setHasSeenTutorial] = useState(false) const [hasSeenTutorial, setHasSeenTutorial] = useState(false)
const forceOpenRef = useRef(false)
useEffect(() => { useEffect(() => {
setIsClient(true) setIsClient(true)
@ -69,7 +70,11 @@ export default function QuickActionDashboardPage() {
useEffect(() => { useEffect(() => {
if (!isClient) return if (!isClient) return
if (loading || !userStatus) 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]) }, [isClient, loading, userStatus, allDone, smoothReplace])
// NEW: decide which tutorial step to start on // 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) // CHANGED: single auto-open mechanism (works even if tutorial_seen exists)
useEffect(() => { useEffect(() => {
if (!isClient) return 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 (loading || !userStatus) return
if (allDone) return // NEW: avoid tutorial flash during redirect
if (isTutorialOpen && forceOpenRef.current) {
setCurrentTutorialStep(getNextTutorialStep())
}
if (isTutorialOpen) return if (isTutorialOpen) return
const uid = const uid =
@ -100,9 +120,6 @@ export default function QuickActionDashboardPage() {
const tokenSuffix = (accessToken || '').slice(-12) || 'no-token' const tokenSuffix = (accessToken || '').slice(-12) || 'no-token'
const sessionKey = `pp:tutorialShown:${uid}:${tokenSuffix}` const sessionKey = `pp:tutorialShown:${uid}:${tokenSuffix}`
const urlParams = new URLSearchParams(window.location.search)
const forceOpen = urlParams.get('tutorial') === 'true'
if (forceOpen) { if (forceOpen) {
window.history.replaceState({}, '', window.location.pathname) window.history.replaceState({}, '', window.location.pathname)
} }
@ -180,7 +197,8 @@ export default function QuickActionDashboardPage() {
setIsTutorialOpen(false) setIsTutorialOpen(false)
localStorage.setItem('tutorial_seen', 'true') localStorage.setItem('tutorial_seen', 'true')
setHasSeenTutorial(true) setHasSeenTutorial(true)
}, []) if (allDone) smoothReplace('/dashboard')
}, [allDone, smoothReplace])
const nextTutorialStep = useCallback(() => { const nextTutorialStep = useCallback(() => {
setCurrentTutorialStep(prev => prev + 1) setCurrentTutorialStep(prev => prev + 1)

View File

@ -306,17 +306,9 @@ export default function CompanyAdditionalInformationPage() {
// Refresh user status to update profile completion state // Refresh user status to update profile completion state
await refreshStatus() await refreshStatus()
// Redirect to next step after short delay // Redirect back to tutorial modal after short delay
setTimeout(() => { setTimeout(() => {
// Check if we came from tutorial router.push('/quickaction-dashboard?tutorial=true')
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')
}
}, 1500) }, 1500)
} catch (error: any) { } catch (error: any) {

View File

@ -387,17 +387,9 @@ export default function PersonalAdditionalInformationPage() {
// Refresh user status to update profile completion state // Refresh user status to update profile completion state
await refreshStatus() await refreshStatus()
// Redirect to next step after short delay // Redirect back to tutorial modal after short delay
setTimeout(() => { setTimeout(() => {
// Check if we came from tutorial router.push('/quickaction-dashboard?tutorial=true')
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')
}
}, 1500) }, 1500)
} catch (error: any) { } catch (error: any) {

View File

@ -236,15 +236,7 @@ export default function EmailVerifyPage() {
message: 'Your email has been verified successfully.' message: 'Your email has been verified successfully.'
}) })
await refreshStatus() await refreshStatus()
setTimeout(() => { window.location.href = '/quickaction-dashboard?tutorial=true'
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)
} else { } else {
const msg = data.error || 'Verification failed. Please try again.' const msg = data.error || 'Verification failed. Please try again.'
setError(msg) setError(msg)

View File

@ -277,9 +277,9 @@ export default function CompanySignContractPage() {
// Refresh user status to update contract signed state // Refresh user status to update contract signed state
await refreshStatus() await refreshStatus()
// Redirect to main dashboard after short delay // Redirect back to tutorial modal after short delay
setTimeout(() => { setTimeout(() => {
router.push('/dashboard') router.push('/quickaction-dashboard?tutorial=true')
}, 2000) }, 2000)
} catch (error: unknown) { } catch (error: unknown) {

View File

@ -314,9 +314,9 @@ export default function PersonalSignContractPage() {
// Refresh user status to update contract signed state // Refresh user status to update contract signed state
await refreshStatus() await refreshStatus()
// Redirect to main dashboard after short delay // Redirect back to tutorial modal after short delay
setTimeout(() => { setTimeout(() => {
router.push('/dashboard') router.push('/quickaction-dashboard?tutorial=true')
}, 2000) }, 2000)
} catch (error: unknown) { } catch (error: unknown) {

View File

@ -149,16 +149,7 @@ export function useCompanyUploadId() {
await refreshStatus() await refreshStatus()
setTimeout(() => { setTimeout(() => {
// Check if we came from tutorial window.location.href = '/quickaction-dashboard?tutorial=true'
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'
}
}, 1500) }, 1500)
} catch (err: any) { } catch (err: any) {
console.error('Company ID upload error:', err) console.error('Company ID upload error:', err)

View File

@ -165,15 +165,7 @@ export function usePersonalUploadId() {
}) })
await refreshStatus() await refreshStatus()
setTimeout(() => { setTimeout(() => {
// Check if we came from tutorial window.location.href = '/quickaction-dashboard?tutorial=true'
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) }, 2000)
} else { } else {
const msg = data.message || 'Upload failed. Please try again.' const msg = data.message || 'Upload failed. Please try again.'