-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/marketing page improvements #22
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // src/hooks/useOnboarding.ts | ||
| "use client"; | ||
|
|
||
| import { useState, useEffect, useCallback } from "react"; | ||
|
|
||
| const ONBOARDING_KEY = "tradia_onboarding_complete"; | ||
| const ONBOARDING_STEP_KEY = "tradia_onboarding_step"; | ||
|
|
||
| export type OnboardingStep = | ||
| | "welcome" | ||
| | "create-account" | ||
| | "import-trades" | ||
| | "setup-preferences" | ||
| | "complete"; | ||
|
|
||
| interface OnboardingState { | ||
| isComplete: boolean; | ||
| currentStep: OnboardingStep; | ||
| hasAccount: boolean; | ||
| hasTrades: boolean; | ||
| hasPreferences: boolean; | ||
| } | ||
|
|
||
| export function useOnboarding() { | ||
| const [state, setState] = useState<OnboardingState>({ | ||
| isComplete: false, | ||
| currentStep: "welcome", | ||
| hasAccount: false, | ||
| hasTrades: false, | ||
| hasPreferences: false, | ||
|
Comment on lines
+28
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For users who follow the primary CTAs, these flags never get updated from the actual account/trade state, so the onboarding flow gets stuck. I checked that Useful? React with 👍 / 👎.
Comment on lines
+28
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For users who follow the primary CTAs, these flags never get updated from the actual account/trade/settings state, so the onboarding flow gets stuck. I checked that Useful? React with 👍 / 👎. |
||
| }); | ||
| const [isLoading, setIsLoading] = useState(true); | ||
|
|
||
| useEffect(() => { | ||
| if (typeof window === "undefined") { | ||
| setIsLoading(false); | ||
| return; | ||
| } | ||
| const stored = localStorage.getItem(ONBOARDING_KEY); | ||
| const step = localStorage.getItem(ONBOARDING_STEP_KEY) as OnboardingStep | null; | ||
|
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If Useful? React with 👍 / 👎. |
||
|
|
||
| if (stored === "true") { | ||
| setState(s => ({ ...s, isComplete: true, currentStep: "complete" })); | ||
| } else { | ||
| setState(s => ({ ...s, currentStep: step || "welcome" })); | ||
| } | ||
| setIsLoading(false); | ||
| }, []); | ||
|
|
||
| const completeStep = useCallback((step: OnboardingStep) => { | ||
| let nextStep: OnboardingStep = "welcome"; | ||
|
|
||
| switch (step) { | ||
| case "welcome": | ||
| nextStep = "create-account"; | ||
| break; | ||
| case "create-account": | ||
| nextStep = "import-trades"; | ||
| setState(s => ({ ...s, hasAccount: true })); | ||
| break; | ||
| case "import-trades": | ||
| nextStep = "setup-preferences"; | ||
| setState(s => ({ ...s, hasTrades: true })); | ||
| break; | ||
| case "setup-preferences": | ||
| nextStep = "complete"; | ||
| setState(s => ({ ...s, hasPreferences: true })); | ||
| break; | ||
| case "complete": | ||
| return; | ||
| } | ||
|
|
||
| if (typeof window !== "undefined") { | ||
| localStorage.setItem(ONBOARDING_STEP_KEY, nextStep); | ||
| } | ||
| setState(s => ({ ...s, currentStep: nextStep })); | ||
| }, []); | ||
|
|
||
| const skipOnboarding = useCallback(() => { | ||
| if (typeof window !== "undefined") { | ||
| localStorage.setItem(ONBOARDING_KEY, "true"); | ||
| localStorage.removeItem(ONBOARDING_STEP_KEY); | ||
| } | ||
| setState(s => ({ ...s, isComplete: true, currentStep: "complete" })); | ||
| }, []); | ||
|
|
||
| const completeOnboarding = useCallback(() => { | ||
| if (typeof window !== "undefined") { | ||
| localStorage.setItem(ONBOARDING_KEY, "true"); | ||
| localStorage.removeItem(ONBOARDING_STEP_KEY); | ||
| } | ||
| setState(s => ({ ...s, isComplete: true, currentStep: "complete" })); | ||
| }, []); | ||
|
|
||
| const resetOnboarding = useCallback(() => { | ||
| if (typeof window !== "undefined") { | ||
| localStorage.removeItem(ONBOARDING_KEY); | ||
| localStorage.removeItem(ONBOARDING_STEP_KEY); | ||
| } | ||
| setState({ | ||
| isComplete: false, | ||
| currentStep: "welcome", | ||
| hasAccount: false, | ||
| hasTrades: false, | ||
| hasPreferences: false, | ||
| }); | ||
| }, []); | ||
|
|
||
| return { | ||
| ...state, | ||
| isLoading, | ||
| completeStep, | ||
| skipOnboarding, | ||
| completeOnboarding, | ||
| resetOnboarding, | ||
| }; | ||
| } | ||
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.
Because these localStorage keys are global to the browser, completing or skipping onboarding as one signed-in user suppresses it for every later user on the same device/browser profile. I checked the dashboard uses NextAuth sessions, but this hook never includes the session/user id in the key or stores state server-side, so a fresh account can land on
/dashboardand have onboarding hidden solely because a previous account settradia_onboarding_complete=true.Useful? React with 👍 / 👎.