From 60057b6c94814244d3245f83df12b9993140ab42 Mon Sep 17 00:00:00 2001 From: Seazn Date: Sun, 15 Mar 2026 01:11:57 +0100 Subject: [PATCH] feat: enhance user flow for guest and regular users in quick action and dashboard pages --- src/app/dashboard/page.tsx | 30 +- src/app/quickaction-dashboard/page.tsx | 279 +++++++++++------- .../register-email-verify/page.tsx | 24 +- 3 files changed, 200 insertions(+), 133 deletions(-) diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index bfddc4e..36359c9 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -78,16 +78,20 @@ export default function DashboardPage() { } }, [isAuthReady, user, router]) - // NEW: block dashboard unless all 4 quickaction steps are completed + // NEW: block dashboard unless all quickaction steps are completed + // For guest users: only email verification is required + // For regular users: all 4 steps must be completed useEffect(() => { if (!isAuthReady || !user) return if (statusLoading || !userStatus) return - const allDone = - !!userStatus.email_verified && - !!userStatus.documents_uploaded && - !!userStatus.profile_completed && - !!userStatus.contract_signed + const isGuest = user?.role === 'guest' + const allDone = isGuest + ? !!userStatus.email_verified + : !!userStatus.email_verified && + !!userStatus.documents_uploaded && + !!userStatus.profile_completed && + !!userStatus.contract_signed if (!allDone) smoothReplace('/quickaction-dashboard') }, [isAuthReady, user, statusLoading, userStatus, smoothReplace]) @@ -116,13 +120,15 @@ export default function DashboardPage() { ) } - // NEW: final guard (don’t render dashboard if not all done) + // Final guard (don't render dashboard if not all done) if (!userStatus) return null - const allDone = - !!userStatus.email_verified && - !!userStatus.documents_uploaded && - !!userStatus.profile_completed && - !!userStatus.contract_signed + const isGuestUser = user?.role === 'guest' + const allDone = isGuestUser + ? !!userStatus.email_verified + : !!userStatus.email_verified && + !!userStatus.documents_uploaded && + !!userStatus.profile_completed && + !!userStatus.contract_signed if (!allDone) return null // Get user name diff --git a/src/app/quickaction-dashboard/page.tsx b/src/app/quickaction-dashboard/page.tsx index dc5729f..2a714f9 100644 --- a/src/app/quickaction-dashboard/page.tsx +++ b/src/app/quickaction-dashboard/page.tsx @@ -90,8 +90,13 @@ export default function QuickActionDashboardPage() { const additionalInfo = userStatus?.profile_completed || false const contractSigned = userStatus?.contract_signed || false - // NEW: if everything is done, quickaction-dashboard is no longer accessible - const allDone = emailVerified && idUploaded && additionalInfo && contractSigned + // Detect guest user — guests only need email verification + const isGuest = isClient && user?.role === 'guest' + + // For guests: only email verification matters. For regular users: all 4 steps. + const allDone = isGuest + ? emailVerified + : emailVerified && idUploaded && additionalInfo && contractSigned // NEW: smooth redirect (prevents snappy double navigation) const [redirectTo, setRedirectTo] = useState(null) const redirectOnceRef = useRef(false) @@ -167,36 +172,47 @@ export default function QuickActionDashboardPage() { sessionStorage.setItem(sessionKey, '1') }, [isClient, loading, userStatus, isTutorialOpen, user, accessToken, getNextTutorialStep]) - const statusItems: StatusItem[] = [ - { - key: 'email', - label: 'Email Verification', - description: emailVerified ? 'Verified' : 'Missing', - complete: emailVerified, - icon: EnvelopeOpenIcon - }, - { - key: 'id', - label: 'ID Document', - description: idUploaded ? 'Uploaded' : 'Missing', - complete: idUploaded, - icon: IdentificationIcon - }, - { - key: 'info', - label: 'Additional Info', - description: additionalInfo ? 'Completed' : 'Missing', - complete: additionalInfo, - icon: InformationCircleIcon - }, - { - key: 'contract', - label: 'Contract', - description: contractSigned ? 'Signed' : 'Missing', - complete: contractSigned, - icon: DocumentCheckIcon - } - ] + // For guests: only show email verification step. For regular users: all 4 steps. + const statusItems: StatusItem[] = isGuest + ? [ + { + key: 'email', + label: 'Email Verification', + description: emailVerified ? 'Verified' : 'Missing', + complete: emailVerified, + icon: EnvelopeOpenIcon + } + ] + : [ + { + key: 'email', + label: 'Email Verification', + description: emailVerified ? 'Verified' : 'Missing', + complete: emailVerified, + icon: EnvelopeOpenIcon + }, + { + key: 'id', + label: 'ID Document', + description: idUploaded ? 'Uploaded' : 'Missing', + complete: idUploaded, + icon: IdentificationIcon + }, + { + key: 'info', + label: 'Additional Info', + description: additionalInfo ? 'Completed' : 'Missing', + complete: additionalInfo, + icon: InformationCircleIcon + }, + { + key: 'contract', + label: 'Contract', + description: contractSigned ? 'Signed' : 'Missing', + complete: contractSigned, + icon: DocumentCheckIcon + } + ] // Action handlers - navigate to proper QuickAction pages with tutorial callback const handleVerifyEmail = useCallback(() => { @@ -313,7 +329,11 @@ export default function QuickActionDashboardPage() { Welcome{isClient && user?.firstName ? `, ${user.firstName}` : ''}!

