Refactored job line edit modal to use redux so that it can be an independent form. Created general modals reducer to manage all modals.
This commit is contained in:
12
client/src/redux/modals/modals.actions.js
Normal file
12
client/src/redux/modals/modals.actions.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import ModalsActionTypes from "./modals.types";
|
||||
|
||||
export const toggleModalVisible = modalName => ({
|
||||
type: ModalsActionTypes.TOGGLE_MODAL_VISIBLE,
|
||||
payload: modalName
|
||||
});
|
||||
|
||||
//Modal Context: {context (context object), modal(name of modal)}
|
||||
export const setModalContext = modalContext => ({
|
||||
type: ModalsActionTypes.SET_MODAL_CONTEXT,
|
||||
payload: modalContext
|
||||
});
|
||||
37
client/src/redux/modals/modals.reducer.js
Normal file
37
client/src/redux/modals/modals.reducer.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import ModalsActionTypes from "./modals.types";
|
||||
|
||||
const INITIAL_STATE = {
|
||||
jobLineEdit: {
|
||||
visible: false,
|
||||
context: null,
|
||||
actions: {
|
||||
refetch: null
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const modalsReducer = (state = INITIAL_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case ModalsActionTypes.TOGGLE_MODAL_VISIBLE:
|
||||
return {
|
||||
...state,
|
||||
[action.payload]: {
|
||||
...state[action.payload],
|
||||
visible: !state[action.payload].visible
|
||||
}
|
||||
};
|
||||
case ModalsActionTypes.SET_MODAL_CONTEXT:
|
||||
return {
|
||||
...state,
|
||||
[action.payload.modal]: {
|
||||
...state[action.payload.modal],
|
||||
...action.payload.context,
|
||||
visible: true
|
||||
}
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default modalsReducer;
|
||||
24
client/src/redux/modals/modals.sagas.js
Normal file
24
client/src/redux/modals/modals.sagas.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { all } from "redux-saga/effects";
|
||||
|
||||
// export function* onSendEmail() {
|
||||
// yield takeLatest(EmailActionTypes.SEND_EMAIL, sendEmail);
|
||||
// }
|
||||
// export function* sendEmail(payload) {
|
||||
// try {
|
||||
// console.log("Sending thta email", payload);
|
||||
// axios.post("/sendemail", payload).then(response => {
|
||||
// console.log(JSON.stringify(response));
|
||||
// put(sendEmailSuccess());
|
||||
// });
|
||||
// } catch (error) {
|
||||
// console.log("Error in sendEmail saga.");
|
||||
// yield put(sendEmailFailure(error.message));
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
export function* modalsSagas() {
|
||||
yield all([
|
||||
//call(onSendEmail),
|
||||
]);
|
||||
}
|
||||
9
client/src/redux/modals/modals.selectors.js
Normal file
9
client/src/redux/modals/modals.selectors.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import { createSelector } from "reselect";
|
||||
|
||||
const selectModals = state => state.modals;
|
||||
|
||||
export const selectJobLineEditModal = createSelector(
|
||||
[selectModals],
|
||||
modals => modals.jobLineEdit
|
||||
);
|
||||
|
||||
5
client/src/redux/modals/modals.types.js
Normal file
5
client/src/redux/modals/modals.types.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const ModalActionTypes = {
|
||||
TOGGLE_MODAL_VISIBLE: "TOGGLE_MODAL_VISIBLE",
|
||||
SET_MODAL_CONTEXT: "SET_JOBLINEEDIT_CONTEXT"
|
||||
};
|
||||
export default ModalActionTypes;
|
||||
@@ -5,18 +5,19 @@ import storage from "redux-persist/lib/storage";
|
||||
import userReducer from "./user/user.reducer";
|
||||
import messagingReducer from "./messaging/messaging.reducer";
|
||||
import emailReducer from "./email/email.reducer";
|
||||
|
||||
import modalsReducer from './modals/modals.reducer'
|
||||
const persistConfig = {
|
||||
key: "root",
|
||||
storage,
|
||||
//whitelist: ["user"]
|
||||
blacklist: ["user", "email", "messaging"]
|
||||
blacklist: ["user", "email", "messaging", "modals"]
|
||||
};
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
user: userReducer,
|
||||
messaging: messagingReducer,
|
||||
email: emailReducer
|
||||
email: emailReducer,
|
||||
modals: modalsReducer
|
||||
});
|
||||
|
||||
export default persistReducer(persistConfig, rootReducer);
|
||||
|
||||
@@ -3,6 +3,8 @@ import { all, call } from "redux-saga/effects";
|
||||
import { userSagas } from "./user/user.sagas";
|
||||
import { messagingSagas } from "./messaging/messaging.sagas";
|
||||
import { emailSagas } from "./email/email.sagas";
|
||||
import { modalsSagas } from "./modals/modals.sagas";
|
||||
export default function* rootSaga() {
|
||||
yield all([call(userSagas), call(messagingSagas), call(emailSagas)]);
|
||||
yield all([call(userSagas), call(messagingSagas), call(emailSagas),
|
||||
call(modalsSagas)]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user