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

Commit cd1bbc3

Browse files
authored
Merge pull request #63 from topcoder-platform/dev
feat: ability to hide switch tools
2 parents cbfa3b6 + 154db9c commit cd1bbc3

File tree

9 files changed

+98
-17
lines changed

9 files changed

+98
-17
lines changed

README.md

+2
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

+9-14
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ 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";
1413

1514
const App = () => {
1615
// all menu options
@@ -19,14 +18,18 @@ const App = () => {
1918
const apps = useMemo(() => _.flatMap(menu, "apps"), [menu]);
2019
// list of routes where we have to disabled sidebar
2120
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+
);
2225
// user profile information
2326
const auth = useSelector((state) => state.auth);
2427
// `true` is sidebar has to be disabled for the current route
2528
const isSideBarDisabled = useMatchSomeRoute(disabledRoutes);
29+
// `true` is navigation has to be disabled for the current route
30+
const isNavigationDisabled = useMatchSomeRoute(disabledNavigations);
2631
// Left sidebar collapse state
2732
const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
28-
// hide switch tools and notification when user is onboarding
29-
const [hideSwitchTools, setHideSwitchTools] = useState(false);
3033
// Toggle left sidebar callback
3134
const toggleSidebar = useCallback(() => {
3235
setSidebarCollapsed(!sidebarCollapsed);
@@ -47,19 +50,11 @@ const App = () => {
4750
} else {
4851
document.body.classList.remove("no-sidebar");
4952
}
50-
}, [isSideBarDisabled]);
51-
52-
useEffect(() => {
53-
if (matchPath("onboard/*", location.pathname)) {
54-
setHideSwitchTools(true);
55-
} else {
56-
setHideSwitchTools(false);
57-
}
58-
}, [location]);
53+
}, [isSideBarDisabled, location.pathname]);
5954

6055
return (
6156
<>
62-
<NavBar hideSwitchTools={hideSwitchTools} />
57+
<NavBar hideSwitchTools={isNavigationDisabled} />
6358
{!isSideBarDisabled && (
6459
<div className="main-menu-wrapper">
6560
<Router>

src/actions/menu.js

+24
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/components/NavBar/index.jsx

+1-1
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/constants/index.js

+2
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

+30
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/topcoder-micro-frontends-navbar-app.js

+4
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

+5-1
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

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _ from 'lodash';
1+
import _ from "lodash";
22
import moment from "moment";
33
import config from "../../config";
44

@@ -47,3 +47,23 @@ export const login = () => {
4747
export const businessLogin = () => {
4848
window.location = getBusinessLoginUrl();
4949
};
50+
51+
/**
52+
* Checks If current user's profile creation time
53+
*
54+
* @param profile {Object} user profile
55+
*
56+
* @returns {boolean}
57+
*/
58+
export const checkProfileCreationDate = (profile) => {
59+
const thresholdDate = moment(
60+
config.PROFILE_CREATION_DATE_THRESHOLD,
61+
"YYYY-MM-DD"
62+
);
63+
64+
if (profile?.createdAt) {
65+
return thresholdDate.isBefore(moment(profile?.createdAt));
66+
}
67+
68+
return false;
69+
};

0 commit comments

Comments
 (0)