diff --git a/src/components/Alert/index.js b/src/components/Alert/index.js
index 33f818e..07bb309 100644
--- a/src/components/Alert/index.js
+++ b/src/components/Alert/index.js
@@ -3,10 +3,11 @@
import React from "react";
import "./index.scss";
-import { infoAlert } from "../../redux/actions/modalActions";
+import { alert } from "../../redux/actions";
import { connect } from "react-redux";
function Alert(props) {
+ props.confirmAlert();
return (
@@ -244,10 +245,11 @@ function Alert(props) {
);
}
-const mapStateToProps = (state) => {
- return {};
-};
+const mapStateToProps = (state) => ({});
+const mapDispatchToProps = {
+ confirmAlert: alert.confirm,
+};
// export default Alert;
-export default connect(mapStateToProps, { customAlert: infoAlert })(Alert);
+export default connect(mapStateToProps, mapDispatchToProps)(Alert);
diff --git a/src/redux/actions/alert.js b/src/redux/actions/alert.js
new file mode 100644
index 0000000..ac798b8
--- /dev/null
+++ b/src/redux/actions/alert.js
@@ -0,0 +1,12 @@
+const alert = {
+ toast:
+ (data = {}) =>
+ async (dispatch) =>
+ await dispatch({ type: "alert/toast", data }),
+ confirm:
+ (data = {}) =>
+ async (dispatch) =>
+ await dispatch({ type: "alert/confirm", data }),
+};
+
+export default alert;
diff --git a/src/redux/actions/index.js b/src/redux/actions/index.js
index fd4740a..b471741 100644
--- a/src/redux/actions/index.js
+++ b/src/redux/actions/index.js
@@ -1 +1,2 @@
export { default as components } from "./components";
+export { default as alert } from "./alert";
diff --git a/src/redux/actions/modalActions.js b/src/redux/actions/modalActions.js
deleted file mode 100644
index 544b87d..0000000
--- a/src/redux/actions/modalActions.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import { INFO_ALERT, TOAST_ALERT } from "./types";
-
-export const infoAlert = (data) => (dispatch) => {
- dispatch({
- type: INFO_ALERT,
- data: data,
- });
-};
-
-export const toastAlert = (data) => (dispatch) => {
- dispatch({
- type: TOAST_ALERT,
- data: data,
- });
-};
diff --git a/src/redux/actions/types.js b/src/redux/actions/types.js
deleted file mode 100644
index 9e388f9..0000000
--- a/src/redux/actions/types.js
+++ /dev/null
@@ -1,2 +0,0 @@
-export const INFO_ALERT = "INFO_ALERT";
-export const TOAST_ALERT = "TOAST_ALERT";
diff --git a/src/redux/reducers/modalReducer.js b/src/redux/reducers/alert.js
similarity index 62%
rename from src/redux/reducers/modalReducer.js
rename to src/redux/reducers/alert.js
index 6f685bb..158660d 100644
--- a/src/redux/reducers/modalReducer.js
+++ b/src/redux/reducers/alert.js
@@ -1,12 +1,11 @@
-import { INFO_ALERT } from "../actions/types";
import Swal from "sweetalert2";
const initialState = {};
-const modalReducer = (state = initialState, action) => {
+const alert = (state = initialState, action) => {
const { type, data } = action;
switch (type) {
- case INFO_ALERT:
+ case "alert/confirm":
Swal.fire({
icon: data.icon,
title: data.title,
@@ -36,9 +35,29 @@ const modalReducer = (state = initialState, action) => {
return {
...state,
};
+ case "alert.toast":
+ Swal.fire({
+ icon: data.icon,
+ title: data.title,
+ showCloseButton: data.showCloseButton,
+ toast: data.toast,
+ position: data.position,
+ showConfirmButton: data.showConfirmButton,
+ timer: data.timer,
+ timerProgressBar: data.timerProgressBar,
+ customClass: {
+ title: data.customClass.title,
+ closeButton: data.customClass.closeButton,
+ popup: data.customClass.popup,
+ footer: data.customClass.footer,
+ },
+ });
+ return {
+ ...state,
+ };
default:
return state;
}
};
-export default modalReducer;
+export default alert;
diff --git a/src/redux/reducers/index.js b/src/redux/reducers/index.js
index fd4740a..b471741 100644
--- a/src/redux/reducers/index.js
+++ b/src/redux/reducers/index.js
@@ -1 +1,2 @@
export { default as components } from "./components";
+export { default as alert } from "./alert";
diff --git a/src/redux/reducers/rootReducer.js b/src/redux/reducers/rootReducer.js
deleted file mode 100644
index 4e1f863..0000000
--- a/src/redux/reducers/rootReducer.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import modalReducer from "./modalReducer";
-import toastReducer from "./toastReducer";
-import { combineReducers } from "redux";
-
-const rootReducer = combineReducers({
- modalReducer: modalReducer,
- toastReducer: toastReducer,
-});
-
-export default rootReducer;
diff --git a/src/redux/reducers/toastReducer.js b/src/redux/reducers/toastReducer.js
deleted file mode 100644
index f4fd787..0000000
--- a/src/redux/reducers/toastReducer.js
+++ /dev/null
@@ -1,34 +0,0 @@
-import { INFO_ALERT, TOAST_ALERT } from "../actions/types";
-import Swal from "sweetalert2";
-
-const initialState = {};
-
-const toastReducer = (state = initialState, action) => {
- const { type, data } = action;
- switch (type) {
- case TOAST_ALERT:
- Swal.fire({
- icon: data.icon,
- title: data.title,
- showCloseButton: data.showCloseButton,
- toast: data.toast,
- position: data.position,
- showConfirmButton: data.showConfirmButton,
- timer: data.timer,
- timerProgressBar: data.timerProgressBar,
- customClass: {
- title: data.customClass.title,
- closeButton: data.customClass.closeButton,
- popup: data.customClass.popup,
- footer: data.customClass.footer,
- },
- });
- return {
- ...state,
- };
- default:
- return state;
- }
-};
-
-export default toastReducer;
diff --git a/src/redux/store.js b/src/redux/store.js
index d909d05..bd9c2ff 100644
--- a/src/redux/store.js
+++ b/src/redux/store.js
@@ -3,15 +3,19 @@ import { composeWithDevTools } from "redux-devtools-extension";
import thunk from "redux-thunk";
import * as reducers from "./reducers";
-import { persistStore, persistReducer } from "redux-persist";
-import storage from "redux-persist/lib/storage"; // defaults to localStorage for web
+// import { persistStore, persistReducer } from "redux-persist";
+// import storage from "redux-persist/lib/storage"; // defaults to localStorage for web
const initialState = {};
const middleware = [thunk];
+// const persistConfig = {
+// key: "root",
+// storage,
+// };
+
const store = createStore(
combineReducers(reducers),
- applyMiddleware(thunk),
initialState,
composeWithDevTools(applyMiddleware(...middleware))
);