2020-12-05 08:47:02 +01:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2020-12-06 23:54:37 +01:00
|
|
|
import { Service, RestService } from './services/Service';
|
2020-12-05 08:47:02 +01:00
|
|
|
import { IntlProvider } from 'react-intl'
|
|
|
|
|
2020-12-12 05:06:42 +01:00
|
|
|
import { GlobalStyle } from './theme/global-style';
|
|
|
|
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-08 08:14:08 +01:00
|
|
|
|
2020-12-05 08:47:02 +01:00
|
|
|
import {
|
|
|
|
Route,
|
|
|
|
Switch,
|
2020-12-06 07:35:21 +01:00
|
|
|
Redirect,
|
2020-12-06 17:24:53 +01:00
|
|
|
BrowserRouter as Router,
|
2020-12-05 08:47:02 +01:00
|
|
|
} from 'react-router-dom';
|
2020-12-10 07:29:28 +01:00
|
|
|
|
2020-12-08 08:34:01 +01:00
|
|
|
import { ForgotPasswordPage } from './components/forgot-password-page';
|
2020-12-05 08:47:02 +01:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const App = () => {
|
|
|
|
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();
|
|
|
|
}, []);
|
|
|
|
|
2020-12-06 23:54:37 +01:00
|
|
|
// Create Service object...
|
2020-12-08 08:14:08 +01:00
|
|
|
const service: Service = new RestService('http://localhost:8080', () => { console.log("401 error") });
|
2020-12-06 23:54:37 +01:00
|
|
|
|
2020-12-05 08:47:02 +01:00
|
|
|
return messages ? (
|
|
|
|
<IntlProvider locale={locale} defaultLocale='en' messages={messages}>
|
2020-12-12 05:06:42 +01:00
|
|
|
<GlobalStyle />
|
|
|
|
<Router>
|
|
|
|
<Switch>
|
|
|
|
<Route exact path="/">
|
2020-12-12 05:37:48 +01:00
|
|
|
<Redirect to="/c/login" />
|
2020-12-12 05:06:42 +01:00
|
|
|
</Route>
|
2020-12-12 05:37:48 +01:00
|
|
|
<Route path="/c/login" component={LoginPage} />
|
|
|
|
<Route path="/c/registration">
|
2020-12-12 05:06:42 +01:00
|
|
|
<RegistationPage service={service} />
|
|
|
|
</Route>
|
2020-12-12 05:37:48 +01:00
|
|
|
<Route path="/c/registration-success" component={RegistrationSuccessPage} />
|
|
|
|
<Route path="/c/forgot-password">
|
2020-12-12 05:06:42 +01:00
|
|
|
<ForgotPasswordPage service={service} />
|
|
|
|
</Route>
|
2020-12-12 05:37:48 +01:00
|
|
|
<Route path="/c/forgot-password-success" component={ForgotPasswordSuccessPage} />
|
2020-12-12 05:06:42 +01:00
|
|
|
</Switch>
|
|
|
|
</Router>
|
2020-12-05 08:47:02 +01:00
|
|
|
</IntlProvider>
|
2020-12-10 04:33:30 +01:00
|
|
|
) : <div>Loading ... </div>
|
2020-12-05 08:47:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|