Skip to content

Redirect new users to onboarding flow #2186

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
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

shanbady
Copy link
Contributor

@shanbady shanbady commented Apr 7, 2025

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/6857

Description (What does it do?)

This PR adds a "completed_onboarding" flag to the user profile that gets set to True once the user has interacted with the onboarding page after they first login.

How can this be tested?

  1. Checkout this branch
  2. run migrations
  3. Assuming you have an existing user locally, manually set user.profile.completed_onboarding to False (migrations automatically set to True for all existing users)
  4. visit any page on the app after logging in - it should redirect you to the onboarding flow
  5. leaving the onboarding page at any point should land you wherever you intended to go (no redirect back to onboarding after first seeing it)

test the "skip_onboarding" get parameter which skips the onboarding.

  1. perform step 3 from above
  2. visit the homepage with ?skip_onboarding=1. You should not be forwarded to the onboarding page.

Copy link

github-actions bot commented Apr 7, 2025

OpenAPI Changes

Show/hide 24 changes: 0 error, 0 warning, 24 info
24 changes: 0 error, 0 warning, 24 info
info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/profiles/{user__username}/
		added the optional property 'completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the optional property 'completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the optional property 'completed_onboarding' to the response with the '200' status

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/users/
		added the optional property '/items/profile/completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the new optional request property 'profile/completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the optional property 'profile/completed_onboarding' to the response with the '201' status

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/users/me/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/users/{username}/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status


@shanbady shanbady changed the title Redirect new users to login page Redirect new users to onboarding flow Apr 8, 2025
@shanbady shanbady added Needs Review An open Pull Request that is ready for review and removed Work in Progress labels Apr 8, 2025
@shanbady shanbady marked this pull request as ready for review April 8, 2025 15:37
Copy link

github-actions bot commented Apr 8, 2025

OpenAPI Changes

Show/hide 24 changes: 0 error, 0 warning, 24 info
24 changes: 0 error, 0 warning, 24 info
info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/profiles/{user__username}/
		added the optional property 'completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the optional property 'completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the optional property 'completed_onboarding' to the response with the '200' status

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/users/
		added the optional property '/items/profile/completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the new optional request property 'profile/completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the optional property 'profile/completed_onboarding' to the response with the '201' status

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/users/me/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/users/{username}/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status


Copy link

github-actions bot commented Apr 8, 2025

OpenAPI Changes

Show/hide 24 changes: 0 error, 0 warning, 24 info
24 changes: 0 error, 0 warning, 24 info
info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/profiles/{user__username}/
		added the optional property 'completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the optional property 'completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the optional property 'completed_onboarding' to the response with the '200' status

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/users/
		added the optional property '/items/profile/completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the new optional request property 'profile/completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the optional property 'profile/completed_onboarding' to the response with the '201' status

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/users/me/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/users/{username}/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status


@rhysyngsun rhysyngsun self-assigned this Apr 8, 2025
Copy link
Contributor

@rhysyngsun rhysyngsun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small things, but you might not need to do them if we do the following suggestion:

I noticed that when the site loads you see a flash of the content followed by the redirect over to /onboarding. I hadn't thought of this when I wrote out the issue but I'm thinking that maybe we instead want to take care of this on the login view in the backend instead. Something along the lines of this:

class CustomLoginView(View):
    """
    Redirect the user to the appropriate url after login
    """

    def get(
        self,
        request,
        *args,  # noqa: ARG002
        **kwargs,  # noqa: ARG002
    ):
        """
        GET endpoint for logging a user in.
        """
        redirect_url = get_redirect_url(request)

        if (
            not request.user.profile.completed_onboarding
            and not request.GET.get("skip_onboarding", "0") == "1"
        ):
            # redirect the user to onboarding and later to the next url
            params = urlencode({"next": redirect_url})
            redirect_url = f"{settings.NEW_USER_REDIRECT_URL}?{params}"

        return redirect(redirect_url)

This also passes along the next parameter to the onboarding flow, I can't recall if we handle that, but we should if we don't so the user ends up where they left off.

@@ -171,7 +169,7 @@ const OnboardingPage: React.FC = () => {
if (activeStep < NUM_STEPS - 1) {
setActiveStep((prevActiveStep) => prevActiveStep + 1)
} else {
router.push(DASHBOARD_HOME)
;(window as Window).location = DASHBOARD_HOME
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why this change was needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea - basically there was some caching of data that happens with the profile query such that when we update the completed_onboarding it reads the cached value on the subsequent page unless we do a full reload. I spoke with @ChristopherChudzicki and it seemed like the full reload was the easiest way since we only should ever do this once per user

!user?.profile?.completed_onboarding &&
pathname !== urls.ONBOARDING
) {
if (typeof profileMutate === "function") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused why this would ever not be a function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was running into some error previously but I think its removable since I moved this into useEffect. removed

Copy link

OpenAPI Changes

Show/hide 24 changes: 0 error, 0 warning, 24 info
24 changes: 0 error, 0 warning, 24 info
info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/profiles/{user__username}/
		added the optional property 'completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/profiles/{user__username}/
		added the optional property 'completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the new optional request property 'completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/profiles/{user__username}/
		added the optional property 'completed_onboarding' to the response with the '200' status

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/users/
		added the optional property '/items/profile/completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the new optional request property 'profile/completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API POST /api/v0/users/
		added the optional property 'profile/completed_onboarding' to the response with the '201' status

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/users/me/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API GET /api/v0/users/{username}/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PATCH /api/v0/users/{username}/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[new-optional-request-property] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the new optional request property 'profile/completed_onboarding'

info	[response-optional-property-added] at head/openapi/specs/v0.yaml	
	in API PUT /api/v0/users/{username}/
		added the optional property 'profile/completed_onboarding' to the response with the '200' status


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review An open Pull Request that is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants