Skip to content

Remove param based onboarding navigation #2233

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

Merged
merged 2 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.contrib.auth import logout
from django.shortcuts import redirect
from django.utils.http import url_has_allowed_host_and_scheme, urlencode
from django.utils.http import url_has_allowed_host_and_scheme
from django.views import View

from main import settings
Expand Down Expand Up @@ -80,8 +80,7 @@ def get(
not profile.completed_onboarding
and request.GET.get("skip_onboarding", "0") == "0"
):
params = urlencode({"next": redirect_url})
redirect_url = f"{settings.MITOL_NEW_USER_LOGIN_URL}?{params}"
redirect_url = settings.MITOL_NEW_USER_LOGIN_URL
profile.completed_onboarding = True
profile.save()
return redirect(redirect_url)
3 changes: 1 addition & 2 deletions authentication/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,14 @@ def test_custom_login_view_authenticated_user_with_onboarding(mocker):
request.user = MagicMock(is_anonymous=False)
request.user.profile = MagicMock(completed_onboarding=False)
mocker.patch("authentication.views.get_redirect_url", return_value="/dashboard")
mocker.patch("authentication.views.urlencode", return_value="next=/dashboard")
mocker.patch(
"authentication.views.settings.MITOL_NEW_USER_LOGIN_URL", "/onboarding"
)

response = CustomLoginView().get(request)

assert response.status_code == 302
assert response.url == "/onboarding?next=/dashboard"
assert response.url == "/onboarding"


def test_custom_login_view_authenticated_user_skip_onboarding(mocker):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { merge, times } from "lodash"
import {
renderWithProviders,
screen,
waitFor,
setMockResponse,
user,
} from "../../test-utils"
Expand All @@ -18,32 +19,8 @@ import {
type Profile,
} from "api/v0"

import { waitFor } from "@testing-library/react"

import OnboardingPage from "./OnboardingPage"

const oldWindowLocation = window.location

beforeAll(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (window as any).location

window.location = Object.defineProperties(
{} as unknown as string & Location,
{
...Object.getOwnPropertyDescriptors(oldWindowLocation),
assign: {
configurable: true,
value: jest.fn(),
},
},
)
})

afterAll(() => {
window.location = oldWindowLocation as unknown as string & Location
})

const STEPS_DATA: Partial<Profile>[] = [
{
topic_interests: [factories.learningResources.topic()],
Expand Down Expand Up @@ -91,9 +68,7 @@ const setup = async (profile: Profile) => {
...req,
}))

renderWithProviders(<OnboardingPage />, {
url: "/onboarding?next=http%3A%2F%2Flearn.mit.edu",
})
renderWithProviders(<OnboardingPage />)
}

// this function sets up the test and progresses the UI to the designated step
Expand Down Expand Up @@ -132,15 +107,8 @@ describe("OnboardingPage", () => {
const nextStep = step + 1
await setupAndProgressToStep(step)
if (step === STEP_TITLES.length - 1) {
const finishButton = await findFinishButton()

await findFinishButton()
expect(queryBackButton()).not.toBeNil()

await user.click(finishButton)
await waitFor(() => {
expect(window.location).toBe("http://learn.mit.edu")
})

return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import { DASHBOARD_HOME } from "@/common/urls"
import { useFormik } from "formik"
import { useLearningResourceTopics } from "api/hooks/learningResources"
import { useUserMe } from "api/hooks/user"

import { useSearchParams } from "next/navigation"
import {
CERTIFICATE_CHOICES,
EDUCATION_LEVEL_OPTIONS,
Expand Down Expand Up @@ -158,8 +156,6 @@ const OnboardingPage: React.FC = () => {
const { isLoading: userLoading, data: user } = useUserMe()
const [activeStep, setActiveStep] = React.useState<number>(0)
const router = useRouter()
const searchParams = useSearchParams()
const nextUrl = searchParams.get("next")

const formik = useFormik({
enableReinitialize: true,
Expand All @@ -175,10 +171,6 @@ const OnboardingPage: React.FC = () => {
if (activeStep < NUM_STEPS - 1) {
setActiveStep((prevActiveStep) => prevActiveStep + 1)
} else {
if (nextUrl) {
;(window as Window).location = nextUrl
return null
}
router.push(DASHBOARD_HOME)
}
},
Expand Down
Loading