%PDF- %PDF-
Direktori : /home/emergentqj/actioncivile/pre-auth/.632e77b3fb93bc8da5b589b869bc0037/static/js/components/ |
Current File : /home/emergentqj/actioncivile/pre-auth/.632e77b3fb93bc8da5b589b869bc0037/static/js/components/Alert.js |
import React from "react"; import PropTypes from "prop-types"; import Swal from "sweetalert2"; import { connect } from "react-redux"; import { hideAlert } from "actions/list_actions"; function Alert({ icon, show, title, text, showCancelButton, confirmButtonText, cancelButtonText, hideAlertFunc, didClose, }) { if (show) { const sweetAlertConfiguration = { title, text, icon, confirmButtonText, showCancelButton, cancelButtonText, didClose, }; Swal.fire(sweetAlertConfiguration).then(() => hideAlertFunc()); } return <div />; } Alert.propTypes = { cancelButtonText: PropTypes.string, confirmButtonText: PropTypes.string, didClose: PropTypes.func, hideAlertFunc: PropTypes.func.isRequired, icon: PropTypes.oneOf(["warning", "error", "success", "info", "question"]), show: PropTypes.bool.isRequired, showCancelButton: PropTypes.bool, text: PropTypes.string, title: PropTypes.string, }; Alert.defaultProps = { cancelButtonText: "Cancel", confirmButtonText: "OK", didClose: () => {}, icon: "error", showCancelButton: false, text: "", title: "", }; const mapStateToProps = (state) => ({ cancelButtonText: state.alert.cancelButtonText, confirmButtonText: state.alert.confirmButtonText, didClose: state.alert.didClose, icon: state.alert.icon, show: state.alert.show, showCancelButton: state.alert.showCancelButton, text: state.alert.text, title: state.alert.title, }); const mapDispatchToProps = (dispatch) => ({ hideAlertFunc: () => { dispatch(hideAlert()); }, }); export default connect(mapStateToProps, mapDispatchToProps)(Alert);