update 4 files and delete 5 files

master
mahdi 3 years ago
parent f0a4d8c9dd
commit ea74009e7d
  1. 12
      src/components/Alert/index.js
  2. 12
      src/redux/actions/alert.js
  3. 1
      src/redux/actions/index.js
  4. 15
      src/redux/actions/modalActions.js
  5. 2
      src/redux/actions/types.js
  6. 27
      src/redux/reducers/alert.js
  7. 1
      src/redux/reducers/index.js
  8. 10
      src/redux/reducers/rootReducer.js
  9. 34
      src/redux/reducers/toastReducer.js
  10. 10
      src/redux/store.js

@ -3,10 +3,11 @@
import React from "react"; import React from "react";
import "./index.scss"; import "./index.scss";
import { infoAlert } from "../../redux/actions/modalActions"; import { alert } from "../../redux/actions";
import { connect } from "react-redux"; import { connect } from "react-redux";
function Alert(props) { function Alert(props) {
props.confirmAlert();
return ( return (
<div className=""> <div className="">
<h2 className="mt-4 mx-7 bg-pink-600 rounded p-4 text-center text-white"> <h2 className="mt-4 mx-7 bg-pink-600 rounded p-4 text-center text-white">
@ -244,10 +245,11 @@ function Alert(props) {
); );
} }
const mapStateToProps = (state) => { const mapStateToProps = (state) => ({});
return {};
};
const mapDispatchToProps = {
confirmAlert: alert.confirm,
};
// export default Alert; // export default Alert;
export default connect(mapStateToProps, { customAlert: infoAlert })(Alert); export default connect(mapStateToProps, mapDispatchToProps)(Alert);

@ -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;

@ -1 +1,2 @@
export { default as components } from "./components"; export { default as components } from "./components";
export { default as alert } from "./alert";

@ -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,
});
};

@ -1,2 +0,0 @@
export const INFO_ALERT = "INFO_ALERT";
export const TOAST_ALERT = "TOAST_ALERT";

@ -1,12 +1,11 @@
import { INFO_ALERT } from "../actions/types";
import Swal from "sweetalert2"; import Swal from "sweetalert2";
const initialState = {}; const initialState = {};
const modalReducer = (state = initialState, action) => { const alert = (state = initialState, action) => {
const { type, data } = action; const { type, data } = action;
switch (type) { switch (type) {
case INFO_ALERT: case "alert/confirm":
Swal.fire({ Swal.fire({
icon: data.icon, icon: data.icon,
title: data.title, title: data.title,
@ -36,9 +35,29 @@ const modalReducer = (state = initialState, action) => {
return { return {
...state, ...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: default:
return state; return state;
} }
}; };
export default modalReducer; export default alert;

@ -1 +1,2 @@
export { default as components } from "./components"; export { default as components } from "./components";
export { default as alert } from "./alert";

@ -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;

@ -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;

@ -3,15 +3,19 @@ import { composeWithDevTools } from "redux-devtools-extension";
import thunk from "redux-thunk"; import thunk from "redux-thunk";
import * as reducers from "./reducers"; import * as reducers from "./reducers";
import { persistStore, persistReducer } from "redux-persist"; // import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage"; // defaults to localStorage for web // import storage from "redux-persist/lib/storage"; // defaults to localStorage for web
const initialState = {}; const initialState = {};
const middleware = [thunk]; const middleware = [thunk];
// const persistConfig = {
// key: "root",
// storage,
// };
const store = createStore( const store = createStore(
combineReducers(reducers), combineReducers(reducers),
applyMiddleware(thunk),
initialState, initialState,
composeWithDevTools(applyMiddleware(...middleware)) composeWithDevTools(applyMiddleware(...middleware))
); );

Loading…
Cancel
Save