Newsletter
@@ -335,7 +334,7 @@ export default class AccountHomePage extends React.Component {
componentDidMount() {
const {member} = this.context;
- if (!member && !isPreviewMode()) {
+ if (!member) {
this.context.onAction('switchPage', {
page: 'signup'
});
diff --git a/ghost/portal/src/components/pages/AccountPlanPage.js b/ghost/portal/src/components/pages/AccountPlanPage.js
index be08f8664e..6b0f1c52be 100644
--- a/ghost/portal/src/components/pages/AccountPlanPage.js
+++ b/ghost/portal/src/components/pages/AccountPlanPage.js
@@ -1,7 +1,6 @@
import AppContext from '../../AppContext';
import ActionButton from '../common/ActionButton';
import PlansSection from '../common/PlansSection';
-import isPreviewMode from '../../utils/is-preview-mode';
import {ReactComponent as ArrowLeftIcon} from '../../images/icons/arrow-left.svg';
const React = require('react');
@@ -20,7 +19,7 @@ export default class AccountPlanPage extends React.Component {
componentDidMount() {
const {member} = this.context;
- if (!member && !isPreviewMode()) {
+ if (!member) {
this.context.onAction('switchPage', {
page: 'signup'
});
diff --git a/ghost/portal/src/components/pages/AccountProfilePage.js b/ghost/portal/src/components/pages/AccountProfilePage.js
index d36f97019d..0a39782fd9 100644
--- a/ghost/portal/src/components/pages/AccountProfilePage.js
+++ b/ghost/portal/src/components/pages/AccountProfilePage.js
@@ -3,7 +3,6 @@ import MemberAvatar from '../common/MemberGravatar';
import ActionButton from '../common/ActionButton';
import InputField from '../common/InputField';
import Switch from '../common/Switch';
-import isPreviewMode from '../../utils/is-preview-mode';
import {ReactComponent as ArrowLeftIcon} from '../../images/icons/arrow-left.svg';
const React = require('react');
@@ -22,7 +21,7 @@ export default class AccountProfilePage extends React.Component {
componentDidMount() {
const {member} = this.context;
- if (!member && !isPreviewMode()) {
+ if (!member) {
this.context.onAction('switchPage', {
page: 'signup'
});
diff --git a/ghost/portal/src/components/pages/SigninPage.js b/ghost/portal/src/components/pages/SigninPage.js
index 6ccc0ed5ef..9ef31f0f94 100644
--- a/ghost/portal/src/components/pages/SigninPage.js
+++ b/ghost/portal/src/components/pages/SigninPage.js
@@ -1,7 +1,6 @@
import ActionButton from '../common/ActionButton';
import InputField from '../common/InputField';
import AppContext from '../../AppContext';
-import isPreviewMode from '../../utils/is-preview-mode';
const React = require('react');
@@ -17,7 +16,7 @@ export default class SigninPage extends React.Component {
componentDidMount() {
const {member} = this.context;
- if (member && !isPreviewMode()) {
+ if (member) {
this.context.onAction('switchPage', {
page: 'accountHome'
});
diff --git a/ghost/portal/src/components/pages/SignupPage.js b/ghost/portal/src/components/pages/SignupPage.js
index 7e7e29da38..d25b158641 100644
--- a/ghost/portal/src/components/pages/SignupPage.js
+++ b/ghost/portal/src/components/pages/SignupPage.js
@@ -2,7 +2,6 @@ import ActionButton from '../common/ActionButton';
import InputField from '../common/InputField';
import AppContext from '../../AppContext';
import PlansSection from '../common/PlansSection';
-import isPreviewMode from '../../utils/is-preview-mode';
const React = require('react');
@@ -20,7 +19,7 @@ class SignupPage extends React.Component {
componentDidMount() {
const {member} = this.context;
- if (member && !isPreviewMode()) {
+ if (member) {
this.context.onAction('switchPage', {
page: 'accountHome'
});
diff --git a/ghost/portal/src/pages.js b/ghost/portal/src/pages.js
new file mode 100644
index 0000000000..57e9f90958
--- /dev/null
+++ b/ghost/portal/src/pages.js
@@ -0,0 +1,36 @@
+import SigninPage from './components/pages/SigninPage';
+import SignupPage from './components/pages/SignupPage';
+import AccountHomePage from './components/pages/AccountHomePage';
+import MagicLinkPage from './components/pages/MagicLinkPage';
+import LoadingPage from './components/pages/LoadingPage';
+import AccountPlanPage from './components/pages/AccountPlanPage';
+import AccountProfilePage from './components/pages/AccountProfilePage';
+import LinkPage from './components/pages/LinkPage';
+
+/** List of all available pages in Portal, mapped to their UI component
+ * Any new page added to portal needs to be mapped here
+*/
+const Pages = {
+ signin: SigninPage,
+ signup: SignupPage,
+ accountHome: AccountHomePage,
+ accountPlan: AccountPlanPage,
+ accountProfile: AccountProfilePage,
+ magiclink: MagicLinkPage,
+ loading: LoadingPage,
+ links: LinkPage
+};
+
+/** Return page if valid, fallback to signup */
+export const getActivePage = function ({page}) {
+ if (Object.keys(Pages).includes(page)) {
+ return page;
+ }
+ return 'signup';
+};
+
+export const isAccountPage = function ({page}) {
+ return page.includes('account');
+};
+
+export default Pages;
\ No newline at end of file
diff --git a/ghost/portal/src/utils/api.js b/ghost/portal/src/utils/api.js
index de01eba5a2..65d2c008f6 100644
--- a/ghost/portal/src/utils/api.js
+++ b/ghost/portal/src/utils/api.js
@@ -1,4 +1,5 @@
import * as Fixtures from './fixtures';
+import {hasMode} from './check-mode';
function setupGhostApi({siteUrl = window.location.origin}) {
const apiPath = 'members/api';
@@ -215,11 +216,10 @@ function setupGhostApi({siteUrl = window.location.origin}) {
};
api.init = async () => {
- // Load member from fixtures for local development
- if (process.env.NODE_ENV === 'development') {
- return {site: Fixtures.site, member: null};
- }
-
+ // // Load site data from fixtures for dev/test modes
+ // if (hasMode(['dev', 'test'])) {
+ // return {site: Fixtures.site, member: null};
+ // }
const {site} = await api.site.read();
const member = await api.member.sessionData();
return {site, member};
diff --git a/ghost/portal/src/utils/check-mode.js b/ghost/portal/src/utils/check-mode.js
new file mode 100644
index 0000000000..5a350adeb0
--- /dev/null
+++ b/ghost/portal/src/utils/check-mode.js
@@ -0,0 +1,25 @@
+export const isPreviewMode = function () {
+ const [path, qs] = window.location.hash.substr(1).split('?');
+ return (path === '/portal/preview') || (path === '/portal' && qs);
+};
+
+export const isDevMode = function () {
+ return (process.env.NODE_ENV === 'development');
+};
+
+export const isTestMode = function () {
+ return (process.env.NODE_ENV === 'test');
+};
+
+const modeFns = {
+ preview: isPreviewMode,
+ dev: isDevMode,
+ test: isTestMode
+};
+
+export const hasMode = (modes = []) => {
+ return modes.some((mode) => {
+ const modeFn = modeFns[mode];
+ return !!(modeFn && modeFn());
+ });
+};
\ No newline at end of file
diff --git a/ghost/portal/src/utils/is-preview-mode.js b/ghost/portal/src/utils/is-preview-mode.js
deleted file mode 100644
index 74e1cf5d96..0000000000
--- a/ghost/portal/src/utils/is-preview-mode.js
+++ /dev/null
@@ -1,6 +0,0 @@
-function isPreviewMode() {
- const [path, qs] = window.location.hash.substr(1).split('?');
- return ((process.env.NODE_ENV === 'development') || (path === '/portal' && qs));
-}
-
-export default isPreviewMode;
\ No newline at end of file