2016-03-17 18:08:03 +09:00
|
|
|
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
|
|
|
|
2016-03-17 18:08:03 +09:00
|
|
|
class Flash extends Component{
|
2016-02-23 13:10:08 +09:00
|
|
|
|
2016-03-27 17:30:28 +09:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.dismissFlash = this.dismissFlash.bind(this);
|
|
|
|
}
|
|
|
|
|
2016-02-23 13:10:08 +09:00
|
|
|
componentDidMount() {
|
2016-10-19 10:32:24 +02:00
|
|
|
this.props.markAsSeen(this.props.message._id);
|
2016-03-17 18:08:03 +09:00
|
|
|
}
|
2016-02-23 13:10:08 +09:00
|
|
|
|
2016-03-27 17:30:28 +09:00
|
|
|
dismissFlash(e) {
|
|
|
|
e.preventDefault();
|
2016-10-19 10:32:24 +02:00
|
|
|
this.props.clear(this.props.message._id);
|
2016-03-27 17:30:28 +09:00
|
|
|
}
|
|
|
|
|
2016-02-23 13:10:08 +09:00
|
|
|
render() {
|
2016-03-25 10:45:28 +09:00
|
|
|
|
2016-10-19 10:32:24 +02: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 (
|
2016-10-19 10:32:24 +02:00
|
|
|
<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-03-17 18:08:03 +09:00
|
|
|
}
|
2016-02-23 13:10:08 +09:00
|
|
|
|
2016-03-27 17:30:28 +09:00
|
|
|
Flash.propTypes = {
|
|
|
|
message: React.PropTypes.object.isRequired
|
|
|
|
}
|
|
|
|
|
2016-02-23 13:10:08 +09:00
|
|
|
module.exports = Flash;
|