ES6 Plato on Github
Report Home
Summary Display
components/UserMessage.js
Maintainability
61.74
Lines of code
46
Difficulty
21.67
Estimated Errors
0.26
Function weight
By Complexity
By SLOC
import React from 'react'; import PropTypes from 'prop-types'; import { INFO_MESSAGE_TYPE, SUCCESS_MESSAGE_TYPE, ERROR_MESSAGE_TYPE } from '../constants/UserMessages'; import { Alert } from 'react-bootstrap'; /* React component which displays a message to the user */ class UserMessage extends React.Component { render() { const { type, message, isTextCentered } = this.props; function getStyle(isTextCentered) { if (isTextCentered) { return { textAlign: 'center', borderRadius: '25px' }; } else { return { textAlign: 'left', borderRadius: '25px' }; } } if (type && message && message !== '') { if (type === INFO_MESSAGE_TYPE) { return (<Alert bsStyle='info' style={getStyle(isTextCentered)} > {message} </Alert>); } if (type === SUCCESS_MESSAGE_TYPE) { return ( <Alert bsStyle='success' style={getStyle(isTextCentered)} > {message} </Alert>); } if (type === ERROR_MESSAGE_TYPE) { return ( <Alert bsStyle='danger' style={getStyle(isTextCentered)} > {message} </Alert>); } } else { return null; } } } UserMessage.propTypes = { /** the error message itself */ message: PropTypes.string.isRequired, /* the type of the message */ type: PropTypes.string.isRequired, /* whether the text is centered. TRUE when the text is centered. FALSE or NO VALUE aligns the text on the left */ isTextCentered: PropTypes.bool }; export default UserMessage;