- {isClient && user?.userType === 'company' ? 'Company Account' : 'Personal Account'} + {isGuest + ? 'Guest Account' + : isClient && user?.userType === 'company' + ? 'Company Account' + : 'Personal Account'}

{loading &&

Loading status...

} {error && ( @@ -350,11 +370,14 @@ export default function QuickActionDashboardPage() { {/* Status Overview */}

- Status Overview + {isGuest ? 'Email Verification Status' : 'Status Overview'}

- {/* CHANGED: mobile 2x2 grid */} -
+ {/* Guest: single centered card. Regular: 2x2 / 4-col grid */} +
{statusItems.map(item => { const CompleteIcon = item.complete ? CheckCircleIcon : XCircleIcon return ( @@ -362,7 +385,7 @@ export default function QuickActionDashboardPage() { key={item.key} className={`rounded-lg px-3 py-4 sm:px-4 sm:py-6 flex flex-col items-center text-center border transition-colors ${ item.complete ? 'bg-emerald-50 border-emerald-100' : 'bg-rose-50 border-rose-100' - }`} + } ${isGuest ? 'w-full max-w-xs' : ''}`} >

- Quick Actions + {isGuest ? 'Action Required' : 'Quick Actions'}

- + {/* Tutorial button — only for regular users */} + {!isGuest && ( + + )}
- {/* CHANGED: mobile 2x2 grid (order already matches desired layout) */} -
- {/* Email Verification */} -
+ {isGuest ? ( + /* ── Guest view: single email verification action ── */ +
+
+

+ Please verify your email address to activate your guest account and access your subscriptions. +

+ + {!emailVerified && ( +

+ {resendRemainingSec > 0 + ? `Resend available in ${formatMmSs(resendRemainingSec)}` + : 'You can request a new code now'} +

+ )} +
+
+ ) : ( + /* ── Regular user view: all 4 quick action buttons ── */ +
+ {/* Email Verification */} +
+ + {!emailVerified && ( +

+ {resendRemainingSec > 0 + ? `Resend available in ${formatMmSs(resendRemainingSec)}` + : 'You can request a new code now'} +

+ )} +
+ + {/* ID Upload */} - {/* NEW: resend feedback (only when not verified) */} - {!emailVerified && ( -

- {resendRemainingSec > 0 - ? `Resend available in ${formatMmSs(resendRemainingSec)}` - : 'You can request a new code now'} -

- )} -
- {/* ID Upload */} - - - {/* Additional Info */} - - - {/* Sign Contract */} -
+ {/* Additional Info */} - {!canSignContract && !contractSigned && ( -

- Complete previous steps (email, ID, profile) before signing the contract. -

- )} + + {/* Sign Contract */} +
+ + {!canSignContract && !contractSigned && ( +

+ Complete previous steps (email, ID, profile) before signing the contract. +

+ )} +
-
+ )}
{/* Latest News */} diff --git a/src/app/quickaction-dashboard/register-email-verify/page.tsx b/src/app/quickaction-dashboard/register-email-verify/page.tsx index bd046b8..43c5e57 100644 --- a/src/app/quickaction-dashboard/register-email-verify/page.tsx +++ b/src/app/quickaction-dashboard/register-email-verify/page.tsx @@ -236,7 +236,9 @@ export default function EmailVerifyPage() { message: 'Your email has been verified successfully.' }) await refreshStatus() - window.location.href = '/quickaction-dashboard?tutorial=true' + // Guests go directly to dashboard after email verification + const isGuest = user?.role === 'guest' + window.location.href = isGuest ? '/dashboard' : '/quickaction-dashboard?tutorial=true' } else { const msg = data.error || 'Verification failed. Please try again.' setError(msg) @@ -345,18 +347,22 @@ export default function EmailVerifyPage() { useEffect(() => { if (statusLoading || !userStatus) return - const allDone = - !!userStatus.email_verified && - !!userStatus.documents_uploaded && - !!userStatus.profile_completed && - !!userStatus.contract_signed + const isGuest = user?.role === 'guest' + const allDone = isGuest + ? !!userStatus.email_verified + : !!userStatus.email_verified && + !!userStatus.documents_uploaded && + !!userStatus.profile_completed && + !!userStatus.contract_signed if (allDone) { - smoothReplace('/dashboard') // CHANGED + smoothReplace('/dashboard') } else if (userStatus.email_verified) { - smoothReplace('/quickaction-dashboard') // CHANGED + // Regular users go back to quickaction dashboard for remaining steps + // Guests should never reach here since allDone covers them + smoothReplace('/quickaction-dashboard') } - }, [statusLoading, userStatus, smoothReplace]) + }, [statusLoading, userStatus, user, smoothReplace]) // NEW: must be logged in useEffect(() => {