-
Notifications
You must be signed in to change notification settings - Fork 10
feat: Onboarding MVP #1499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sidneyswift
wants to merge
14
commits into
test
Choose a base branch
from
feat/onboarding-mvp
base: test
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: Onboarding MVP #1499
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
90f6423
feat: [US-001] - Create onboarding route with minimal layout
sidneyswift 4074957
feat: [US-002] - Create useOnboarding state management hook
sidneyswift c6ba4f1
feat: [US-004] - Create OnboardingProgress indicator component
sidneyswift f4f189a
feat: [US-005] - Create WelcomeStep component
sidneyswift c845a29
feat: [US-006] - Create RoleStep component
sidneyswift 56e5e2e
feat: [US-007] Create ArtistsStep component
sidneyswift b1841a5
feat: [US-008] add onboarding template helpers
sidneyswift 711095d
feat: [US-009] Create runOnboardingTask helper function
sidneyswift 46eab86
feat: [US-010] Create TaskPickerStep component
sidneyswift 257a68b
feat: [US-011] Create RunningStep component
sidneyswift a022a7c
feat: [US-012] Create ResultStep component
sidneyswift 3ba3311
feat: [US-013] Create RecurringStep component
sidneyswift 6501f60
feat: [US-014] Create CompleteStep component
sidneyswift 6f02c39
feat: [US-016] Add onboarding detection and redirect
sidneyswift File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { NextResponse } from "next/server"; | ||
| import { fetchOnboardingTemplates } from "@/lib/onboarding/fetchOnboardingTemplates"; | ||
|
|
||
| export const runtime = "edge"; | ||
|
|
||
| /** | ||
| * GET /api/onboarding-templates | ||
| * Fetches all onboarding templates (system templates with 'onboarding' tag) | ||
| */ | ||
| export async function GET() { | ||
| try { | ||
| const templates = await fetchOnboardingTemplates(); | ||
| return NextResponse.json(templates); | ||
| } catch (error) { | ||
| console.error("Error fetching onboarding templates:", error); | ||
| return NextResponse.json( | ||
| { error: "Failed to fetch onboarding templates" }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export const dynamic = "force-dynamic"; | ||
| export const revalidate = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| export default function OnboardingLayout({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) { | ||
| return ( | ||
| <div className="fixed inset-0 z-50 bg-background"> | ||
| <div className="h-full w-full overflow-y-auto"> | ||
| {children} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import OnboardingFlow from "@/components/Onboarding/OnboardingFlow"; | ||
|
|
||
| export default function OnboardingPage() { | ||
| return <OnboardingFlow />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| "use client"; | ||
|
|
||
| import { useOnboarding, type OnboardingStep } from "@/hooks/useOnboarding"; | ||
| import OnboardingProgress from "./OnboardingProgress"; | ||
| import { | ||
| WelcomeStep, | ||
| RoleStep, | ||
| ArtistsStep, | ||
| TaskPickerStep, | ||
| RunningStep, | ||
| ResultStep, | ||
| RecurringStep, | ||
| CompleteStep, | ||
| } from "./steps"; | ||
|
|
||
| interface StepComponentProps { | ||
| onNext: () => void; | ||
| onBack: () => void; | ||
| } | ||
|
|
||
| type StepComponent = React.ComponentType<StepComponentProps>; | ||
|
|
||
| const STEP_COMPONENTS: Record<OnboardingStep, StepComponent> = { | ||
| welcome: WelcomeStep, | ||
| role: RoleStep, | ||
| artists: ArtistsStep, | ||
| "task-picker": TaskPickerStep, | ||
| running: RunningStep, | ||
| result: ResultStep, | ||
| recurring: RecurringStep, | ||
| complete: CompleteStep, | ||
| }; | ||
|
|
||
| export default function OnboardingFlow() { | ||
| const { step, nextStep, prevStep, currentStepIndex, totalSteps } = | ||
| useOnboarding(); | ||
|
|
||
| const StepComponent = STEP_COMPONENTS[step]; | ||
|
|
||
| return ( | ||
| <div className="flex flex-col items-center min-h-screen py-8 px-4"> | ||
| {/* Progress indicator - rendered above step content */} | ||
| <div className="w-full max-w-2xl mb-8"> | ||
| <OnboardingProgress | ||
| currentStep={step} | ||
| currentStepIndex={currentStepIndex} | ||
| totalSteps={totalSteps} | ||
| /> | ||
| </div> | ||
|
|
||
| {/* Current step content */} | ||
| <div className="w-full max-w-2xl flex-1"> | ||
| <StepComponent onNext={nextStep} onBack={prevStep} /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect, useRef } from "react"; | ||
| import { useRouter, usePathname } from "next/navigation"; | ||
| import { useUserProvider } from "@/providers/UserProvder"; | ||
| import { useArtistProvider } from "@/providers/ArtistProvider"; | ||
| import useAccountOrganizations from "@/hooks/useAccountOrganizations"; | ||
| import { needsOnboarding, OnboardingStatus } from "@/lib/onboarding"; | ||
|
|
||
| /** | ||
| * OnboardingGuard component that redirects new org users to /onboarding | ||
| * if they haven't completed onboarding yet. | ||
| * | ||
| * Conditions for redirect: | ||
| * 1. User has at least one organization | ||
| * 2. onboarding_status.completed !== true | ||
| * 3. Organization has at least one artist | ||
| * 4. Not already on /onboarding route | ||
| */ | ||
| const OnboardingGuard = ({ children }: { children: React.ReactNode }) => { | ||
| const router = useRouter(); | ||
| const pathname = usePathname(); | ||
| const { userData } = useUserProvider(); | ||
| const { artists, isLoading: artistsLoading } = useArtistProvider(); | ||
| const { data: organizations, isLoading: orgsLoading } = | ||
| useAccountOrganizations(); | ||
| const hasChecked = useRef(false); | ||
|
|
||
| useEffect(() => { | ||
| // Skip if data is still loading | ||
| if (orgsLoading || artistsLoading) { | ||
| return; | ||
| } | ||
|
|
||
| // Skip if no userData yet | ||
| if (!userData) { | ||
| return; | ||
| } | ||
|
|
||
| // Skip if already on onboarding route | ||
| if (pathname?.startsWith("/onboarding")) { | ||
| return; | ||
| } | ||
|
|
||
| // Skip if already checked this session (to prevent redirect loops) | ||
| if (hasChecked.current) { | ||
| return; | ||
| } | ||
|
|
||
| // Parse onboarding_status from userData | ||
| const onboardingStatus = userData.onboarding_status as | ||
| | OnboardingStatus | ||
| | null | ||
| | undefined; | ||
|
|
||
| // Check if org has artists | ||
| const orgHasArtists = artists && artists.length > 0; | ||
|
|
||
| const shouldRedirect = needsOnboarding({ | ||
| onboardingStatus, | ||
| organizations, | ||
| orgHasArtists, | ||
| }); | ||
|
|
||
| // Mark as checked to prevent re-checking | ||
| hasChecked.current = true; | ||
|
|
||
| if (shouldRedirect) { | ||
| router.push("/onboarding"); | ||
| } | ||
| }, [ | ||
| userData, | ||
| organizations, | ||
| artists, | ||
| orgsLoading, | ||
| artistsLoading, | ||
| pathname, | ||
| router, | ||
| ]); | ||
|
|
||
| return <>{children}</>; | ||
| }; | ||
|
|
||
| export default OnboardingGuard; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| "use client"; | ||
|
|
||
| import { cn } from "@/lib/utils"; | ||
| import { type OnboardingStep } from "@/hooks/useOnboarding"; | ||
|
|
||
| interface OnboardingProgressProps { | ||
| currentStep: OnboardingStep; | ||
| currentStepIndex: number; | ||
| totalSteps: number; | ||
| className?: string; | ||
| } | ||
|
|
||
| // Brand primary color: #345A5D | ||
| const BRAND_PRIMARY = "#345A5D"; | ||
|
|
||
| // Step order for dot display | ||
| const STEPS_ORDER: OnboardingStep[] = [ | ||
| "welcome", | ||
| "role", | ||
| "artists", | ||
| "task-picker", | ||
| "running", | ||
| "result", | ||
| "recurring", | ||
| "complete", | ||
| ]; | ||
|
|
||
| export default function OnboardingProgress({ | ||
| currentStepIndex, | ||
| totalSteps, | ||
| className, | ||
| }: OnboardingProgressProps) { | ||
| // Calculate progress percentage | ||
| const progressPercentage = ((currentStepIndex + 1) / totalSteps) * 100; | ||
|
|
||
| return ( | ||
| <div className={cn("w-full max-w-md mx-auto", className)}> | ||
| {/* Step indicator text */} | ||
| <div className="flex items-center justify-between mb-2"> | ||
| <span className="text-sm text-muted-foreground"> | ||
| Step {currentStepIndex + 1} of {totalSteps} | ||
| </span> | ||
| <span className="text-sm text-muted-foreground"> | ||
| {Math.round(progressPercentage)}% | ||
| </span> | ||
| </div> | ||
|
|
||
| {/* Progress bar */} | ||
| <div className="relative h-2 w-full overflow-hidden rounded-full bg-muted"> | ||
| <div | ||
| className="h-full transition-all duration-300 ease-out rounded-full" | ||
| style={{ | ||
| width: `${progressPercentage}%`, | ||
| backgroundColor: BRAND_PRIMARY, | ||
| }} | ||
| /> | ||
| </div> | ||
|
|
||
| {/* Step dots */} | ||
| <div className="flex justify-between mt-3"> | ||
| {STEPS_ORDER.map((step, index) => { | ||
| const isCompleted = index < currentStepIndex; | ||
| const isCurrent = index === currentStepIndex; | ||
|
|
||
| return ( | ||
| <div | ||
| key={step} | ||
| className={cn( | ||
| "w-2.5 h-2.5 rounded-full transition-all duration-200", | ||
| isCompleted && "scale-100", | ||
| isCurrent && "scale-125 ring-2 ring-offset-2 ring-offset-background", | ||
| !isCompleted && !isCurrent && "bg-muted" | ||
| )} | ||
| style={{ | ||
| backgroundColor: isCompleted || isCurrent ? BRAND_PRIMARY : undefined, | ||
| ["--tw-ring-color" as string]: isCurrent ? BRAND_PRIMARY : undefined, | ||
| }} | ||
| aria-label={`Step ${index + 1}: ${step}`} | ||
| aria-current={isCurrent ? "step" : undefined} | ||
| /> | ||
| ); | ||
| })} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The guard bases its redirect decision on
userData.onboarding_status, but the completion flow only posts to/api/account/updateand does not refreshuserDatain the same session. As a result, right after onboarding completion, the first navigation to/can still look incomplete to this guard and bounce the user back to/onboardinguntil a full reload. Consider updatinguserDatawith the completion response or checking a local completion flag so the guard reflects the just-finished state.Useful? React with 👍 / 👎.