2018-09-14 15:37:35 +03:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-10-26 05:44:23 +03:00
|
|
|
import { Trans } from 'react-i18next';
|
2018-09-14 15:37:35 +03:00
|
|
|
|
|
|
|
class Toast extends Component {
|
|
|
|
componentDidMount() {
|
2018-09-14 16:43:27 +03:00
|
|
|
const timeout = this.props.type === 'error' ? 30000 : 5000;
|
2018-09-14 16:41:34 +03:00
|
|
|
|
2018-09-14 15:37:35 +03:00
|
|
|
setTimeout(() => {
|
|
|
|
this.props.removeToast(this.props.id);
|
2018-09-14 16:43:27 +03:00
|
|
|
}, timeout);
|
2018-09-14 15:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
shouldComponentUpdate() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className={`toast toast--${this.props.type}`}>
|
|
|
|
<p className="toast__content">
|
2018-10-26 05:44:23 +03:00
|
|
|
<Trans>{this.props.message}</Trans>
|
2018-09-14 15:37:35 +03:00
|
|
|
</p>
|
|
|
|
<button className="toast__dismiss" onClick={() => this.props.removeToast(this.props.id)}>
|
|
|
|
<svg stroke="#fff" fill="none" width="20" height="20" strokeWidth="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="m18 6-12 12"/><path d="m6 6 12 12"/></svg>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Toast.propTypes = {
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
message: PropTypes.string.isRequired,
|
|
|
|
type: PropTypes.string.isRequired,
|
|
|
|
removeToast: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Toast;
|