1- import React from 'react' ;
1+ import React , { useMemo } from 'react' ;
22
3- import PropTypes from 'prop-types' ;
43import queryString from 'query-string' ;
54import Loadable from 'react-loadable' ;
6- import { connect } from 'react-redux' ;
5+ import { useSelector } from 'react-redux' ;
76import {
87 BrowserRouter , Redirect , Route , Switch ,
98} from 'react-router-dom' ;
109import Alert from 'react-s-alert' ;
1110import { ClimbingBoxLoader } from 'react-spinners' ;
11+ import {
12+ getCurrentLocationSupportedActivities ,
13+ getNotificationAutohideDelay ,
14+ getSpinner ,
15+ } from 'selectors' ;
1216
1317import CustomAlert from 'components/dashboard/CustomAlert' ;
1418import MainLayoutRoute from 'components/Layout/MainLayoutRoute' ;
1519import Loading from 'components/Loading' ;
20+ import ActivityCode from 'consts/activityCode' ;
1621import { DASHBOARD_URL } from 'consts/applicationUrls' ;
1722import useConnectionListener from 'hooks/useConnectionListener' ;
1823import FlashScopeListenerWrapper from 'wrappers/FlashScopeListenerWrapper' ;
@@ -227,12 +232,19 @@ const AsyncStockTransferList = Loadable({
227232 loading : Loading ,
228233} ) ;
229234
230- const Router = ( props ) => {
235+ const Router = ( ) => {
231236 useConnectionListener ( ) ;
232237
233- const Dashboard = ! props . supportedActivities . includes ( 'MANAGE_INVENTORY' ) && props . supportedActivities . includes ( 'SUBMIT_REQUEST' )
234- ? AsyncStockRequestDashboard
235- : AsyncDashboard ;
238+ const spinner = useSelector ( getSpinner ) ;
239+ const supportedActivities = useSelector ( getCurrentLocationSupportedActivities ) ;
240+ const notificationAutohideDelay = useSelector ( getNotificationAutohideDelay ) ;
241+
242+ const Dashboard = useMemo (
243+ ( ) => ( ! supportedActivities ?. includes ( ActivityCode . MANAGE_INVENTORY )
244+ && supportedActivities ?. includes ( ActivityCode . SUBMIT_REQUEST )
245+ ? AsyncStockRequestDashboard
246+ : AsyncDashboard ) , [ supportedActivities ] ,
247+ ) ;
236248
237249 return (
238250 < div >
@@ -286,12 +298,12 @@ const Router = (props) => {
286298 < div className = "spinner-container" >
287299 < ClimbingBoxLoader
288300 color = "#0c769e"
289- loading = { props . spinner }
290- style = { { top : '40%' , lefft : '50%' } }
301+ loading = { spinner }
302+ style = { { top : '40%' , left : '50%' } }
291303 />
292304 </ div >
293305 < Alert
294- timeout = { props . notificationAutohideDelay }
306+ timeout = { notificationAutohideDelay }
295307 stack = { { limit : 3 } }
296308 contentTemplate = { CustomAlert }
297309 position = "top-right"
@@ -302,16 +314,4 @@ const Router = (props) => {
302314 ) ;
303315} ;
304316
305- const mapStateToProps = ( state ) => ( {
306- spinner : state . spinner . show ,
307- supportedActivities : state . session . supportedActivities ,
308- notificationAutohideDelay : state . session . notificationAutohideDelay ,
309- } ) ;
310-
311- export default connect ( mapStateToProps , { } ) ( Router ) ;
312-
313- Router . propTypes = {
314- spinner : PropTypes . bool . isRequired ,
315- supportedActivities : PropTypes . arrayOf ( PropTypes . string ) . isRequired ,
316- notificationAutohideDelay : PropTypes . number . isRequired ,
317- } ;
317+ export default Router ;
0 commit comments