diff --git a/src/components/Page/Page.js b/src/components/Page/Page.js deleted file mode 100644 index 6be3286f..00000000 --- a/src/components/Page/Page.js +++ /dev/null @@ -1,23 +0,0 @@ -import React, { PropTypes } from 'react'; -import Helmet from 'react-helmet'; -import { Topbar } from '../../containers'; - -const Page = props => { - const { className, title, children } = props; - return ( -
- - -

{title}

- {children} -
- ); -}; - -const { string, any } = PropTypes; - -Page.defaultProps = { className: '', children: null }; - -Page.propTypes = { className: string, title: string.isRequired, children: any }; - -export default Page; diff --git a/src/components/PageLayout/PageLayout.js b/src/components/PageLayout/PageLayout.js new file mode 100644 index 00000000..d3ba63a6 --- /dev/null +++ b/src/components/PageLayout/PageLayout.js @@ -0,0 +1,42 @@ +import React, { Component, PropTypes } from 'react'; +import Helmet from 'react-helmet'; +import { Topbar } from '../../containers'; + +const scrollToTop = () => { + // Todo: this might need fine tuning later + window.scrollTo(0, 0); +} + +class PageLayout extends Component { + + componentDidMount() { + this.historyUnlisten = this.context.history.listen(() => scrollToTop()); + } + + componentWillUnmount() { + this.historyUnlisten(); + } + + + render() { + const { className, title, children } = this.props; + return ( +
+ + +

{title}

+ {children} +
+ ); + } +} + +PageLayout.contextTypes = { history: React.PropTypes.object }; + +PageLayout.defaultProps = { className: '', children: null }; + +const { string, any } = PropTypes; + +Page.propTypes = { className: string, title: string.isRequired, children: any }; + +export default Page; diff --git a/src/components/index.js b/src/components/index.js index 151ee0f4..3c747810 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -1,4 +1,4 @@ /* eslint-disable import/prefer-default-export */ -import Page from './Page/Page'; +import PageLayout from './PageLayout/PageLayout'; -export { Page }; +export { PageLayout }; diff --git a/src/containers/AuthenticationPage/AuthenticationPage.js b/src/containers/AuthenticationPage/AuthenticationPage.js index 648a4b42..76eac332 100644 --- a/src/containers/AuthenticationPage/AuthenticationPage.js +++ b/src/containers/AuthenticationPage/AuthenticationPage.js @@ -1,6 +1,6 @@ import React, { Component, PropTypes } from 'react'; import { Link, Redirect } from 'react-router'; -import { Page } from '../../components'; +import { PageLayout } from '../../components'; import { fakeAuth } from '../../Routes'; class AuthenticationPage extends Component { @@ -30,30 +30,28 @@ class AuthenticationPage extends Component { const alternativeMethod = this.props.tab === 'login' ? toSignup : toLogin; const currentMethod = this.props.tab === 'login' ? 'Log in' : 'Sign up'; - const fromLoginMsg = from ? ( -

- You must log in to view the page at - {from.pathname} -

- ) : null; + const fromLoginMsg = from ?

+ You must log in to view the page at + {from.pathname} +

: null; return ( - + {redirectToReferrer ? : null} {fromLoginMsg}

or {alternativeMethod}

-
+ ); } } AuthenticationPage.defaultProps = { location: {}, tab: 'signup' }; -const { shape, string, oneOf } = PropTypes; +const { shape, string, object, oneOf, oneOfType } = PropTypes; AuthenticationPage.propTypes = { - location: shape({ state: shape({ from: string }) }), + location: shape({ state: shape({ from: oneOfType([object, string]) }) }), tab: oneOf([ 'login', 'signup' ]), }; diff --git a/src/containers/AuthenticationPage/AuthenticationPage.test.js b/src/containers/AuthenticationPage/AuthenticationPage.test.js index c6fc46de..c6885d77 100644 --- a/src/containers/AuthenticationPage/AuthenticationPage.test.js +++ b/src/containers/AuthenticationPage/AuthenticationPage.test.js @@ -6,11 +6,9 @@ import AuthenticationPage from './AuthenticationPage'; describe('AuthenticationPage', () => { it('matches snapshot', () => { const component = renderer.create( - ( - - - - ), + + + , ); const tree = component.toJSON(); expect(tree).toMatchSnapshot(); diff --git a/src/containers/CheckoutPage/CheckoutPage.js b/src/containers/CheckoutPage/CheckoutPage.js index c4aac069..9f2f1a3d 100644 --- a/src/containers/CheckoutPage/CheckoutPage.js +++ b/src/containers/CheckoutPage/CheckoutPage.js @@ -1,11 +1,11 @@ import React, { PropTypes } from 'react'; import { Link } from 'react-router'; -import { Page } from '../../components'; +import { PageLayout } from '../../components'; const CheckoutPage = ({ params }) => ( - + - + ); const { shape, string } = PropTypes; diff --git a/src/containers/CheckoutPage/CheckoutPage.test.js b/src/containers/CheckoutPage/CheckoutPage.test.js index 14834f2f..0887a31a 100644 --- a/src/containers/CheckoutPage/CheckoutPage.test.js +++ b/src/containers/CheckoutPage/CheckoutPage.test.js @@ -6,11 +6,9 @@ import CheckoutPage from './CheckoutPage'; describe('CheckoutPage', () => { it('matches snapshot', () => { const component = renderer.create( - ( - - - - ), + + + , ); const tree = component.toJSON(); expect(tree).toMatchSnapshot(); diff --git a/src/containers/ContactDetailsPage/ContactDetailsPage.js b/src/containers/ContactDetailsPage/ContactDetailsPage.js index c66b62af..c96ad26b 100644 --- a/src/containers/ContactDetailsPage/ContactDetailsPage.js +++ b/src/containers/ContactDetailsPage/ContactDetailsPage.js @@ -1,4 +1,4 @@ import React from 'react'; -import { Page } from '../../components'; +import { PageLayout } from '../../components'; -export default () => +export default () => ; diff --git a/src/containers/ContactDetailsPage/ContactDetailsPage.test.js b/src/containers/ContactDetailsPage/ContactDetailsPage.test.js index ae0d096c..31207dc4 100644 --- a/src/containers/ContactDetailsPage/ContactDetailsPage.test.js +++ b/src/containers/ContactDetailsPage/ContactDetailsPage.test.js @@ -6,11 +6,9 @@ import ContactDetailsPage from './ContactDetailsPage'; describe('ContactDetailsPage', () => { it('matches snapshot', () => { const component = renderer.create( - ( - - - - ), + + + , ); const tree = component.toJSON(); expect(tree).toMatchSnapshot(); diff --git a/src/containers/ConversationPage/ConversationPage.js b/src/containers/ConversationPage/ConversationPage.js index 8803ef02..5365123a 100644 --- a/src/containers/ConversationPage/ConversationPage.js +++ b/src/containers/ConversationPage/ConversationPage.js @@ -1,12 +1,12 @@ import React, { PropTypes } from 'react'; -import { Page } from '../../components'; +import { PageLayout } from '../../components'; const ConversationPage = props => { const { params } = props; return ( - +

Conversation id: {params.id}

-
+
); }; diff --git a/src/containers/ConversationPage/ConversationPage.test.js b/src/containers/ConversationPage/ConversationPage.test.js index 3d9af4af..eef04a4c 100644 --- a/src/containers/ConversationPage/ConversationPage.test.js +++ b/src/containers/ConversationPage/ConversationPage.test.js @@ -6,11 +6,9 @@ import ConversationPage from './ConversationPage'; describe('ConversationPage', () => { it('matches snapshot', () => { const component = renderer.create( - ( - - - - ), + + + , ); const tree = component.toJSON(); expect(tree).toMatchSnapshot(); diff --git a/src/containers/EditProfilePage/EditProfilePage.js b/src/containers/EditProfilePage/EditProfilePage.js index d92cbe7c..99a1da1c 100644 --- a/src/containers/EditProfilePage/EditProfilePage.js +++ b/src/containers/EditProfilePage/EditProfilePage.js @@ -1,9 +1,9 @@ import React, { PropTypes } from 'react'; -import { Page } from '../../components'; +import { PageLayout } from '../../components'; const EditProfilePage = props => { const { params } = props; - return ; + return ; }; const { shape, string } = PropTypes; diff --git a/src/containers/EditProfilePage/EditProfilePage.test.js b/src/containers/EditProfilePage/EditProfilePage.test.js index ef5c30ba..98a22b7e 100644 --- a/src/containers/EditProfilePage/EditProfilePage.test.js +++ b/src/containers/EditProfilePage/EditProfilePage.test.js @@ -6,11 +6,9 @@ import EditProfilePage from './EditProfilePage'; describe('EditProfilePage', () => { it('matches snapshot', () => { const component = renderer.create( - ( - - - - ), + + + , ); const tree = component.toJSON(); expect(tree).toMatchSnapshot(); diff --git a/src/containers/InboxPage/InboxPage.js b/src/containers/InboxPage/InboxPage.js index f94605a9..01035ee9 100644 --- a/src/containers/InboxPage/InboxPage.js +++ b/src/containers/InboxPage/InboxPage.js @@ -1,6 +1,6 @@ import React, { PropTypes } from 'react'; import { Link } from 'react-router'; -import { Page } from '../../components'; +import { PageLayout } from '../../components'; const toPath = (filter, id) => { switch (filter) { @@ -16,11 +16,11 @@ const toPath = (filter, id) => { const InboxPage = props => { const { filter } = props; return ( - +
  • Single thread
-
+
); }; @@ -28,6 +28,6 @@ InboxPage.defaultProps = { filter: 'conversation' }; const { oneOf } = PropTypes; -InboxPage.propTypes = { filter: oneOf([ 'orders', 'sales', 'conversation' ]) }; +InboxPage.propTypes = { filter: oneOf([ 'orders', 'sales', 'inbox' ]) }; export default InboxPage; diff --git a/src/containers/InboxPage/InboxPage.test.js b/src/containers/InboxPage/InboxPage.test.js index 7076f86e..cd8eb048 100644 --- a/src/containers/InboxPage/InboxPage.test.js +++ b/src/containers/InboxPage/InboxPage.test.js @@ -8,7 +8,7 @@ describe('InboxPage', () => { const component = renderer.create( ( - + ), ); diff --git a/src/containers/InboxPage/__snapshots__/InboxPage.test.js.snap b/src/containers/InboxPage/__snapshots__/InboxPage.test.js.snap index 3c315f29..41351df5 100644 --- a/src/containers/InboxPage/__snapshots__/InboxPage.test.js.snap +++ b/src/containers/InboxPage/__snapshots__/InboxPage.test.js.snap @@ -135,7 +135,7 @@ exports[`InboxPage matches snapshot 1`] = `

- conversation page + inbox page