-
Notifications
You must be signed in to change notification settings - Fork 258
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
feat: Force user to go through onboarding steps for every registration #4014
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5985be6
feat: Force user to go through onboarding steps for every registration
AmarTrebinjac e3a1f82
Merge branch 'main' into MI-700
AmarTrebinjac a412c78
extend check beyond onboarding
AmarTrebinjac c9ed1b1
Merge branch 'main' into MI-700
AmarTrebinjac 0252913
Merge branch 'main' into MI-700
AmarTrebinjac 36eae31
Merge branch 'main' into MI-700
AmarTrebinjac 0676072
lint
AmarTrebinjac fb7c833
update logic to use date and let old users skip
AmarTrebinjac ddbe413
updated extension App.tsx
AmarTrebinjac 010f935
remove unused import
AmarTrebinjac 44ac9bf
remove unused function
AmarTrebinjac 715a708
remove router as dependency
AmarTrebinjac a64ba27
Merge branch 'main' into MI-700
AmarTrebinjac 90723e5
undo automatic redirect for extension
AmarTrebinjac fcc3311
Merge branch 'main' into MI-700
AmarTrebinjac 6dde472
lint
AmarTrebinjac 37637ee
update date
AmarTrebinjac 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 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 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 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 |
---|---|---|
@@ -1,12 +1,41 @@ | ||
import { useMemo } from 'react'; | ||
import { useAuthContext } from '../../contexts/AuthContext'; | ||
import { useActions } from '../useActions'; | ||
import { ActionType } from '../../graphql/actions'; | ||
|
||
interface UseOnboarding { | ||
shouldShowAuthBanner: boolean; | ||
isOnboardingReady: boolean; | ||
hasCompletedEditTags: boolean; | ||
hasCompletedContentTypes: boolean; | ||
completeStep: (action: ActionType) => void; | ||
} | ||
|
||
export const useOnboarding = (): UseOnboarding => { | ||
const { checkHasCompleted, isActionsFetched, completeAction } = useActions(); | ||
const { isAuthReady, user } = useAuthContext(); | ||
const shouldShowAuthBanner = isAuthReady && !user; | ||
|
||
return { shouldShowAuthBanner }; | ||
const { hasCompletedEditTags, hasCompletedContentTypes } = useMemo(() => { | ||
/* | ||
This is the date that completing the onboarding became required. | ||
Anyone who created an account before this date is exempt from the requirement. | ||
*/ | ||
const registeredBeforeRequired = | ||
user?.createdAt && new Date(user.createdAt) < new Date('2025-01-20'); | ||
return { | ||
hasCompletedEditTags: | ||
registeredBeforeRequired || checkHasCompleted(ActionType.EditTag), | ||
hasCompletedContentTypes: | ||
registeredBeforeRequired || checkHasCompleted(ActionType.ContentTypes), | ||
}; | ||
}, [checkHasCompleted, user]); | ||
|
||
return { | ||
shouldShowAuthBanner, | ||
isOnboardingReady: isActionsFetched && isAuthReady, | ||
hasCompletedEditTags, | ||
hasCompletedContentTypes, | ||
completeStep: (action: ActionType) => completeAction(action), | ||
}; | ||
}; |
This file contains 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 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 |
---|---|---|
@@ -1,11 +1,5 @@ | ||
import type { ReactElement } from 'react'; | ||
import React, { | ||
useCallback, | ||
useEffect, | ||
useMemo, | ||
useRef, | ||
useState, | ||
} from 'react'; | ||
import React, { useEffect, useMemo, useRef, useState } from 'react'; | ||
import classNames from 'classnames'; | ||
import type { | ||
AuthOptionsProps, | ||
|
@@ -78,6 +72,8 @@ import { | |
UserAgent, | ||
} from '@dailydotdev/shared/src/lib/func'; | ||
import { useOnboardingExtension } from '@dailydotdev/shared/src/components/onboarding/Extension/useOnboardingExtension'; | ||
import { useOnboarding } from '@dailydotdev/shared/src/hooks/auth'; | ||
import { ActionType } from '@dailydotdev/shared/src/graphql/actions'; | ||
import { useInstallPWA } from '@dailydotdev/shared/src/components/onboarding/PWA/useInstallPWA'; | ||
import { defaultOpenGraph, defaultSeo } from '../next-seo'; | ||
import { getTemplatedTitle } from '../components/layouts/utils'; | ||
|
@@ -146,6 +142,12 @@ const seo: NextSeoProps = { | |
}; | ||
|
||
export function OnboardPage(): ReactElement { | ||
const { | ||
isOnboardingReady, | ||
hasCompletedEditTags, | ||
hasCompletedContentTypes, | ||
completeStep, | ||
} = useOnboarding(); | ||
const router = useRouter(); | ||
const { setSettings } = useSettingsContext(); | ||
const isLogged = useRef(false); | ||
|
@@ -212,19 +214,29 @@ export function OnboardPage(): ReactElement { | |
].includes(activeScreen); | ||
|
||
useEffect(() => { | ||
if (!isPageReady || isLogged.current) { | ||
if (!isPageReady || isLogged.current || !isOnboardingReady) { | ||
return; | ||
} | ||
|
||
if (user?.infoConfirmed && !hasCompletedEditTags) { | ||
setActiveScreen(OnboardingStep.EditTag); | ||
return; | ||
} | ||
|
||
if (user) { | ||
if (user?.infoConfirmed && !hasCompletedContentTypes) { | ||
setActiveScreen(OnboardingStep.ContentTypes); | ||
return; | ||
} | ||
|
||
if (user?.infoConfirmed && activeScreen === OnboardingStep.Intro) { | ||
router.replace(getPathnameWithQuery(webappUrl, window.location.search)); | ||
return; | ||
} | ||
|
||
isLogged.current = true; | ||
// @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [isPageReady, user]); | ||
}, [isPageReady, user, isOnboardingReady]); | ||
|
||
const onClickNext: OnboardingOnClickNext = (options) => { | ||
logEvent({ | ||
|
@@ -237,10 +249,15 @@ export function OnboardPage(): ReactElement { | |
} | ||
|
||
if (activeScreen === OnboardingStep.EditTag) { | ||
completeStep(ActionType.EditTag); | ||
setShouldEnrollOnboardingStep(true); | ||
return setActiveScreen(OnboardingStep.ContentTypes); | ||
} | ||
|
||
if (activeScreen === OnboardingStep.ContentTypes) { | ||
completeStep(ActionType.ContentTypes); | ||
} | ||
|
||
if ( | ||
activeScreen === OnboardingStep.ContentTypes && | ||
isMobile && | ||
|
@@ -332,10 +349,6 @@ export function OnboardPage(): ReactElement { | |
return onClickNext(); | ||
}; | ||
|
||
const onSuccessfulLogin = useCallback(() => { | ||
router.replace(getPathnameWithQuery(webappUrl, window.location.search)); | ||
}, [router]); | ||
|
||
const onSuccessfulRegistration = (userRefetched: LoggedUser) => { | ||
logPixelSignUp({ | ||
experienceLevel: userRefetched?.experienceLevel, | ||
|
@@ -361,7 +374,6 @@ export function OnboardPage(): ReactElement { | |
initialEmail: email, | ||
isLoginFlow, | ||
targetId, | ||
onSuccessfulLogin, | ||
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. Is this used anywhere else that existing flows might get affected? |
||
onSuccessfulRegistration, | ||
onAuthStateUpdate: (props: AuthProps) => | ||
setAuth({ isAuthenticating: true, ...props }), | ||
|
@@ -376,7 +388,6 @@ export function OnboardPage(): ReactElement { | |
isAuthenticating, | ||
isLoginFlow, | ||
isMobile, | ||
onSuccessfulLogin, | ||
targetId, | ||
]); | ||
|
||
|
@@ -399,8 +410,10 @@ export function OnboardPage(): ReactElement { | |
!isAuthenticating && activeScreen === OnboardingStep.Intro && !shouldVerify; | ||
|
||
const showGenerigLoader = | ||
isAuthenticating && isAuthLoading && activeScreen === OnboardingStep.Intro; | ||
|
||
isAuthenticating && | ||
isAuthLoading && | ||
activeScreen === OnboardingStep.Intro && | ||
!isOnboardingReady; | ||
if (!isPageReady) { | ||
return null; | ||
} | ||
|
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.
Doesn't this affect current users now? (I didn't test it)