%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/emergentqj/actioncivile/pre-auth/.f81b4c9eb38fd76cdf20462cf2027aa3/static/js/components/
Upload File :
Create Path :
Current File : /home/emergentqj/actioncivile/pre-auth/.f81b4c9eb38fd76cdf20462cf2027aa3/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);

Zerion Mini Shell 1.0