2020-12-05 08:47:02 +01:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2020-12-26 06:39:54 +01:00
|
|
|
import { IntlProvider } from 'react-intl';
|
|
|
|
import { Route, Switch, Redirect, BrowserRouter as Router } from 'react-router-dom';
|
2020-12-05 08:47:02 +01:00
|
|
|
|
2021-01-25 19:39:53 +01:00
|
|
|
import { GlobalStyle } from './theme';
|
2020-12-12 05:06:42 +01:00
|
|
|
import RegistrationSuccessPage from './components/registration-success-page';
|
|
|
|
import ForgotPasswordSuccessPage from './components/forgot-password-success-page';
|
|
|
|
import RegistationPage from './components/registration-page';
|
2020-12-08 08:34:01 +01:00
|
|
|
import LoginPage from './components/login-page';
|
2020-12-25 02:39:06 +01:00
|
|
|
import MapsPage from './components/maps-page';
|
2020-12-26 06:39:54 +01:00
|
|
|
import store from "./store";
|
2020-12-08 08:34:01 +01:00
|
|
|
import { ForgotPasswordPage } from './components/forgot-password-page';
|
2020-12-25 02:39:06 +01:00
|
|
|
import { Provider } from 'react-redux';
|
2020-12-27 18:58:21 +01:00
|
|
|
import { QueryClient, QueryClientProvider } from 'react-query';
|
2021-01-25 19:39:53 +01:00
|
|
|
import { CssBaseline, ThemeProvider } from '@material-ui/core';
|
|
|
|
import { theme } from './theme'
|
|
|
|
|
2020-12-06 06:28:00 +01:00
|
|
|
function loadLocaleData(language: string) {
|
2020-12-05 08:47:02 +01:00
|
|
|
switch (language) {
|
|
|
|
case 'es':
|
2020-12-06 06:28:00 +01:00
|
|
|
return require('./compiled-lang/es.json')
|
2020-12-05 08:47:02 +01:00
|
|
|
default:
|
2020-12-06 06:28:00 +01:00
|
|
|
return require('./compiled-lang/en.json')
|
2020-12-05 08:47:02 +01:00
|
|
|
}
|
2020-12-25 02:39:06 +01:00
|
|
|
}
|
2020-12-05 08:47:02 +01:00
|
|
|
|
2021-02-02 09:20:35 +01:00
|
|
|
const queryClient = new QueryClient({
|
|
|
|
defaultOptions: {
|
|
|
|
queries: {
|
|
|
|
refetchIntervalInBackground: false,
|
|
|
|
staleTime: 5*1000*60 // 10 minutes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-12-25 02:39:06 +01:00
|
|
|
const App = () => {
|
2020-12-05 08:47:02 +01:00
|
|
|
const [messages, setMessages] = useState(undefined);
|
|
|
|
// Boostrap i18n ...
|
|
|
|
const locale = (navigator.languages && navigator.languages[0])
|
|
|
|
|| navigator.language
|
|
|
|
|| 'en-US';
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const language = locale.split('-')[0];
|
|
|
|
const fetchData = async () => {
|
|
|
|
const messages = await loadLocaleData(language);
|
|
|
|
setMessages(messages);
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchData();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return messages ? (
|
2020-12-25 02:39:06 +01:00
|
|
|
<Provider store={store}>
|
2021-02-02 09:20:35 +01:00
|
|
|
<GlobalStyle />
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
<IntlProvider locale={locale} defaultLocale='en' messages={messages}>
|
|
|
|
<ThemeProvider theme={theme}>
|
|
|
|
<CssBaseline />
|
|
|
|
<Router>
|
|
|
|
<Switch>
|
|
|
|
<Route exact path="/">
|
|
|
|
<Redirect to="/c/login" />
|
|
|
|
</Route>
|
|
|
|
<Route path="/c/login" component={LoginPage} />
|
|
|
|
<Route path="/c/registration">
|
|
|
|
<RegistationPage />
|
|
|
|
</Route>
|
|
|
|
<Route path="/c/registration-success" component={RegistrationSuccessPage} />
|
|
|
|
<Route path="/c/forgot-password">
|
|
|
|
<ForgotPasswordPage />
|
|
|
|
</Route>
|
|
|
|
<Route path="/c/forgot-password-success" component={ForgotPasswordSuccessPage} />
|
|
|
|
<Route path="/c/maps/">
|
|
|
|
<MapsPage />
|
|
|
|
</Route>
|
|
|
|
</Switch>
|
|
|
|
</Router>
|
|
|
|
</ThemeProvider>
|
|
|
|
</IntlProvider>
|
|
|
|
</QueryClientProvider>
|
2020-12-25 02:39:06 +01:00
|
|
|
</Provider>
|
|
|
|
|
2020-12-10 04:33:30 +01:00
|
|
|
) : <div>Loading ... </div>
|
2020-12-05 08:47:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|