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

40 lines
858 B
React
Raw Normal View History

import React, { PropTypes, Component } from 'react';
2016-03-25 10:45:28 +09:00
import { Alert } from 'react-bootstrap';
2016-02-25 17:44:43 +09:00
import Core from "meteor/nova:core";
const Messages = Core.Messages;
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() {
Messages.markAsSeen(this.props.message._id);
}
2016-02-23 13:10:08 +09:00
dismissFlash(e) {
e.preventDefault();
Messages.clear(this.props.message._id);
}
2016-02-23 13:10:08 +09:00
render() {
2016-03-25 10:45:28 +09:00
let type = this.props.message.type;
type = type === "error" ? "danger" : type; // if type is "error", use "danger" instead
2016-02-23 13:10:08 +09:00
return (
<Alert className="flash-message" bsStyle={type} 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
}
2016-02-23 13:10:08 +09:00
module.exports = Flash;