|
1 | 1 | import React from 'react';
|
2 | 2 |
|
3 |
| -import {connect, shallowEqual} from 'react-redux'; |
| 3 | +import {connect} from 'react-redux'; |
4 | 4 | import type {RedirectProps} from 'react-router-dom';
|
5 | 5 | import {Redirect, Route, Switch} from 'react-router-dom';
|
6 | 6 |
|
| 7 | +import {PageError} from '../../components/Errors/PageError/PageError'; |
| 8 | +import {LoaderWrapper} from '../../components/LoaderWrapper/LoaderWrapper'; |
7 | 9 | import {useSlots} from '../../components/slots';
|
8 | 10 | import type {SlotMap} from '../../components/slots/SlotMap';
|
9 | 11 | import type {SlotComponent} from '../../components/slots/types';
|
10 | 12 | import routes from '../../routes';
|
11 | 13 | import type {RootState} from '../../store';
|
12 |
| -import {getUser} from '../../store/reducers/authentication/authentication'; |
| 14 | +import {authenticationApi} from '../../store/reducers/authentication/authentication'; |
13 | 15 | import {capabilitiesApi} from '../../store/reducers/capabilities/capabilities';
|
14 | 16 | import {nodesListApi} from '../../store/reducers/nodesList';
|
15 | 17 | import {cn} from '../../utils/cn';
|
16 |
| -import {useTypedDispatch, useTypedSelector} from '../../utils/hooks'; |
17 | 18 | import {lazyComponent} from '../../utils/lazyComponent';
|
18 | 19 | import Authentication from '../Authentication/Authentication';
|
19 | 20 | import {getClusterPath} from '../Cluster/utils';
|
@@ -143,43 +144,37 @@ export function Content(props: ContentProps) {
|
143 | 144 | {additionalRoutes?.rendered}
|
144 | 145 | {/* Single cluster routes */}
|
145 | 146 | <Route key="single-cluster">
|
146 |
| - <GetUser /> |
147 |
| - <GetNodesList /> |
148 |
| - <GetCapabilities /> |
149 |
| - <Header mainPage={mainPage} /> |
150 |
| - <Switch> |
151 |
| - {routesSlots.map((route) => { |
152 |
| - return renderRouteSlot(slots, route); |
153 |
| - })} |
154 |
| - <Route |
155 |
| - path={redirectProps.from || redirectProps.path} |
156 |
| - exact={redirectProps.exact} |
157 |
| - strict={redirectProps.strict} |
158 |
| - render={() => <Redirect to={redirectProps.to} push={redirectProps.push} />} |
159 |
| - /> |
160 |
| - </Switch> |
| 147 | + <GetUser> |
| 148 | + <GetNodesList /> |
| 149 | + <GetCapabilities /> |
| 150 | + <Header mainPage={mainPage} /> |
| 151 | + <Switch> |
| 152 | + {routesSlots.map((route) => { |
| 153 | + return renderRouteSlot(slots, route); |
| 154 | + })} |
| 155 | + <Route |
| 156 | + path={redirectProps.from || redirectProps.path} |
| 157 | + exact={redirectProps.exact} |
| 158 | + strict={redirectProps.strict} |
| 159 | + render={() => ( |
| 160 | + <Redirect to={redirectProps.to} push={redirectProps.push} /> |
| 161 | + )} |
| 162 | + /> |
| 163 | + </Switch> |
| 164 | + </GetUser> |
161 | 165 | </Route>
|
162 | 166 | </Switch>
|
163 | 167 | );
|
164 | 168 | }
|
165 | 169 |
|
166 |
| -function GetUser() { |
167 |
| - const dispatch = useTypedDispatch(); |
168 |
| - const {isAuthenticated, isInternalUser} = useTypedSelector( |
169 |
| - (state) => ({ |
170 |
| - isAuthenticated: state.authentication.isAuthenticated, |
171 |
| - isInternalUser: Boolean(state.authentication.user), |
172 |
| - }), |
173 |
| - shallowEqual, |
174 |
| - ); |
175 |
| - |
176 |
| - React.useEffect(() => { |
177 |
| - if (isAuthenticated && !isInternalUser) { |
178 |
| - dispatch(getUser()); |
179 |
| - } |
180 |
| - }, [dispatch, isAuthenticated, isInternalUser]); |
| 170 | +function GetUser({children}: {children: React.ReactNode}) { |
| 171 | + const {isLoading, error} = authenticationApi.useWhoamiQuery(undefined); |
181 | 172 |
|
182 |
| - return null; |
| 173 | + return ( |
| 174 | + <LoaderWrapper loading={isLoading} size="l"> |
| 175 | + <PageError error={error}>{children}</PageError> |
| 176 | + </LoaderWrapper> |
| 177 | + ); |
183 | 178 | }
|
184 | 179 |
|
185 | 180 | function GetNodesList() {
|
|
0 commit comments