File size: 2,049 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
// @flow
import * as React from 'react';
import compose from 'recompose/compose';
import { connect } from 'react-redux';
import type { Dispatch } from 'redux';
import { Span, ProBadge, BlockedBadge, PendingBadge, TeamBadge } from './style';
import { withCurrentUser } from 'src/components/withCurrentUser';
import Tooltip from 'src/components/tooltip';
type Props = {
type: string,
label?: string,
onClick?: Function,
tipText: string,
currentUser: ?Object,
dispatch: Dispatch<Object>,
};
class Badge extends React.Component<Props> {
render() {
const { type, label, ...rest } = this.props;
switch (type) {
case 'beta-supporter':
return (
<Tooltip content={'Beta Supporter'}>
<ProBadge type={type} {...rest}>
{label || 'Supporter'}
</ProBadge>
</Tooltip>
);
case 'blocked':
return (
<Tooltip content={this.props.tipText}>
<BlockedBadge type={type} {...rest}>
{label || type}
</BlockedBadge>
</Tooltip>
);
case 'pending':
return (
<Tooltip content={this.props.tipText}>
<PendingBadge type={type} {...rest}>
{label || type}
</PendingBadge>
</Tooltip>
);
case 'moderator':
case 'admin':
return (
<Tooltip
content={`${
type === 'moderator' ? 'Moderator' : 'Owner'
} of this community`}
>
<TeamBadge type={type} {...rest}>
Team
</TeamBadge>
</Tooltip>
);
default:
return (
<Tooltip content={this.props.tipText || label || ''}>
<Span
type={type}
onClick={this.props.onClick && this.props.onClick}
{...rest}
>
{label || type}
</Span>
</Tooltip>
);
}
}
}
export default compose(
withCurrentUser,
connect()
)(Badge);
|