2017-08-22 21:49:50 +03:00
|
|
|
import React, { Component } from 'react';
|
2017-05-25 22:11:57 +03:00
|
|
|
import { Link } from 'react-router-dom';
|
2016-01-04 08:02:13 +02:00
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
2019-12-07 21:02:00 +02:00
|
|
|
import { Account } from 'app/components/accounts/reducer';
|
|
|
|
import buttons from 'app/components/ui/buttons.scss';
|
2016-01-04 08:02:13 +02:00
|
|
|
|
2016-05-22 11:06:21 +03:00
|
|
|
import messages from './Userbar.intl.json';
|
2016-01-04 08:02:13 +02:00
|
|
|
import styles from './userbar.scss';
|
2016-03-02 00:01:56 +03:00
|
|
|
import LoggedInPanel from './LoggedInPanel';
|
|
|
|
|
2018-02-27 23:17:31 +02:00
|
|
|
export default class Userbar extends Component<{
|
2019-12-07 13:28:52 +02:00
|
|
|
account: Account | null;
|
|
|
|
guestAction: 'register' | 'login';
|
2018-02-27 23:17:31 +02:00
|
|
|
}> {
|
2019-11-27 11:03:32 +02:00
|
|
|
static displayName = 'Userbar';
|
2016-06-05 13:31:17 +03:00
|
|
|
|
2019-11-27 11:03:32 +02:00
|
|
|
static defaultProps = {
|
|
|
|
guestAction: 'register',
|
|
|
|
};
|
2016-02-13 17:28:47 +02:00
|
|
|
|
2019-11-27 11:03:32 +02:00
|
|
|
render() {
|
2019-12-07 13:28:52 +02:00
|
|
|
const { account, guestAction: actionType } = this.props;
|
2016-06-05 13:31:17 +03:00
|
|
|
|
2019-12-07 13:28:52 +02:00
|
|
|
let guestAction: React.ReactElement;
|
|
|
|
|
|
|
|
switch (actionType) {
|
2019-11-27 11:03:32 +02:00
|
|
|
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>
|
2016-01-04 08:02:13 +02:00
|
|
|
);
|
2019-11-27 11:03:32 +02:00
|
|
|
break;
|
2016-01-04 08:02:13 +02:00
|
|
|
}
|
2019-11-27 11:03:32 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.userbar}>
|
|
|
|
{account ? <LoggedInPanel username={account.username} /> : guestAction}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-01-04 08:02:13 +02:00
|
|
|
}
|