diff --git a/js/app.js b/js/app.js index ce7c90b6..5ae013e5 100644 --- a/js/app.js +++ b/js/app.js @@ -1,29 +1,22 @@ -'use strict'; - import 'core-js/es6'; import 'core-js/stage/4'; import 'classlist-polyfill'; import 'isomorphic-fetch'; import React from 'react'; -import { Router, Redirect } from 'react-router'; +import { Router } from 'react-router'; + +import AppResolver from './app_resolver'; import history from './history'; -import ApiUrls from './constants/api_urls'; - -import AppConstants from './constants/application_constants'; -import getRoutes from './routes'; -import requests from './utils/requests'; - -import { updateApiUrls } from './constants/api_urls'; import { getDefaultSubdomainSettings, getSubdomainSettings } from './utils/constants_utils'; import { initLogging } from './utils/error_utils'; import { getSubdomain } from './utils/general_utils'; +import requests from './utils/requests'; -// FIXME: redo these event actions +// FIXME: rename these event actions import EventActions from './actions/event_actions'; -// FIXME: use a ./third_party/index.js instead, remove DebugHandler // You can comment out the modules you don't need // import DebugHandler from './third_party/debug_handler'; import './third_party/facebook_handler'; @@ -38,68 +31,60 @@ import '../sass/main.scss'; const AppGateway = { start() { - try { - const subdomain = getSubdomain(); - const settings = getSubdomainSettings(subdomain); + let subdomainSettings; - AppConstants.whitelabel = settings; - updateApiUrls(settings.type, subdomain); - this.load(settings); - } catch(err) { - // if there are no matching subdomains, we're routing - // to the default frontend + try { + subdomainSettings = getSubdomainSettings(getSubdomain()); + } catch (err) { + // if there are no matching subdomains, we''ll route to the default frontend console.logGlobal(err); - this.load(getDefaultSubdomainSettings()); + subdomainSettings = getDefaultSubdomainSettings(); } + + this.load(subdomainSettings); }, load(settings) { - const { subdomain, type } = settings; - let redirectRoute = (); - - if (subdomain) { - // Some whitelabels have landing pages so we should not automatically redirect from / to /collection. - // Only www and cc do not have a landing page. - if (subdomain !== 'cc') { - redirectRoute = null; - } - - // Adds a client specific class to the body for whitelabel styling - window.document.body.classList.add('client--' + subdomain); - } - // Send the applicationWillBoot event to the third-party stores EventActions.applicationWillBoot(settings); - // `history.listen` is called on every route change, which is perfect for - // us in that case. + // `history.listen` is called on every route change, which is perfect for routeDidChange + // events. history.listen(EventActions.routeDidChange); - React.render(( - - {redirectRoute} - {getRoutes(type, subdomain)} - - ), document.getElementById('main')); + // Adds a client specific class to the body for whitelabel styling + window.document.body.classList.add(`client--${settings.subdomain}`); - // Send the applicationDidBoot event to the third-party stores - EventActions.applicationDidBoot(settings); + AppResolver + .resolve(settings) + .then(({ apiUrls, redirectRoute, routes }) => { + // Initialize api urls and defaults for outgoing requests + requests.defaults({ + urlMap: apiUrls, + http: { + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + credentials: 'include' + } + }); + + React.render(( + + {redirectRoute} + {routes} + + ), document.getElementById('main')); + + // Send the applicationDidBoot event to the third-party stores + EventActions.applicationDidBoot(settings); + }); } }; // Initialize pre-start components initLogging(); -requests.defaults({ - urlMap: ApiUrls, - http: { - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - credentials: 'include' - } -}); - // And bootstrap app AppGateway.start(); diff --git a/js/app_resolver.js b/js/app_resolver.js new file mode 100644 index 00000000..97a8fde5 --- /dev/null +++ b/js/app_resolver.js @@ -0,0 +1,22 @@ +import React from 'react'; +import { Redirect } from 'react-router'; + +import Routes from './routes'; + +import ApiUrls from './constants/api_urls'; + + +function resolve({ subdomain, type }) { + if (type === 'wallet') { + return System.import('./components/whitelabel/wallet/wallet_app_resolver') + .then(({ default: WalletAppResolver }) => WalletAppResolver.resolve(subdomain)); + } else { + return Promise.resolve({ + apiUrls: ApiUrls, + redirectRoute: (), + routes: Routes + }); + } +} + +export default { resolve }; diff --git a/js/components/whitelabel/wallet/wallet_app_resolver.js b/js/components/whitelabel/wallet/wallet_app_resolver.js new file mode 100644 index 00000000..bd0daacd --- /dev/null +++ b/js/components/whitelabel/wallet/wallet_app_resolver.js @@ -0,0 +1,22 @@ +import React from 'react'; +import { Redirect } from 'react-router'; + +import getWalletApiUrls from './constants/wallet_api_urls'; +import getWalletRoutes from './wallet_routes'; + +import { updateApiUrls } from '../../../constants/api_urls'; + + +function resolve(subdomain) { + // Most whitelabels have landing pages so we should not automatically redirect from / to /collection. + // Only cc does not have a landing page. + const redirectRoute = subdomain === 'cc' ? () : null; + + return { + redirectRoute, + apiUrls: updateApiUrls(getWalletApiUrls(subdomain)), + routes: getWalletRoutes(subdomain) + }; +} + +export default { resolve }; diff --git a/js/components/whitelabel/wallet/wallet_routes.js b/js/components/whitelabel/wallet/wallet_routes.js index 2e0e9a10..fe1d9161 100644 --- a/js/components/whitelabel/wallet/wallet_routes.js +++ b/js/components/whitelabel/wallet/wallet_routes.js @@ -1,5 +1,3 @@ -'use strict'; - import React from 'react'; import { Route, IndexRoute } from 'react-router'; @@ -17,7 +15,6 @@ import EditionContainer from '../../../components/ascribe_detail/edition_contain import SettingsContainer from '../../../components/ascribe_settings/settings_container'; import ContractSettings from '../../../components/ascribe_settings/contract_settings'; import ErrorNotFoundPage from '../../../components/error_not_found_page'; -import Footer from '../../../components/footer.js'; import CCRegisterPiece from './components/cc/cc_register_piece'; @@ -54,409 +51,407 @@ import WalletApp from './wallet_app'; import { getLangText } from '../../../utils/lang_utils'; -let ROUTES = { +const ROUTES = { 'cyland': ( - + + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(CylandLanding)} /> + path="login" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(LoginContainer)} /> + path="logout" + component={ProxyHandler(AuthRedirect({ to: '/', when: 'loggedOut' }))(LogoutContainer)} /> + path="signup" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(SignupContainer)} /> + path="password_reset" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(PasswordResetContainer)} /> + path="settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(SettingsContainer)} /> + path="contract_settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(ContractSettings)} /> + aclName="acl_wallet_submit" /> + disableOn="noPieces" /> ), 'cc': ( - + + path="login" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(LoginContainer)} /> + path="logout" + component={ProxyHandler(AuthRedirect({ to: '/', when: 'loggedOut' }))(LogoutContainer)} /> + path="signup" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(SignupContainer)} /> + path="password_reset" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(PasswordResetContainer)} /> + path="settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(SettingsContainer)} /> + path="contract_settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(ContractSettings)} /> + disableOn="noPieces" /> ), 'ikonotv': ( - + + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(IkonotvLanding)} /> + path="login" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(LoginContainer)} /> + path="logout" + component={ProxyHandler(AuthRedirect({ to: '/', when: 'loggedOut' }))(LogoutContainer)} /> + path="signup" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(SignupContainer)} /> + path="password_reset" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(PasswordResetContainer)} /> + path="settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(SettingsContainer)} /> + path="contract_settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(ContractSettings)} /> + aclName="acl_create_contractagreement" /> + aclName="acl_wallet_submit" /> + disableOn="noPieces" /> + path="contract_notifications" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(IkonotvContractNotifications)} /> ), 'lumenus': ( - + + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(LumenusLanding)} /> + path="login" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(LoginContainer)} /> + path="logout" + component={ProxyHandler(AuthRedirect({ to: '/', when: 'loggedOut' }))(LogoutContainer)} /> + path="signup" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(SignupContainer)} /> + path="password_reset" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(PasswordResetContainer)} /> + path="settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(SettingsContainer)} /> + path="contract_settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(ContractSettings)} /> + aclName="acl_wallet_submit" /> + disableOn="noPieces" /> ), '23vivi': ( - - + + ), 'polline': ( - - + + + path="login" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(LoginContainer)} /> + path="logout" + component={ProxyHandler(AuthRedirect({ to: '/', when: 'loggedOut' }))(LogoutContainer)} /> + path="signup" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(SignupContainer)} /> + path="password_reset" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(PasswordResetContainer)} /> + path="settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(SettingsContainer)} /> + path="contract_settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(ContractSettings)} /> + aclName="acl_wallet_submit" /> - - - - + disableOn="noPieces" /> + + + + ), 'artcity': ( - - + + + path="login" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(LoginContainer)} /> + path="logout" + component={ProxyHandler(AuthRedirect({ to: '/', when: 'loggedOut' }))(LogoutContainer)} /> + path="signup" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(SignupContainer)} /> + path="password_reset" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(PasswordResetContainer)} /> + path="settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(SettingsContainer)} /> + path="contract_settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(ContractSettings)} /> + aclName="acl_wallet_submit" /> - - - - + disableOn="noPieces" /> + + + + ), 'demo': ( - - + + + path="login" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(LoginContainer)} /> + path="logout" + component={ProxyHandler(AuthRedirect({ to: '/', when: 'loggedOut' }))(LogoutContainer)} /> + path="signup" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(SignupContainer)} /> + path="password_reset" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(PasswordResetContainer)} /> + path="settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(SettingsContainer)} /> + path="contract_settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(ContractSettings)} /> + aclName="acl_wallet_submit" /> - - - - + disableOn="noPieces" /> + + + + ), 'liquidgallery': ( - - + + + path="login" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(LoginContainer)} /> + path="logout" + component={ProxyHandler(AuthRedirect({ to: '/', when: 'loggedOut' }))(LogoutContainer)} /> + path="signup" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(SignupContainer)} /> + path="password_reset" + component={ProxyHandler(AuthRedirect({ to: '/collection', when: 'loggedIn' }))(PasswordResetContainer)} /> + path="settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(SettingsContainer)} /> + path="contract_settings" + component={ProxyHandler(AuthRedirect({ to: '/login', when: 'loggedOut' }))(ContractSettings)} /> + aclName="acl_wallet_submit" /> - - - - + disableOn="noPieces" /> + + + + ) }; -function getRoutes(commonRoutes, subdomain) { - if(subdomain in ROUTES) { - return ROUTES[subdomain]; +export default function getWalletRoutes(subdomain) { + if (subdomain in ROUTES) { + return (ROUTES[subdomain]); } else { - throw new Error('Subdomain wasn\'t specified in the wallet app.'); + throw new Error("Subdomain wasn't specified in the wallet app."); } } - -export default getRoutes; diff --git a/js/constants/api_urls.js b/js/constants/api_urls.js index 79e7c83b..4e556bd8 100644 --- a/js/constants/api_urls.js +++ b/js/constants/api_urls.js @@ -1,13 +1,7 @@ -'use strict'; - import AppConstants from './application_constants'; -import getWalletApiUrls from '../components/whitelabel/wallet/constants/wallet_api_urls'; -import { update } from '../utils/general_utils'; - - -let ApiUrls = { +const ApiUrls = { 'applications': AppConstants.apiEndpoint + '/applications/', 'application_token_refresh': AppConstants.apiEndpoint + '/applications/refresh_token/', 'blob_digitalworks': AppConstants.apiEndpoint + '/blob/digitalworks/', @@ -79,10 +73,8 @@ let ApiUrls = { }; -export function updateApiUrls(type, subdomain) { - if (type === 'wallet') { - update(getWalletApiUrls(subdomain)); - } +export function updateApiUrls(updatedApiUrls) { + return Object.assign(ApiUrls, updatedApiUrls); } export default ApiUrls; diff --git a/js/routes.js b/js/routes.js index 3c7e1228..442f0c4d 100644 --- a/js/routes.js +++ b/js/routes.js @@ -1,10 +1,6 @@ -'use strict'; - import React from 'react'; import { Route } from 'react-router'; -import getWalletRoutes from './components/whitelabel/wallet/wallet_routes'; - import AscribeApp from './components/ascribe_app'; import PieceList from './components/piece_list'; @@ -31,62 +27,56 @@ import { ProxyHandler, AuthRedirect } from './components/ascribe_routes/proxy_ha import { getLangText } from './utils/lang_utils'; -const COMMON_ROUTES = ( - +const Routes = ( + - - - - ); - -function getRoutes(type, subdomain) { - if (type === 'wallet') { - return getWalletRoutes(COMMON_ROUTES, subdomain); - } else { - return COMMON_ROUTES; - } -} - - -export default getRoutes; +export default Routes; diff --git a/js/third_party/imports/shmui.js b/js/third_party/imports/shmui.js index e1be32f3..55873b9f 100644 --- a/js/third_party/imports/shmui.js +++ b/js/third_party/imports/shmui.js @@ -11,9 +11,9 @@ import { InjectInHeadUtils } from '../../utils/inject_utils'; function importLib() { return InjectInHeadUtils.inject(AppConstants.jquery.sdkUrl) .then(() => Promise.all([ - System.import('shmui/jquery.shmui.js'), + System.import('shmui/jquery.shmui'), System.import('shmui/shmui.css') - ])) + ])); } export default { importLib };