import React, { useState } from "react";
import { Dimensions } from "react-native";
import { connect } from "react-redux";
import AwesomeAlert from "react-native-awesome-alerts";
//style
import Colors from "../constants/Colors";
//variables
const { width } = Dimensions.get("window");
const AlertModal = (props) => {
const [alert, setAlert] = useState({
show: false,
showProgress: false,
title: "خطا",
message: "خطای ناشناخته",
closeOnTouchOutside: false,
closeOnHardwareBackPress: false,
showCancelButton: true,
showConfirmButton: true,
cancelText: "بیخیال",
confirmText: "باشه",
confirmButtonColor: "#2980b9",
onCancel: () => {},
onConfirm: () => {},
});
const [apiAlert, setApiAlert] = useState({
show: false,
showProgress: false,
title: "خطا",
message: "خطای ناشناخته",
closeOnTouchOutside: false,
closeOnHardwareBackPress: false,
showCancelButton: true,
showConfirmButton: true,
cancelText: "بیخیال",
confirmText: "باشه",
confirmButtonColor: "#2980b9",
onCancel: () => {},
onConfirm: () => {},
});
global.globalAlert = (params) => {
setAlert({
...alert,
...params,
});
};
global.globalApiAlert = (params) => {
setApiAlert({
...apiAlert,
...params,
});
};
function hideAlert() {
setAlert({ ...alert, show: false });
}
function onApiCancelPressed() {
globalApiAlert({ show: false });
apiAlert.onCancel();
}
function onApiConfirmPressed() {
globalApiAlert({ show: false });
apiAlert.onConfirm();
}
function onCancelPressed() {
hideAlert();
alert.onCancel();
}
function onConfirmPressed() {
hideAlert();
alert.onConfirm();
}
return (
<>
>
);
};
const mapStateToProps = (state) => ({
theme: state.publicApi.theme,
});
export default connect(mapStateToProps)(AlertModal);