Skip to content

feat: redirect to retUrl for regSources that require going to retUrl … #181

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 1 commit into from
Feb 17, 2022
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
8 changes: 7 additions & 1 deletion src/hoc/withAuthentication/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ export default function withAuthentication(Component) {
status: "seen",
},
});

updateOnboardingWizardTraits(handle, traits, shouldCreate);
} else if (
traits[onboardingWizardChecklistIndex].onboarding_wizard?.status ===
"pending_at_user"
) {
traits[onboardingWizardChecklistIndex].onboarding_wizard.status =
"seen";
updateOnboardingWizardTraits(handle, traits, shouldCreate);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/root.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (HEAP_ANALYTICS_KEY) {
export default function Root() {
useEffect(() => {
disableNavigationForRoute("/onboard/*");

disableSidebarForRoute("/onboard");
disableSidebarForRoute("/onboard/contact-details");
disableSidebarForRoute("/onboard/payment-setup");
Expand Down
35 changes: 29 additions & 6 deletions src/routes/BuildMyProfile/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import moment from "moment";
import _ from "lodash";
import { createTraits, updateTraits } from "services/traits";
import { updateMemberData } from "services/memberData";
import { getCookie } from "utils/";
import { updateOnboardingWizardTraits } from "services/onboardingChecklist";

const formatDate = (date) => {
let ret = new Date(
Expand All @@ -61,6 +63,9 @@ const BuildMyProfile = () => {
const [isLoading, setIsLoading] = useState(false);
const [myProfileData, setMyProfileData] = useState({});
const [bio, setBio] = useState("");
const [redirectUrl, setRedirectUrl] = useState(
config.TOPCODER_COMMUNITY_WEBSITE_URL + "/home"
);

// form states
const [formData, setFormData] = useState({
Expand Down Expand Up @@ -189,6 +194,7 @@ const BuildMyProfile = () => {
// Get Member data from redux (firstName, lastName, handle, photoURL) and store it on myProfileData
useEffect(() => {
if (!authUser || !authUser.handle) return;

getAuthUserProfile()
.then((result) => {
setMyProfileData(result);
Expand All @@ -209,6 +215,9 @@ const BuildMyProfile = () => {
// find datas we need
// get traits values
let traits = result?.data;
const onboardingChecklist = traits.find(
(t) => t.traitId === "onboarding_checklist"
);
let basicInfo = traits.find((t) => t.traitId === "basic_info");
let workExp = traits.find((t) => t.traitId === "work");
let educationExp = traits.find((t) => t.traitId === "education");
Expand All @@ -218,6 +227,24 @@ const BuildMyProfile = () => {
let educationExpValue = educationExp?.traits?.data;
let languagesExpValue = languagesExp?.traits?.data;

if (
onboardingChecklist.traits.data.length > 0 &&
onboardingChecklist.traits.data[0].onboarding_wizard?.status !==
"completed"
) {
onboardingChecklist.traits.data[0].onboarding_wizard.status =
"completed";
const url = getCookie("returnAfterOnboard");
if (url != null) {
setRedirectUrl(url);
}
updateOnboardingWizardTraits(
authUser.handle,
onboardingChecklist.traits.data,
false
);
}

// fill title and bio to state
if (basicInfoValue) {
// Using shortBio as title has to do with v3 using this mapping
Expand Down Expand Up @@ -535,7 +562,7 @@ const BuildMyProfile = () => {
}

setIsLoading(false);
window.location.href = config.TOPCODER_COMMUNITY_WEBSITE_URL + "/home";
window.location.href = redirectUrl;
};

return (
Expand Down Expand Up @@ -1018,11 +1045,7 @@ const BuildMyProfile = () => {
</Button>
</Link>
<a
href={
errors && canSubmit()
? config.TOPCODER_COMMUNITY_WEBSITE_URL + "/home"
: "#"
}
href={errors && canSubmit() ? redirectUrl : "#"}
onClick={(e) => handleSubmit(e)}
>
<Button
Expand Down
7 changes: 7 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,10 @@ export function wrapV3(payload) {
param: payload,
};
}

export function clearCookie(name) {}

export function getCookie(name) {
const v = document.cookie.match("(^|;) ?" + name + "=([^;]*)(;|$)");
return v ? v[2] : undefined;
}