import React from 'react'; import { Container } from 'react-bootstrap'; import Toast from 'react-bootstrap/Toast'; class Flash extends React.Component { constructor(props) { super(props); this.state = { messages: [], } this.seq = 0; } componentDidMount() { window.flash = this.flash.bind(this); } componentWillUnmount() { window.flash = null; } render() { if (this.state.messages.length === 0) { return ''; } let that = this; const messages = this.state.messages.map(function(message, index) { return that.remove(message.seq)} autohide={true} delay={(index+1)*3000}> {message.header || 'Inventory'} {message.text} ; }); return {messages} ; } remove(seq) { this.setState(function(state, props) { const messages = state.messages.filter((message) => message.seq !== seq); return { messages }; }); } flash(message) { message.seq = ++this.seq; this.setState(function(state, props) { const messages = [...state.messages, message]; return { messages }; }); } } export { Flash };