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

Commit ea67727

Browse files
committed
revert onboarding checklist
1 parent 5c759ce commit ea67727

File tree

3 files changed

+93
-8
lines changed

3 files changed

+93
-8
lines changed

src/App.jsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import React, { useState, useCallback, useMemo, useEffect } from "react";
55
import _ from "lodash";
66
import MainMenu from "./components/MainMenu";
77
import NavBar from "./components/NavBar";
8-
import { matchPath, Router, useLocation } from "@reach/router";
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";
1212
import "./styles/main.module.scss";
13-
import { checkOnboardingPath } from "./utils";
13+
import { checkOnboarding, checkProfileCreationDate } from "./utils";
14+
import { getOnboardingChecklist } from "./services/auth";
1415

1516
const App = () => {
1617
// all menu options
@@ -50,12 +51,21 @@ const App = () => {
5051
}, [isSideBarDisabled]);
5152

5253
useEffect(() => {
53-
if (matchPath("onboard/*", location.pathname)) {
54-
setHideSwitchTools(true);
55-
} else {
56-
setHideSwitchTools(false);
57-
}
58-
}, [location]);
54+
(async () => {
55+
if (auth?.profile && checkProfileCreationDate(auth?.profile)) {
56+
const { profile, tokenV3 } = auth;
57+
58+
const response = await getOnboardingChecklist(profile?.handle, tokenV3);
59+
const onboardingPath = checkOnboarding(response);
60+
if (onboardingPath) {
61+
setHideSwitchTools(true);
62+
navigate(onboardingPath);
63+
} else {
64+
setHideSwitchTools(false);
65+
}
66+
}
67+
})();
68+
}, [auth]);
5969

6070
return (
6171
<>

src/services/auth.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,15 @@ export function authenticate(store) {
125125
}
126126
});
127127
}
128+
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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,66 @@ export const login = () => {
4747
export const businessLogin = () => {
4848
window.location = getBusinessLoginUrl();
4949
};
50+
51+
/**
52+
* Check Onboarding API
53+
*
54+
* @param resp {Object} User trait object
55+
*
56+
* @returns {boolean | string}
57+
*/
58+
export function checkOnboarding(resp) {
59+
if (resp?.data.length === 0) {
60+
return false;
61+
}
62+
const data = resp?.data.filter(
63+
(item) => item.traitId === "onboarding_checklist"
64+
)[0].traits.data[0].profile_completed;
65+
if (data.status === "completed") {
66+
return false;
67+
}
68+
69+
for (const item in data.metadata) {
70+
if (data.metadata[item]) {
71+
return false;
72+
}
73+
}
74+
75+
const steps = {
76+
"/onboard/": ["profile_picture", "skills"],
77+
"/onboard/contact-details": ["country"],
78+
"/onboard/payments-setup": [],
79+
"/onboard/build-my-profile": ["bio", "work", "education", "language"],
80+
};
81+
if (data.status === "pending_at_user") {
82+
const flags = Object.keys(data.metadata);
83+
for (const step of Object.keys(steps)) {
84+
for (const flag of steps[step]) {
85+
if (flags.indexOf(flag) >= 0 && !data.metadata[flag]) {
86+
return step;
87+
}
88+
}
89+
}
90+
}
91+
return false;
92+
}
93+
94+
/**
95+
* Checks If current user's profile creation time
96+
*
97+
* @param profile {Object} user profile
98+
*
99+
* @returns {boolean}
100+
*/
101+
export const checkProfileCreationDate = (profile) => {
102+
const thresholdDate = moment(
103+
config.PROFILE_CREATION_DATE_THRESHOLD,
104+
"YYYY-MM-DD"
105+
);
106+
107+
if (profile?.createdAt) {
108+
return thresholdDate.isBefore(moment(profile?.createdAt));
109+
}
110+
111+
return false;
112+
};

0 commit comments

Comments
 (0)