2020-12-05 08:47:02 +01:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2020-12-06 07:35:21 +01:00
|
|
|
import LoginPage from './components/LoginPage';
|
|
|
|
import { RegistrationSuccessPage, RegistationFormPage } from './components/RegistrationPage';
|
2020-12-05 08:47:02 +01:00
|
|
|
import { IntlProvider } from 'react-intl'
|
|
|
|
|
|
|
|
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-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();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return messages ? (
|
|
|
|
<IntlProvider locale={locale} defaultLocale='en' messages={messages}>
|
2020-12-06 17:24:53 +01:00
|
|
|
<Router>
|
|
|
|
<Switch>
|
|
|
|
<Route exact path="/">
|
|
|
|
<Redirect to="/c/login" />
|
|
|
|
</Route>
|
|
|
|
<Route path="/c/login" component={LoginPage} />
|
|
|
|
<Route path="/c/user/registration" component={RegistationFormPage} />
|
|
|
|
<Route path="/c/user/registrationSuccess" component={RegistrationSuccessPage} />
|
|
|
|
</Switch>
|
|
|
|
</Router>
|
2020-12-05 08:47:02 +01:00
|
|
|
</IntlProvider>
|
|
|
|
) : <div>loading</div>
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|