From d50d0faabe655799e09699a0e3519e34ede118c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 29 Sep 2015 14:58:56 +0200 Subject: [PATCH 1/6] Write generic function for extracting subdomain and implement troughout whole app --- js/app.js | 10 ++++++---- js/components/whitelabel/prize/prize_app.js | 5 ++++- js/components/whitelabel/wallet/wallet_app.js | 4 +++- js/fetchers/license_fetcher.js | 5 ++++- js/fetchers/whitelabel_fetcher.js | 5 ++++- js/third_party/intercom.js | 4 +++- js/third_party/notifications.js | 6 ++++-- js/utils/general_utils.js | 11 +++++++++++ 8 files changed, 39 insertions(+), 11 deletions(-) diff --git a/js/app.js b/js/app.js index 30a57d2b..bd1b839a 100644 --- a/js/app.js +++ b/js/app.js @@ -10,13 +10,15 @@ import fetch from 'isomorphic-fetch'; /* eslint-enable */ import ApiUrls from './constants/api_urls'; -import { updateApiUrls } from './constants/api_urls'; -import appConstants from './constants/application_constants'; + +import AppConstants from './constants/application_constants'; import getRoutes from './routes'; import requests from './utils/requests'; +import { updateApiUrls } from './constants/api_urls'; import { getSubdomainSettings } from './utils/constants_utils'; import { initLogging } from './utils/error_utils'; +import { getSubdomain } from './utils/general_utils'; import EventActions from './actions/event_actions'; @@ -48,11 +50,11 @@ requests.defaults({ class AppGateway { start() { let settings; - let subdomain = window.location.host.split('.')[0]; + let subdomain = getSubdomain(); try { settings = getSubdomainSettings(subdomain); - appConstants.whitelabel = settings; + AppConstants.whitelabel = settings; updateApiUrls(settings.type, subdomain); this.load(settings); } catch(err) { diff --git a/js/components/whitelabel/prize/prize_app.js b/js/components/whitelabel/prize/prize_app.js index f187dd1c..e0be7707 100644 --- a/js/components/whitelabel/prize/prize_app.js +++ b/js/components/whitelabel/prize/prize_app.js @@ -9,6 +9,9 @@ import GlobalNotification from '../../global_notification'; import getRoutes from './prize_routes'; +import { getSubdomain } from '../../../utils/general_utils'; + + let RouteHandler = Router.RouteHandler; let PrizeApp = React.createClass({ @@ -16,7 +19,7 @@ let PrizeApp = React.createClass({ render() { let header = null; - let subdomain = window.location.host.split('.')[0]; + let subdomain = getSubdomain(); let ROUTES = getRoutes(null, subdomain); diff --git a/js/components/whitelabel/wallet/wallet_app.js b/js/components/whitelabel/wallet/wallet_app.js index 2a235cef..bbc58689 100644 --- a/js/components/whitelabel/wallet/wallet_app.js +++ b/js/components/whitelabel/wallet/wallet_app.js @@ -10,6 +10,8 @@ import GlobalNotification from '../../global_notification'; import getRoutes from './wallet_routes'; import classNames from 'classnames'; +import { getSubdomain } from '../../../utils/general_utils'; + let RouteHandler = Router.RouteHandler; @@ -18,7 +20,7 @@ let WalletApp = React.createClass({ mixins: [Router.State], render() { - let subdomain = window.location.host.split('.')[0]; + let subdomain = getSubdomain(); let ROUTES = getRoutes(null, subdomain); let activeRoutes = this.getRoutes().map(elem => 'route--' + elem.name); diff --git a/js/fetchers/license_fetcher.js b/js/fetchers/license_fetcher.js index 6b0cada0..d5b296be 100644 --- a/js/fetchers/license_fetcher.js +++ b/js/fetchers/license_fetcher.js @@ -2,12 +2,15 @@ import requests from '../utils/requests'; +import { getSubdomain } from '../utils/general_utils'; + + let LicenseFetcher = { /** * Fetch the available licenses from the API (might be bound to the subdomain e.g. cc.ascribe.io). */ fetch() { - return requests.get('licenses', {'subdomain': window.location.host.split('.')[0]}); + return requests.get('licenses', {'subdomain': getSubdomain()}); } }; diff --git a/js/fetchers/whitelabel_fetcher.js b/js/fetchers/whitelabel_fetcher.js index 51f4ed0f..7a39f676 100644 --- a/js/fetchers/whitelabel_fetcher.js +++ b/js/fetchers/whitelabel_fetcher.js @@ -2,12 +2,15 @@ import requests from '../utils/requests'; +import { getSubdomain } from '../utils/general_utils'; + + let WhitelabelFetcher = { /** * Fetch the custom whitelabel data from the API. */ fetch() { - return requests.get('whitelabel_settings', {'subdomain': window.location.host.split('.')[0]}); + return requests.get('whitelabel_settings', {'subdomain': getSubdomain()}); } }; diff --git a/js/third_party/intercom.js b/js/third_party/intercom.js index ef284d7b..42ecccf7 100644 --- a/js/third_party/intercom.js +++ b/js/third_party/intercom.js @@ -3,6 +3,8 @@ import alt from '../alt'; import EventActions from '../actions/event_actions'; +import { getSubdomain } from '../utils/general_utils'; + class IntercomHandler { constructor() { @@ -20,7 +22,7 @@ class IntercomHandler { /* eslint-enable */ app_id: 'oboxh5w1', email: profile.email, - subdomain: window.location.host.split('.')[0], + subdomain: getSubdomain(), widget: { activator: '#IntercomDefaultWidget' } diff --git a/js/third_party/notifications.js b/js/third_party/notifications.js index 8887bbe2..eeac1bff 100644 --- a/js/third_party/notifications.js +++ b/js/third_party/notifications.js @@ -5,6 +5,8 @@ import EventActions from '../actions/event_actions'; import NotificationActions from '../actions/notification_actions'; +import { getSubdomain } from '../utils/general_utils'; + class NotificationsHandler { @@ -13,11 +15,11 @@ class NotificationsHandler { this.loaded = false; } - onProfileDidLoad(profile) { + onProfileDidLoad() { if (this.loaded) { return; } - let subdomain = window.location.host.split('.')[0]; + let subdomain = getSubdomain(); if (subdomain === 'ikonotv') { NotificationActions.fetchContractAgreementListNotifications().then( (res) => { diff --git a/js/utils/general_utils.js b/js/utils/general_utils.js index ba2b7752..8f4aebbc 100644 --- a/js/utils/general_utils.js +++ b/js/utils/general_utils.js @@ -221,4 +221,15 @@ export function truncateTextAtCharIndex(text, charIndex, replacement = '...') { truncatedText += text.length > charIndex ? replacement : ''; return truncatedText; +} + +/** + * Extracts the user's subdomain from the browser's window. + * If no subdomain is found (for example on a naked domain), the default "www" is just assumed. + * @return {string} subdomain as a string + */ +export function getSubdomain() { + let { host } = window.location; + let matchedHost = host.match(/(([^.]+)\.)?(.*)\.(.*)/); + return matchedHost[2] || 'www'; } \ No newline at end of file From 90cf137c2c6adc1f99e4d0320a37e7a8a76464c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 29 Sep 2015 16:00:58 +0200 Subject: [PATCH 2/6] Integrate error page in app + whitelabel pages --- js/components/error_not_found_page.js | 14 ++++++++++++++ js/components/whitelabel/prize/prize_routes.js | 3 +++ js/components/whitelabel/wallet/wallet_routes.js | 5 +++++ js/routes.js | 4 ++++ 4 files changed, 26 insertions(+) create mode 100644 js/components/error_not_found_page.js diff --git a/js/components/error_not_found_page.js b/js/components/error_not_found_page.js new file mode 100644 index 00000000..6de7c1f0 --- /dev/null +++ b/js/components/error_not_found_page.js @@ -0,0 +1,14 @@ +'use strict'; + +import React from 'react'; + + +let ErrorNotFoundPage = React.createClass({ + render() { + return ( + Hello + ); + } +}); + +export default ErrorNotFoundPage; \ No newline at end of file diff --git a/js/components/whitelabel/prize/prize_routes.js b/js/components/whitelabel/prize/prize_routes.js index d3031774..7ca132e2 100644 --- a/js/components/whitelabel/prize/prize_routes.js +++ b/js/components/whitelabel/prize/prize_routes.js @@ -14,11 +14,13 @@ import PrizePieceContainer from './components/ascribe_detail/prize_piece_contain import EditionContainer from '../../ascribe_detail/edition_container'; import SettingsContainer from './components/prize_settings_container'; import CoaVerifyContainer from '../../../components/coa_verify_container'; +import ErrorNotFoundPage from '../../../components/error_not_found_page'; import App from './prize_app'; import AppConstants from '../../../constants/application_constants'; let Route = Router.Route; +let NotFoundRoute = Router.NotFoundRoute; let baseUrl = AppConstants.baseUrl; @@ -36,6 +38,7 @@ function getRoutes() { + ); } diff --git a/js/components/whitelabel/wallet/wallet_routes.js b/js/components/whitelabel/wallet/wallet_routes.js index 4aad0ae0..7097a88b 100644 --- a/js/components/whitelabel/wallet/wallet_routes.js +++ b/js/components/whitelabel/wallet/wallet_routes.js @@ -14,6 +14,7 @@ import PieceContainer from '../../../components/ascribe_detail/piece_container'; import EditionContainer from '../../../components/ascribe_detail/edition_container'; 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 CylandLanding from './components/cyland/cyland_landing'; import CylandPieceContainer from './components/cyland/ascribe_detail/cyland_piece_container'; @@ -33,6 +34,7 @@ import WalletApp from './wallet_app'; import AppConstants from '../../../constants/application_constants'; let Route = Router.Route; +let NotFoundRoute = Router.NotFoundRoute; let Redirect = Router.Redirect; let baseUrl = AppConstants.baseUrl; @@ -52,6 +54,7 @@ let ROUTES = { + ), 'cc': ( @@ -68,6 +71,7 @@ let ROUTES = { + ), 'ikonotv': ( @@ -86,6 +90,7 @@ let ROUTES = { + ) }; diff --git a/js/routes.js b/js/routes.js index 1366f205..a8b024d4 100644 --- a/js/routes.js +++ b/js/routes.js @@ -21,11 +21,14 @@ import ContractSettings from './components/ascribe_settings/contract_settings'; import SettingsContainer from './components/ascribe_settings/settings_container'; import CoaVerifyContainer from './components/coa_verify_container'; +import ErrorNotFoundPage from './components/error_not_found_page'; + import RegisterPiece from './components/register_piece'; import AppConstants from './constants/application_constants'; let Route = Router.Route; +let NotFoundRoute = Router.NotFoundRoute; let Redirect = Router.Redirect; let baseUrl = AppConstants.baseUrl; @@ -45,6 +48,7 @@ const COMMON_ROUTES = ( + ); From e356570bc89d41d417f1ca85d3074adf36ddfd2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 29 Sep 2015 17:56:18 +0200 Subject: [PATCH 3/6] remove console log --- js/components/ascribe_detail/edition.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/components/ascribe_detail/edition.js b/js/components/ascribe_detail/edition.js index 51884751..97f9fb3d 100644 --- a/js/components/ascribe_detail/edition.js +++ b/js/components/ascribe_detail/edition.js @@ -100,7 +100,6 @@ let Edition = React.createClass({ }, refreshCollection() { - console.log('freshing'); PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc, this.state.filterBy); EditionListActions.refreshEditionList({pieceId: this.props.edition.parent}); From 99d29449a3482b78a4611757e13fc0de35dbe70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Wed, 30 Sep 2015 10:44:38 +0200 Subject: [PATCH 4/6] style 404 page --- js/components/error_not_found_page.js | 11 ++++++++++- sass/main.scss | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/js/components/error_not_found_page.js b/js/components/error_not_found_page.js index 6de7c1f0..32787cb4 100644 --- a/js/components/error_not_found_page.js +++ b/js/components/error_not_found_page.js @@ -6,7 +6,16 @@ import React from 'react'; let ErrorNotFoundPage = React.createClass({ render() { return ( - Hello +
+
+
+

404

+

+ Ups, the page you are looking for does not exist. +

+
+
+
); } }); diff --git a/sass/main.scss b/sass/main.scss index 1e56c7ed..d5fef084 100644 --- a/sass/main.scss +++ b/sass/main.scss @@ -480,3 +480,20 @@ hr { border-color: #ccc; } } + +.error-wrapper { + width: 100%; + text-align: center; + + padding: 5% 20% 5% 20%; + + > h1 { + font-size: 10em; + font-weight: 600; + margin-bottom: .25em; + } + + > p { + font-size: 2em; + } +} \ No newline at end of file From dc753caf87808c94c46e4111e0d23ef4e1294137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Wed, 30 Sep 2015 11:06:42 +0200 Subject: [PATCH 5/6] Add getLangText to ErrorNotFoundPage --- js/components/error_not_found_page.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/components/error_not_found_page.js b/js/components/error_not_found_page.js index 32787cb4..61f83196 100644 --- a/js/components/error_not_found_page.js +++ b/js/components/error_not_found_page.js @@ -2,6 +2,8 @@ import React from 'react'; +import { getLangText } from '../utils/lang_utils'; + let ErrorNotFoundPage = React.createClass({ render() { @@ -11,7 +13,7 @@ let ErrorNotFoundPage = React.createClass({

404

- Ups, the page you are looking for does not exist. + {getLangText('Ups, the page you are looking for does not exist.')}

From aa908a1c57444f8c52c7f729fb7a515e57335089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Wed, 30 Sep 2015 11:09:04 +0200 Subject: [PATCH 6/6] PR Feedback: Simplify subdomain extraction --- js/utils/general_utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/utils/general_utils.js b/js/utils/general_utils.js index 8f4aebbc..2cba98b9 100644 --- a/js/utils/general_utils.js +++ b/js/utils/general_utils.js @@ -230,6 +230,6 @@ export function truncateTextAtCharIndex(text, charIndex, replacement = '...') { */ export function getSubdomain() { let { host } = window.location; - let matchedHost = host.match(/(([^.]+)\.)?(.*)\.(.*)/); - return matchedHost[2] || 'www'; + let tokens = host.split('.'); + return tokens.length > 2 ? tokens[0] : 'www'; } \ No newline at end of file