accounts-frontend/src/index.js

97 lines
4.1 KiB
JavaScript
Raw Normal View History

import 'polyfills';
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider as ReduxProvider } from 'react-redux';
import { Router, Route, Switch } from 'react-router-dom';
import { factory as userFactory } from 'components/user/factory';
2016-05-20 01:11:43 +05:30
import { IntlProvider } from 'components/i18n';
import authFlow from 'services/authFlow';
2016-06-18 20:30:45 +05:30
import storeFactory from 'storeFactory';
2016-07-30 00:59:27 +05:30
import bsodFactory from 'components/ui/bsod/factory';
import loader from 'services/loader';
import logger from 'services/logger';
2017-01-25 11:22:19 +05:30
import font from 'services/font';
import history, { browserHistory } from 'services/history';
import AuthFlowRoute from 'containers/AuthFlowRoute';
import RootPage from 'pages/root/RootPage';
import SuccessOauthPage from 'pages/auth/SuccessOauthPage';
history.init();
logger.init({
sentryCdn: window.SENTRY_CDN
});
2016-06-18 20:30:45 +05:30
const store = storeFactory();
bsodFactory(store, () => loader.hide());
authFlow.setStore(store);
2016-07-30 00:59:27 +05:30
Promise.all([
userFactory(store),
2017-01-25 11:22:19 +05:30
font.load(['Roboto', 'Roboto Condensed'])
])
.then(() => {
ReactDOM.render(
<ReduxProvider store={store}>
<IntlProvider>
<Router history={browserHistory}>
<Switch>
<Route path="/oauth2/code/success" component={SuccessOauthPage} />
<AuthFlowRoute path="/oauth2/:version(v\d+)/:clientId?" component={() => null} />
<Route path="/" component={RootPage} />
</Switch>
</Router>
</IntlProvider>
</ReduxProvider>,
document.getElementById('app')
);
initAnalytics();
});
import { loadScript, debounce } from 'functions';
const trackPageView = debounce(_trackPageView);
function initAnalytics() {
if (!window.ga) {
const ga = window.ga = function() {
(ga.q = ga.q || []).push(arguments); // eslint-disable-line
};
ga.l = Date.now(); // eslint-disable-line
if (window.GA_ID) {
// when GA is not available, we will continue to push into array
// for debug purposes
// Catch to prevent "unhandled rejection" error
loadScript('https://www.google-analytics.com/analytics.js').catch(() => {});
}
2016-11-20 17:31:57 +05:30
ga('create', window.GA_ID, 'auto');
trackPageView(location);
2016-11-20 17:31:57 +05:30
browserHistory.listen(trackPageView);
2016-11-20 17:31:57 +05:30
}
}
function _trackPageView(location) {
const ga = window.ga;
2016-11-20 17:31:57 +05:30
ga('set', 'page', location.pathname + location.search);
ga('send', 'pageview');
}
/* global process: false */
if (process.env.NODE_ENV !== 'production') {
// some shortcuts for testing on localhost
window.testOAuth = (loginHint = '') => location.href = `/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&login_hint=${loginHint}`;
window.testOAuthPermissions = () => location.href = '/oauth2/v1/tlauncher?client_id=tlauncher&redirect_uri=http%3A%2F%2Flocalhost%3A8080&response_type=code&scope=account_info,account_email';
window.testOAuthPromptAccount = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&prompt=select_account';
window.testOAuthPromptPermissions = (loginHint = '') => location.href = `/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&prompt=consent&login_hint=${loginHint}`;
window.testOAuthPromptAll = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&prompt=select_account,consent';
window.testOAuthStatic = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=static_page_with_code&response_type=code&scope=account_info%2Caccount_email';
window.testOAuthStaticCode = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=static_page&response_type=code&scope=account_info%2Caccount_email';
}