36 lines
831 B
JavaScript

import React from "react";
import PropTypes from "prop-types";
import SweetAlert from "react-bootstrap-sweetalert";
import { connect } from "react-redux";
import { dismissAlert } from "../../actions/alerts";
const mapStateToProps = state => ({
show: state.alerts.get("show"),
title: state.alerts.get("message"),
type: state.alerts.get("type")
});
const mapDispatchToProps = { dismissAlert };
const Alert = props => {
if (!props.show) {
return null;
}
return (
<SweetAlert
type={props.type}
title={props.title}
onConfirm={props.dismissAlert}
/>
);
};
Alert.propTypes = {
show: PropTypes.bool.isRequired,
title: PropTypes.string.isRequired,
dismissAlert: PropTypes.func.isRequired,
type: PropTypes.string
};
export default connect(mapStateToProps, mapDispatchToProps)(Alert);