Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3ca002a

Browse files
Nursoltan SaipoldaNursoltan Saipolda
Nursoltan Saipolda
authored and
Nursoltan Saipolda
committedJan 8, 2022
add disableNavigation for route
1 parent 659e109 commit 3ca002a

File tree

9 files changed

+74
-109
lines changed

9 files changed

+74
-109
lines changed
 

‎README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ This app exports functions to be imported by other microapps.
6868
- `getAuthUserProfile` - returns a promise which resolves to the user profile object
6969
- `disableSidebarForRoute` - disable (remove) sidebar for some route
7070
- `enableSidebarForRoute` - enable sidebar for the route, which was previously disabled
71+
- `disableNavigationForRoute` - disable (remove) navigation for some route
72+
- `enableNavigationForRoute` - enable (remove) navigation for some route
7173

7274
#### How to export
7375

‎src/App.jsx

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ 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";
1412
import "./styles/main.module.scss";
1513

1614
const App = () => {
@@ -20,14 +18,18 @@ const App = () => {
2018
const apps = useMemo(() => _.flatMap(menu, "apps"), [menu]);
2119
// list of routes where we have to disabled sidebar
2220
const disabledRoutes = useSelector((state) => state.menu.disabledRoutes);
21+
// list of routes where we have to disabled navigations
22+
const disabledNavigations = useSelector(
23+
(state) => state.menu.disabledNavigations
24+
);
2325
// user profile information
2426
const auth = useSelector((state) => state.auth);
2527
// `true` is sidebar has to be disabled for the current route
2628
const isSideBarDisabled = useMatchSomeRoute(disabledRoutes);
29+
// `true` is navigation has to be disabled for the current route
30+
const isNavigationDisabled = useMatchSomeRoute(disabledNavigations);
2731
// Left sidebar collapse state
2832
const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
29-
// hide switch tools and notification when user is onboarding
30-
const [hideSwitchTools, setHideSwitchTools] = useState(false);
3133
// Toggle left sidebar callback
3234
const toggleSidebar = useCallback(() => {
3335
setSidebarCollapsed(!sidebarCollapsed);
@@ -43,41 +45,16 @@ const App = () => {
4345

4446
// set/remove class for the whole page, to know if sidebar is present or no
4547
useEffect(() => {
46-
if (location.pathname.includes("/self-service")) {
47-
setHideSwitchTools(true);
48-
} else {
49-
setHideSwitchTools(false);
50-
}
5148
if (isSideBarDisabled) {
5249
document.body.classList.add("no-sidebar");
5350
} else {
5451
document.body.classList.remove("no-sidebar");
5552
}
5653
}, [isSideBarDisabled, location.pathname]);
5754

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-
7855
return (
7956
<>
80-
<NavBar hideSwitchTools={hideSwitchTools} />
57+
<NavBar hideSwitchTools={isNavigationDisabled} />
8158
{!isSideBarDisabled && (
8259
<div className="main-menu-wrapper">
8360
<Router>

‎src/actions/menu.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,28 @@ export default {
3939
type: ACTIONS.MENU.ENABLE_SIDEBAR_FOR_ROUTE,
4040
payload: route,
4141
}),
42+
43+
/**
44+
* Disable navigation for route.
45+
*
46+
* @param {String} route route path
47+
*
48+
* @returns {{ type: String, payload: any }} action object
49+
*/
50+
disableNavigationForRoute: (route) => ({
51+
type: ACTIONS.MENU.DISABLE_NAVIGATION_FOR_ROUTE,
52+
payload: route,
53+
}),
54+
55+
/**
56+
* Enable navigation for route.
57+
*
58+
* @param {String} route route path
59+
*
60+
* @returns {{ type: String, payload: any }} action object
61+
*/
62+
enableNavigationForRoute: (route) => ({
63+
type: ACTIONS.MENU.ENABLE_NAVIGATION_FOR_ROUTE,
64+
payload: route,
65+
}),
4266
};

‎src/constants/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ export const ACTIONS = {
1616
SET_APP_MENU: "SET_APP_MENU",
1717
DISABLE_SIDEBAR_FOR_ROUTE: "DISABLE_SIDEBAR_FOR_ROUTE",
1818
ENABLE_SIDEBAR_FOR_ROUTE: "ENABLE_SIDEBAR_FOR_ROUTE",
19+
DISABLE_NAVIGATION_FOR_ROUTE: "DISABLE_NAVIGATION_FOR_ROUTE",
20+
ENABLE_NAVIGATION_FOR_ROUTE: "ENABLE_NAVIGATION_FOR_ROUTE",
1921
},
2022
};

‎src/reducers/menu.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ACTIONS, APP_CATEGORIES } from "../constants";
1010
const initialState = {
1111
categories: APP_CATEGORIES, // Default Apps Menu structure.
1212
disabledRoutes: [],
13+
disabledNavigations: [],
1314
};
1415

1516
/**
@@ -132,6 +133,35 @@ const menuReducer = (state = initialState, action) => {
132133
};
133134
}
134135

136+
case ACTIONS.MENU.DISABLE_NAVIGATION_FOR_ROUTE: {
137+
// if route is already disabled, don't do anything
138+
if (state.disabledNavigations.indexOf(action.payload) > -1) {
139+
return state;
140+
}
141+
142+
return {
143+
...state,
144+
// add route to the disabled list
145+
disabledNavigations: [...state.disabledNavigations, action.payload],
146+
};
147+
}
148+
149+
case ACTIONS.MENU.ENABLE_NAVIGATION_FOR_ROUTE: {
150+
// if route is not disabled, don't do anything
151+
if (state.disabledNavigations.indexOf(action.payload) === -1) {
152+
return state;
153+
}
154+
155+
return {
156+
...state,
157+
// remove the route from the disabled list
158+
disabledNavigations: _.without(
159+
state.disabledNavigations,
160+
action.payload
161+
),
162+
};
163+
}
164+
135165
default:
136166
return state;
137167
}

‎src/services/auth.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,3 @@ 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/topcoder-micro-frontends-navbar-app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
getAuthUserProfile,
1919
setUserProfilePhoto,
2020
setNotificationPlatform,
21+
disableNavigationForRoute,
22+
enableNavigationForRoute,
2123
} from "./utils/exports";
2224

2325
import { login, businessLogin, logout } from "./utils";
@@ -47,5 +49,7 @@ export {
4749
disableSidebarForRoute,
4850
enableSidebarForRoute,
4951
setNotificationPlatform,
52+
disableNavigationForRoute,
53+
enableNavigationForRoute,
5054
PLATFORM,
5155
};

‎src/utils/exports.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ export const {
1616
disableSidebarForRoute,
1717
enableSidebarForRoute,
1818
setNotificationPlatform,
19-
setUserProfilePhoto
19+
setUserProfilePhoto,
20+
disableNavigationForRoute,
21+
enableNavigationForRoute,
2022
} = bindActionCreators(
2123
{
2224
setAppMenu: menuActions.setAppMenu,
2325
disableSidebarForRoute: menuActions.disableSidebarForRoute,
2426
enableSidebarForRoute: menuActions.enableSidebarForRoute,
2527
setNotificationPlatform: notificationActions.setNotificationPlatform,
2628
setUserProfilePhoto: authActions.setProfilePhoto,
29+
disableNavigationForRoute: menuActions.disableNavigationForRoute,
30+
enableNavigationForRoute: menuActions.enableNavigationForRoute,
2731
},
2832
store.dispatch
2933
);

‎src/utils/index.js

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -67,69 +67,3 @@ 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)
This repository has been archived.