2016-06-05 16:01:17 +05:30
|
|
|
import React, { Component, PropTypes } from 'react';
|
2016-01-04 11:32:13 +05:30
|
|
|
|
2017-05-26 00:41:57 +05:30
|
|
|
import { Link } from 'react-router-dom';
|
2016-01-04 11:32:13 +05:30
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
|
|
|
|
|
|
|
import buttons from 'components/ui/buttons.scss';
|
|
|
|
|
2016-05-22 13:36:21 +05:30
|
|
|
import messages from './Userbar.intl.json';
|
2016-01-04 11:32:13 +05:30
|
|
|
import styles from './userbar.scss';
|
|
|
|
|
2016-02-13 20:58:47 +05:30
|
|
|
import { userShape } from 'components/user/User';
|
|
|
|
|
2016-03-02 02:31:56 +05:30
|
|
|
import LoggedInPanel from './LoggedInPanel';
|
|
|
|
|
2016-01-04 11:32:13 +05:30
|
|
|
export default class Userbar extends Component {
|
2016-02-13 20:58:47 +05:30
|
|
|
static displayName = 'Userbar';
|
|
|
|
static propTypes = {
|
2016-06-05 16:01:17 +05:30
|
|
|
user: userShape,
|
|
|
|
guestAction: PropTypes.oneOf(['register', 'login'])
|
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
guestAction: 'register'
|
2016-02-13 20:58:47 +05:30
|
|
|
};
|
|
|
|
|
2016-01-04 11:32:13 +05:30
|
|
|
render() {
|
2016-02-13 20:58:47 +05:30
|
|
|
const { user } = this.props;
|
2016-06-05 16:01:17 +05:30
|
|
|
let { guestAction } = this.props;
|
|
|
|
|
|
|
|
switch (guestAction) {
|
|
|
|
case 'login':
|
|
|
|
guestAction = (
|
|
|
|
<Link to="/login" className={buttons.blue}>
|
|
|
|
<Message {...messages.login} />
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'register':
|
|
|
|
default:
|
|
|
|
guestAction = (
|
|
|
|
<Link to="/register" className={buttons.blue}>
|
|
|
|
<Message {...messages.register} />
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2016-02-13 20:58:47 +05:30
|
|
|
|
2016-01-04 11:32:13 +05:30
|
|
|
return (
|
|
|
|
<div className={styles.userbar}>
|
2016-02-13 20:58:47 +05:30
|
|
|
{user.isGuest
|
|
|
|
? (
|
2016-06-05 16:01:17 +05:30
|
|
|
guestAction
|
2016-02-13 20:58:47 +05:30
|
|
|
)
|
|
|
|
: (
|
2016-03-02 02:31:56 +05:30
|
|
|
<LoggedInPanel {...this.props} />
|
2016-02-13 20:58:47 +05:30
|
|
|
)
|
|
|
|
}
|
2016-01-04 11:32:13 +05:30
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|