1- import { useMemo } from 'react' ;
1+ import { Classes , NonIdealState } from '@blueprintjs/core' ;
2+ import { IconNames } from '@blueprintjs/icons' ;
3+ import classNames from 'classnames' ;
4+ import { useEffect , useMemo , useState } from 'react' ;
25import { useDispatch } from 'react-redux' ;
36import { RouterProvider } from 'react-router' ;
47import { createBrowserRouter } from 'react-router-dom' ;
58
69import { getFullAcademyRouterConfig , playgroundOnlyRouterConfig } from '../../routes/routerConfig' ;
10+ import { getHealth } from '../sagas/RequestsSaga' ;
711import Constants from '../utils/Constants' ;
812import { useSession } from '../utils/Hooks' ;
913import { updateReactRouter } from './actions/CommonsActions' ;
@@ -19,6 +23,11 @@ import { updateReactRouter } from './actions/CommonsActions';
1923const ApplicationWrapper : React . FC = ( ) => {
2024 const dispatch = useDispatch ( ) ;
2125 const { isLoggedIn, role, name, courseId } = useSession ( ) ;
26+ const [ isApiHealthy , setIsApiHealthy ] = useState ( true ) ;
27+
28+ useEffect ( ( ) => {
29+ getHealth ( ) . then ( res => setIsApiHealthy ( ! ! res ) ) ;
30+ } , [ ] ) ;
2231
2332 const router = useMemo ( ( ) => {
2433 const routerConfig = Constants . playgroundOnly
@@ -36,6 +45,18 @@ const ApplicationWrapper: React.FC = () => {
3645 return r ;
3746 } , [ isLoggedIn , role , name , courseId , dispatch ] ) ;
3847
48+ if ( ! isApiHealthy ) {
49+ return (
50+ < div className = { classNames ( 'NoPage' , Classes . DARK ) } >
51+ < NonIdealState
52+ icon = { IconNames . WRENCH }
53+ title = "Under maintenance"
54+ description = "The Source Academy is currently undergoing maintenance. Please try again later."
55+ />
56+ </ div >
57+ ) ;
58+ }
59+
3960 return < RouterProvider router = { router } /> ;
4061} ;
4162
0 commit comments