Skip to content
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

Fix onboarding redirects #20695

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ class RegistrationsController < Devise::RegistrationsController
def new
return redirect_to root_path(signin: "true") if user_signed_in?

if URI(request.referer || "").host == URI(request.base_url).host
if URI(request.referer || "").host == URI(request.base_url).host &&
URI(request.referer).path.exclude?("/enter") &&
URI(request.referer).path.exclude?("/users/sign_up")
store_location_for(:user, request.referer)
end

Expand Down Expand Up @@ -32,13 +34,22 @@ def create
redirect_to confirm_email_path(email: resource.email)
else
sign_in(resource)
redirect_to root_path
respond_with resource, location: after_sign_up_path_for(resource)
end
else
render action: "by_email"
end
end

def after_sign_up_path_for(resource)
referrer = stored_location_for(resource) || root_path
if referrer
onboarding_path(referrer: referrer)
else
onboarding_path
end
end

private

def prepare_new_forem_instance
Expand Down
8 changes: 5 additions & 3 deletions app/javascript/onboarding/Onboarding.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
this.nextSlide = this.nextSlide.bind(this);
this.prevSlide = this.prevSlide.bind(this);
this.slidesCount = slides.length;
const url = new URL(window.location);
this.previousLocation = url.searchParams.get('referrer');

this.state = {
currentSlide: 0,
Expand Down Expand Up @@ -49,7 +51,7 @@
window.location.href = '/';
}
} else {
window.location.href = '/';
window.location.href = this.previousLocation || '/';
Dismissed Show dismissed Hide dismissed
}
}

Expand All @@ -68,7 +70,7 @@
return;
}
const dataBody = JSON.parse(localStorage.getItem('last_interacted_billboard'));

if (dataBody && dataBody['billboard_event']) {
dataBody['billboard_event']['category'] = 'signup';

Expand Down Expand Up @@ -96,7 +98,7 @@
communityConfig.communityBackgroundColor &&
communityConfig.communityBackgroundColor2
? {
background: `linear-gradient(${communityConfig.communityBackgroundColor},
background: `linear-gradient(${communityConfig.communityBackgroundColor},
${communityConfig.communityBackgroundColor2})`,
}
: { top: 777 }
Expand Down