From e0ab116a9a5611248a4b6c6b95933b48e5e6b6a2 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sun, 5 Jun 2016 13:31:17 +0300 Subject: [PATCH] #135: switch register/login buttons in UserBar depending on current page --- src/components/userbar/Userbar.intl.json | 3 ++- src/components/userbar/Userbar.jsx | 32 ++++++++++++++++++++---- src/i18n/en.json | 1 + src/i18n/ru.json | 1 + src/pages/root/RootPage.jsx | 10 +++++++- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/components/userbar/Userbar.intl.json b/src/components/userbar/Userbar.intl.json index 83608e5..151421c 100644 --- a/src/components/userbar/Userbar.intl.json +++ b/src/components/userbar/Userbar.intl.json @@ -1,3 +1,4 @@ { - "register": "Join" + "register": "Join", + "login": "Sign in" } diff --git a/src/components/userbar/Userbar.jsx b/src/components/userbar/Userbar.jsx index 47db14e..60ebc90 100644 --- a/src/components/userbar/Userbar.jsx +++ b/src/components/userbar/Userbar.jsx @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import React, { Component, PropTypes } from 'react'; import { Link } from 'react-router'; import { FormattedMessage as Message } from 'react-intl'; @@ -15,19 +15,41 @@ import LoggedInPanel from './LoggedInPanel'; export default class Userbar extends Component { static displayName = 'Userbar'; static propTypes = { - user: userShape + user: userShape, + guestAction: PropTypes.oneOf(['register', 'login']) + }; + + static defaultProps = { + guestAction: 'register' }; render() { const { user } = this.props; + let { guestAction } = this.props; + + switch (guestAction) { + case 'login': + guestAction = ( + + + + ); + break; + case 'register': + default: + guestAction = ( + + + + ); + break; + } return (
{user.isGuest ? ( - - - + guestAction ) : ( diff --git a/src/i18n/en.json b/src/i18n/en.json index fb28eed..fc96fe2 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -114,6 +114,7 @@ "components.profile.preferencesDescription": "Here you can change the key preferences of your account. Please note that all actions must be confirmed by entering a password.", "components.profile.projectRules": "project rules", "components.profile.twoFactorAuth": "Two factor auth", + "components.userbar.login": "Sign in", "components.userbar.logout": "Logout", "components.userbar.register": "Join", "pages.root.siteName": "Ely.by", diff --git a/src/i18n/ru.json b/src/i18n/ru.json index ad75201..d1aff6b 100644 --- a/src/i18n/ru.json +++ b/src/i18n/ru.json @@ -114,6 +114,7 @@ "components.profile.preferencesDescription": "Здесь вы можете сменить ключевые параметры вашего аккаунта. Обратите внимание, что для всех действий необходимо подтверждение при помощи ввода пароля.", "components.profile.projectRules": "правилам проекта", "components.profile.twoFactorAuth": "Двухфакторная аутентификация", + "components.userbar.login": "Вход", "components.userbar.logout": "Выход", "components.userbar.register": "Регистрация", "pages.root.siteName": "Ely.by", diff --git a/src/pages/root/RootPage.jsx b/src/pages/root/RootPage.jsx index a530881..1b41179 100644 --- a/src/pages/root/RootPage.jsx +++ b/src/pages/root/RootPage.jsx @@ -12,6 +12,8 @@ import styles from './root.scss'; import messages from './RootPage.intl.json'; function RootPage(props) { + const isRegisterPage = props.location.pathname === '/register'; + return (
- +
@@ -38,6 +43,9 @@ function RootPage(props) { RootPage.displayName = 'RootPage'; RootPage.propTypes = { + location: PropTypes.shape({ + pathname: PropTypes.string + }).isRequired, children: PropTypes.element, logout: PropTypes.func.isRequired, isPopupActive: PropTypes.bool