Skip to content

Commit

Permalink
Merge pull request #181 from topcoder-platform/develop
Browse files Browse the repository at this point in the history
feat: redirect to retUrl for regSources that require going to retUrl
  • Loading branch information
rakibansary authored Feb 17, 2022
2 parents 16ec8d7 + 3be2d8b commit 50afe9e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
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;
}

0 comments on commit 50afe9e

Please sign in to comment.