From 8d9c078309e50ca7ad226e8b85d700a5db2d4c91 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Tue, 15 Aug 2017 16:03:24 +0300 Subject: [PATCH 1/5] Improve routing - Allow setting `preferLogin` in route config to enable redirecting to login page instead of signup page - Add missing search params to the auth redirect --- src/Routes.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Routes.js b/src/Routes.js index 261d4578..3565dd37 100644 --- a/src/Routes.js +++ b/src/Routes.js @@ -54,18 +54,22 @@ class RouteComponentRenderer extends Component { render() { const { route, match, location, staticContext, flattenedRoutes } = this.props; - const { component: RouteComponent } = route; + const { component: RouteComponent, preferLogin = false } = route; const canShow = this.canShowComponent(); if (!canShow) { staticContext.forbidden = true; } + const authPageName = preferLogin ? 'LoginPage' : 'SignupPage'; return canShow ? - : ; + : ; } } From 01dbdafbec2ad39e8efaab3f5bf49b99d3e98e59 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Tue, 15 Aug 2017 16:04:23 +0300 Subject: [PATCH 2/5] Prefer login page for email confirmation --- src/app.test.js | 6 ++++-- src/routesConfiguration.js | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app.test.js b/src/app.test.js index a34f9162..ee59940a 100644 --- a/src/app.test.js +++ b/src/app.test.js @@ -60,7 +60,9 @@ describe('Application', () => { }); it('server renders redirects for pages that require authentication', () => { - const defaultAuthPath = '/signup'; + const loginPath = '/login'; + const signupPath = '/signup'; + const defaultAuthPath = signupPath; const urlRedirects = { '/l/new': defaultAuthPath, '/l/listing-title-slug/1234/new/description': defaultAuthPath, @@ -80,7 +82,7 @@ describe('Application', () => { '/account/contact-details': defaultAuthPath, '/account/payout-preferences': defaultAuthPath, '/account/security': defaultAuthPath, - '/email_verification': defaultAuthPath, + '/email_verification': loginPath, }; forEach(urlRedirects, (redirectPath, url) => { const context = {}; diff --git a/src/routesConfiguration.js b/src/routesConfiguration.js index 46b28486..b675a90c 100644 --- a/src/routesConfiguration.js +++ b/src/routesConfiguration.js @@ -309,6 +309,7 @@ const routesConfiguration = [ { path: '/email_verification', auth: true, + preferLogin: true, exact: true, name: 'EmailVerificationPage', component: props => , From 20160382777ec9d9d7e8127434ccda288951fab3 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Tue, 15 Aug 2017 16:04:38 +0300 Subject: [PATCH 3/5] Fix broken logout and lint errors --- .../EmailVerificationPage.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/containers/EmailVerificationPage/EmailVerificationPage.js b/src/containers/EmailVerificationPage/EmailVerificationPage.js index 497fa8a9..03958f4b 100644 --- a/src/containers/EmailVerificationPage/EmailVerificationPage.js +++ b/src/containers/EmailVerificationPage/EmailVerificationPage.js @@ -6,7 +6,7 @@ import { FormattedMessage, injectIntl, intlShape } from 'react-intl'; import * as propTypes from '../../util/propTypes'; import { PageLayout, Topbar } from '../../components'; import { EmailVerificationForm } from '../../containers'; -import { authenticationInProgress } from '../../ducks/Auth.duck'; +import { logout, authenticationInProgress } from '../../ducks/Auth.duck'; import { verify, verificationInProgress } from '../../ducks/EmailVerification.duck'; import { manageDisableScrolling, isScrollingDisabled } from '../../ducks/UI.duck'; import { parse } from '../../util/urlHelpers'; @@ -50,6 +50,8 @@ export const EmailVerificationPageComponent = props => { submitVerification, emailVerificationInProgress, verificationError, + location, + history, } = props; const title = intl.formatMessage({ id: 'EmailVerificationPage.title', @@ -102,7 +104,7 @@ EmailVerificationPageComponent.defaultProps = { verificationError: null, }; -const { bool, func, instanceOf, number } = PropTypes; +const { bool, func, instanceOf, number, object, shape, string } = PropTypes; EmailVerificationPageComponent.propTypes = { authInfoError: instanceOf(Error), @@ -118,6 +120,14 @@ EmailVerificationPageComponent.propTypes = { submitVerification: func.isRequired, emailVerificationInProgress: bool.isRequired, verificationError: instanceOf(Error), + + // from withRouter + history: object.isRequired, + location: shape({ + search: string, + }).isRequired, + + // from injectIntl intl: intlShape.isRequired, }; @@ -150,6 +160,7 @@ const mapStateToProps = state => { }; const mapDispatchToProps = dispatch => ({ + onLogout: () => dispatch(logout()), onManageDisableScrolling: (componentId, disableScrolling) => dispatch(manageDisableScrolling(componentId, disableScrolling)), submitVerification: ({ verificationToken }) => { From 9027d07a846f27e38f1b27ecb8a8a74e34e48053 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Tue, 15 Aug 2017 16:08:12 +0300 Subject: [PATCH 4/5] Format JS --- src/components/SearchMap/SearchMap.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/SearchMap/SearchMap.js b/src/components/SearchMap/SearchMap.js index 8b3447c0..f433484c 100644 --- a/src/components/SearchMap/SearchMap.js +++ b/src/components/SearchMap/SearchMap.js @@ -45,7 +45,6 @@ const MapWithGoogleMap = withGoogleMap(props => { const { center, listings, listingOpen, onListingClicked, onMapLoad, zoom } = props; const priceLabels = listings.reverse().map(listing => { - // if the listing is open, don't print price label if (listingOpen && listingOpen.id.uuid === listing.id.uuid) { return null; @@ -105,7 +104,6 @@ export class SearchMapComponent extends Component { } onMapClicked(e) { - // Close open listing popup / infobox, unless the click is attached to a price label const labelClicked = hasParentWithClassName(e.nativeEvent.target, PRICE_LABEL_HANDLE); if (this.state.listingOpen != null && !labelClicked) { From 2b359caa0aa11e54c4c936c2de66e2a1c3ab7410 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Wed, 16 Aug 2017 09:09:52 +0300 Subject: [PATCH 5/5] Improve routing changes - Add hash to saved from page - Use authPage instead of preferLogin for more flexibility --- src/Routes.js | 7 +++---- src/routesConfiguration.js | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Routes.js b/src/Routes.js index 3565dd37..0fa7ca4f 100644 --- a/src/Routes.js +++ b/src/Routes.js @@ -54,12 +54,11 @@ class RouteComponentRenderer extends Component { render() { const { route, match, location, staticContext, flattenedRoutes } = this.props; - const { component: RouteComponent, preferLogin = false } = route; + const { component: RouteComponent, authPage = 'SignupPage' } = route; const canShow = this.canShowComponent(); if (!canShow) { staticContext.forbidden = true; } - const authPageName = preferLogin ? 'LoginPage' : 'SignupPage'; return canShow ? : ; } } diff --git a/src/routesConfiguration.js b/src/routesConfiguration.js index b675a90c..2dd3b39b 100644 --- a/src/routesConfiguration.js +++ b/src/routesConfiguration.js @@ -309,7 +309,7 @@ const routesConfiguration = [ { path: '/email_verification', auth: true, - preferLogin: true, + authPage: 'LoginPage', exact: true, name: 'EmailVerificationPage', component: props => ,