Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 659e109

Browse files
Nursoltan SaipoldaNursoltan Saipolda
Nursoltan Saipolda
authored and
Nursoltan Saipolda
committed
fix issue 178
1 parent 6eecd23 commit 659e109

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

src/App.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { navigate, Router, useLocation } from "@reach/router";
99
import { useSelector } from "react-redux";
1010
import useMatchSomeRoute from "./hooks/useMatchSomeRoute";
1111
import NotificationsModal from "./components/NotificationsModal";
12+
import { checkOnboarding, checkProfileCreationDate } from "./utils";
13+
import { getOnboardingChecklist } from "./services/auth";
1214
import "./styles/main.module.scss";
1315

1416
const App = () => {
@@ -53,6 +55,26 @@ const App = () => {
5355
}
5456
}, [isSideBarDisabled, location.pathname]);
5557

58+
useEffect(() => {
59+
(async () => {
60+
console.log('qq', auth?.profile);
61+
62+
if (auth?.profile && checkProfileCreationDate(auth?.profile)) {
63+
const { profile, tokenV3 } = auth;
64+
65+
const response = await getOnboardingChecklist(profile?.handle, tokenV3);
66+
const onboardingPath = checkOnboarding(response);
67+
console.log('qq', onboardingPath);
68+
if (onboardingPath) {
69+
setHideSwitchTools(true);
70+
navigate(onboardingPath);
71+
} else {
72+
setHideSwitchTools(false);
73+
}
74+
}
75+
})();
76+
}, [auth]);
77+
5678
return (
5779
<>
5880
<NavBar hideSwitchTools={hideSwitchTools} />

src/components/NavBar/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Shows global top navigation bar with all apps menu, logo and user menu.
55
*/
6-
import React, {
6+
import React, {
77
useState,
88
useCallback,
99
Fragment,

src/services/auth.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,14 @@ export function authenticate(store) {
126126
});
127127
}
128128

129+
/**
130+
* Get the onboarding checklist data to know completed steps
131+
*/
132+
export function getOnboardingChecklist(username, userTokenV3) {
133+
const fetcher = getFetcher(userTokenV3);
134+
return fetcher(
135+
`${config.API.V5}/members/${username}/traits?traitIds=onboarding_checklist`
136+
)
137+
.then((res) => res.json())
138+
.then((res) => ({ data: res || [] }));
139+
}

src/utils/index.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,69 @@ export const checkProfileCreationDate = (profile) => {
6767

6868
return false;
6969
};
70+
71+
/**
72+
* Check Onboarding API
73+
*
74+
* @param resp {Object} User trait object
75+
*
76+
* @returns {boolean | string}
77+
*/
78+
export function checkOnboarding(resp) {
79+
if (resp?.data.length === 0) {
80+
return "/onboard/";
81+
}
82+
83+
const onboardingChecklistTrait = resp?.data.filter(
84+
(item) => item.traitId === "onboarding_checklist"
85+
)[0].traits;
86+
87+
// Check if onboarding flow needs to be skipped
88+
// 1. if the trait onboarding_wizard has a valid value for status.
89+
// possible values of status are [seeen, completed]. Since we only want to show
90+
// the onboarding wizard to users who haven't at least once seen the wizard
91+
// it is sufficient to check for a non null value.
92+
// 2. if the trait onboarding_wizard has a truthy value for skip.
93+
94+
for (let checklistTrait of onboardingChecklistTrait.data) {
95+
if (
96+
checklistTrait.onboarding_wizard != null &&
97+
(checklistTrait.onboarding_wizard.status != null ||
98+
checklistTrait.onboarding_wizard.skip)
99+
) {
100+
return false;
101+
}
102+
}
103+
104+
const profileCompletedData =
105+
onboardingChecklistTrait.data[0].profile_completed;
106+
107+
if (profileCompletedData.status === "completed") {
108+
return false;
109+
}
110+
111+
for (const item in profileCompletedData.metadata) {
112+
if (profileCompletedData.metadata[item]) {
113+
return false;
114+
}
115+
}
116+
117+
const steps = {
118+
"/onboard/": ["profile_picture", "skills"],
119+
"/onboard/contact-details": ["country"],
120+
"/onboard/payments-setup": [],
121+
"/onboard/build-my-profile": ["bio", "work", "education", "language"],
122+
};
123+
124+
if (profileCompletedData.status === "pending_at_user") {
125+
const flags = Object.keys(profileCompletedData.metadata);
126+
for (const step of Object.keys(steps)) {
127+
for (const flag of steps[step]) {
128+
if (flags.indexOf(flag) >= 0 && !profileCompletedData.metadata[flag]) {
129+
return step;
130+
}
131+
}
132+
}
133+
}
134+
return false;
135+
}

0 commit comments

Comments
 (0)