2016-08-18 11:41:13 +02:00
|
|
|
/**
|
|
|
|
*
|
2017-08-21 15:12:53 +02:00
|
|
|
* App.js
|
2016-08-18 11:41:13 +02:00
|
|
|
*
|
|
|
|
* This component is the skeleton around the actual pages, and should only
|
|
|
|
* contain code that should be seen on all pages. (e.g. navigation bar)
|
2016-08-18 11:47:26 +02:00
|
|
|
*
|
|
|
|
* NOTE: while this component should technically be a stateless functional
|
|
|
|
* component (SFC), hot reloading does not currently support SFCs. If hot
|
|
|
|
* reloading is not a neccessity for you then you can refactor it and remove
|
|
|
|
* the linting exception.
|
2016-08-18 11:41:13 +02:00
|
|
|
*/
|
|
|
|
|
2019-09-10 12:14:07 +02:00
|
|
|
import React, { useEffect, useRef, useState } from 'react';
|
2019-09-09 13:58:07 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2017-08-21 15:12:53 +02:00
|
|
|
import { Switch, Route } from 'react-router-dom';
|
2019-11-07 10:48:02 +01:00
|
|
|
|
2019-09-09 13:58:07 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { bindActionCreators, compose } from 'redux';
|
|
|
|
import { LoadingIndicatorPage, request } from 'strapi-helper-plugin';
|
2019-02-22 10:05:07 +01:00
|
|
|
|
2019-04-03 13:05:18 +02:00
|
|
|
import Admin from '../Admin';
|
2019-09-05 16:27:30 +02:00
|
|
|
import AuthPage from '../AuthPage';
|
2019-09-09 18:44:41 +02:00
|
|
|
import NotFoundPage from '../NotFoundPage';
|
|
|
|
import NotificationProvider from '../NotificationProvider';
|
|
|
|
import PrivateRoute from '../PrivateRoute';
|
2019-09-17 15:23:29 +02:00
|
|
|
import Theme from '../Theme';
|
2016-08-18 11:41:13 +02:00
|
|
|
|
2019-09-24 18:42:08 +02:00
|
|
|
import { Content, Wrapper } from './components';
|
|
|
|
|
|
|
|
import GlobalStyle from '../../components/GlobalStyle';
|
|
|
|
|
2019-09-09 13:58:07 +02:00
|
|
|
import { getDataSucceeded } from './actions';
|
|
|
|
|
2019-04-03 13:05:18 +02:00
|
|
|
function App(props) {
|
2019-09-09 13:58:07 +02:00
|
|
|
const getDataRef = useRef();
|
2019-09-10 12:14:07 +02:00
|
|
|
const [state, setState] = useState({ hasAdmin: false, isLoading: true });
|
2019-09-09 13:58:07 +02:00
|
|
|
getDataRef.current = props.getDataSucceeded;
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const getData = async () => {
|
|
|
|
try {
|
|
|
|
const requestURL = '/users-permissions/init';
|
|
|
|
|
|
|
|
const { hasAdmin } = await request(requestURL, { method: 'GET' });
|
2019-09-09 16:06:54 +02:00
|
|
|
const { data } = await request('/admin/init', { method: 'GET' });
|
2019-11-22 18:37:54 +01:00
|
|
|
const { uuid } = data;
|
|
|
|
|
|
|
|
if (uuid) {
|
2019-11-29 16:02:17 +01:00
|
|
|
try {
|
|
|
|
await fetch('https://analytics.strapi.io/track', {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({
|
|
|
|
event: 'didInitializeAdministration',
|
|
|
|
uuid,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
// Silent.
|
|
|
|
}
|
2019-11-22 18:37:54 +01:00
|
|
|
}
|
2019-09-09 16:06:54 +02:00
|
|
|
|
|
|
|
getDataRef.current(hasAdmin, data);
|
2019-09-10 12:14:07 +02:00
|
|
|
setState({ hasAdmin, isLoading: false });
|
2019-09-09 13:58:07 +02:00
|
|
|
} catch (err) {
|
|
|
|
strapi.notification.error('app.containers.App.notification.error.init');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
getData();
|
|
|
|
}, [getDataRef]);
|
|
|
|
|
2019-09-10 12:14:07 +02:00
|
|
|
if (state.isLoading) {
|
|
|
|
return <LoadingIndicatorPage />;
|
|
|
|
}
|
|
|
|
|
2019-04-02 21:23:42 +02:00
|
|
|
return (
|
2019-09-17 15:23:29 +02:00
|
|
|
<Theme>
|
2019-09-24 18:42:08 +02:00
|
|
|
<Wrapper>
|
|
|
|
<GlobalStyle />
|
2019-09-17 15:23:29 +02:00
|
|
|
<NotificationProvider />
|
2019-09-24 18:42:08 +02:00
|
|
|
<Content>
|
2019-09-17 15:23:29 +02:00
|
|
|
<Switch>
|
|
|
|
<Route
|
|
|
|
path="/auth/:authType"
|
|
|
|
render={routerProps => (
|
|
|
|
<AuthPage {...routerProps} hasAdminUser={state.hasAdmin} />
|
|
|
|
)}
|
|
|
|
exact
|
|
|
|
/>
|
|
|
|
<PrivateRoute path="/" component={Admin} />
|
|
|
|
<Route path="" component={NotFoundPage} />
|
|
|
|
</Switch>
|
2019-09-24 18:42:08 +02:00
|
|
|
</Content>
|
|
|
|
</Wrapper>
|
2019-09-17 15:23:29 +02:00
|
|
|
</Theme>
|
2019-04-02 21:23:42 +02:00
|
|
|
);
|
2016-08-18 11:47:26 +02:00
|
|
|
}
|
2016-08-18 14:22:12 +02:00
|
|
|
|
2019-09-09 13:58:07 +02:00
|
|
|
App.propTypes = {
|
|
|
|
getDataSucceeded: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators({ getDataSucceeded }, dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
const withConnect = connect(
|
|
|
|
null,
|
|
|
|
mapDispatchToProps
|
|
|
|
);
|
2016-08-18 14:22:12 +02:00
|
|
|
|
2019-09-09 13:58:07 +02:00
|
|
|
export default compose(withConnect)(App);
|
2019-09-09 15:27:54 +02:00
|
|
|
export { App };
|