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

disable redirection #44

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
27 changes: 9 additions & 18 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import React, { useState, useCallback, useMemo, useEffect } from "react";
import _ from "lodash";
import MainMenu from "./components/MainMenu";
import NavBar from "./components/NavBar";
import { navigate, Router } from "@reach/router";
import { matchPath, Router, useLocation } from "@reach/router";
import { useSelector } from "react-redux";
import useMatchSomeRoute from "./hooks/useMatchSomeRoute";
import NotificationsModal from "./components/NotificationsModal";
import "./styles/main.module.scss";
import { checkOnboarding, checkProfileCreationDate } from "./utils";
import { getOnboardingChecklist } from "./services/auth";
import { checkOnboardingPath } from "./utils";

const App = () => {
// all menu options
Expand Down Expand Up @@ -39,6 +38,7 @@ const App = () => {
(!state.notifications.initialized &&
!state.notifications.communityInitialized)
);
const location = useLocation();

// set/remove class for the whole page, to know if sidebar is present or no
useEffect(() => {
Expand All @@ -50,21 +50,12 @@ const App = () => {
}, [isSideBarDisabled]);

useEffect(() => {
(async () => {
if (auth?.profile && checkProfileCreationDate(auth?.profile)) {
const { profile, tokenV3 } = auth;

const response = await getOnboardingChecklist(profile?.handle, tokenV3);
const onboardingPath = checkOnboarding(response);
if (onboardingPath) {
setHideSwitchTools(true);
navigate(onboardingPath);
} else {
setHideSwitchTools(false);
}
}
})();
}, [auth]);
if (matchPath("onboard/*", location.pathname)) {
setHideSwitchTools(true);
} else {
setHideSwitchTools(false);
}
}, [location]);

return (
<>
Expand Down
12 changes: 0 additions & 12 deletions src/services/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,3 @@ export function authenticate(store) {
}
});
}

/**
* Get the onboarding checklist data to know completed steps
*/
export function getOnboardingChecklist(username, userTokenV3) {
const fetcher = getFetcher(userTokenV3);
return fetcher(
`${config.API.V5}/members/${username}/traits?traitIds=onboarding_checklist`
)
.then((res) => res.json())
.then((res) => ({ data: res || [] }));
}
67 changes: 0 additions & 67 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,70 +47,3 @@ export const login = () => {
export const businessLogin = () => {
window.location = getBusinessLoginUrl();
};

/**
* TODO: Re-check when onboarding processor is ready
* Check Onboarding API
*
* @param resp {Object} User trait object
*
* @returns {boolean | string}
*/
export function checkOnboarding(resp) {
if (resp?.data.length === 0) {
return "/onboard/";
}
const data = resp?.data.filter(
(item) => item.traitId === "onboarding_checklist"
)[0].traits.data[0].profile_completed;
if (data.status === "completed") {
return false;
}

// TODO: Re-check when onboarding processor is ready.
// It checks for at least one onboarding checklist was completed, then we don't enter onboarding flow
// This logic will be changed.
for (const item in data.metadata) {
if (data.metadata[item]) {
return false;
}
}

const steps = {
"/onboard/": ["profile_picture", "skills"],
"/onboard/contact-details": ["country"],
"/onboard/payments-setup": [],
"/onboard/build-my-profile": ["bio", "work", "education", "language"],
};
if (data.status === "pending_at_user") {
const flags = Object.keys(data.metadata);
for (const step of Object.keys(steps)) {
for (const flag of steps[step]) {
if (flags.indexOf(flag) >= 0 && !data.metadata[flag]) {
return step;
}
}
}
}
return false;
}

/**
* Checks If current user's profile creation time
*
* @param profile {Object} user profile
*
* @returns {boolean}
*/
export const checkProfileCreationDate = (profile) => {
const thresholdDate = moment(
config.PROFILE_CREATION_DATE_THRESHOLD,
"YYYY-MM-DD"
);

if (profile?.createdAt) {
return thresholdDate.isBefore(moment(profile?.createdAt));
}

return false;
};