Vulcan/packages/vulcan-base-components/lib/common/Flash.jsx

39 lines
927 B
React
Raw Normal View History

2017-03-23 16:27:59 +09:00
import { registerComponent } from 'meteor/vulcan:core';
2017-05-19 14:42:43 -06:00
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
2017-06-02 07:19:39 +09:00
import Alert from 'react-bootstrap/lib/Alert'
2016-02-23 13:10:08 +09:00
2017-05-19 14:42:43 -06:00
class Flash extends PureComponent {
2016-02-23 13:10:08 +09:00
constructor() {
super();
this.dismissFlash = this.dismissFlash.bind(this);
}
2016-02-23 13:10:08 +09:00
componentDidMount() {
this.props.markAsSeen(this.props.message._id);
}
2016-02-23 13:10:08 +09:00
dismissFlash(e) {
e.preventDefault();
this.props.clear(this.props.message._id);
}
2016-02-23 13:10:08 +09:00
render() {
2016-03-25 10:45:28 +09:00
let flashType = this.props.message.flashType;
flashType = flashType === "error" ? "danger" : flashType; // if flashType is "error", use "danger" instead
2016-03-25 10:45:28 +09:00
2016-02-23 13:10:08 +09:00
return (
<Alert className="flash-message" bsStyle={flashType} onDismiss={this.dismissFlash}>
2016-03-25 10:45:28 +09:00
{this.props.message.content}
</Alert>
2016-02-23 13:10:08 +09:00
)
}
}
2016-02-23 13:10:08 +09:00
Flash.propTypes = {
2017-05-19 14:42:43 -06:00
message: PropTypes.object.isRequired
}
registerComponent('Flash', Flash);