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

38 lines
891 B
React
Raw Normal View History

import { registerComponent } from 'meteor/nova:lib';
import React, { PropTypes, Component } from 'react';
2016-03-25 10:45:28 +09:00
import { Alert } from 'react-bootstrap';
2016-02-23 13:10:08 +09:00
class Flash extends Component{
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 = {
message: React.PropTypes.object.isRequired
}
registerComponent('Flash', Flash);