wisemapping-frontend/packages/login/src/app.tsx

58 lines
1.5 KiB
TypeScript
Raw Normal View History

import React, { useEffect, useState } from 'react';
2020-12-06 06:28:00 +01:00
import LoginPage from './LoginPage';
import { RegistrationSuccessPage, RegistationFormPage } from './RegistrationPage';
import { IntlProvider } from 'react-intl'
import {
Route,
Switch,
2020-12-06 06:28:00 +01:00
Redirect
} from 'react-router-dom';
2020-12-06 06:28:00 +01:00
function loadLocaleData(language: string) {
switch (language) {
case 'es':
2020-12-06 06:28:00 +01:00
return require('./compiled-lang/es.json')
default:
2020-12-06 06:28:00 +01:00
return require('./compiled-lang/en.json')
}
}
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}>
<Switch>
2020-12-05 22:18:44 +01:00
<Route exact path="/">
<Redirect to="/c/login" />
</Route>
2020-12-05 22:18:44 +01:00
<Route exact path="/">
<Redirect to="/react" />
</Route>
<Route path="/c/login" component={LoginPage} />
2020-12-05 22:57:39 +01:00
<Route path="/c/user/registration" component={RegistationFormPage} />
2020-12-05 22:18:44 +01:00
<Route path="/c/user/registrationSuccess" component={RegistrationSuccessPage} />
</Switch>
</IntlProvider>
) : <div>loading</div>
}
export default App;