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:
Patrick Fic
2020-02-24 12:18:54 -08:00
parent 31e0a1f081
commit c21f3c0098
13 changed files with 383 additions and 190 deletions

View 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
});

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

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

View File

@@ -0,0 +1,9 @@
import { createSelector } from "reselect";
const selectModals = state => state.modals;
export const selectJobLineEditModal = createSelector(
[selectModals],
modals => modals.jobLineEdit
);

View File

@@ -0,0 +1,5 @@
const ModalActionTypes = {
TOGGLE_MODAL_VISIBLE: "TOGGLE_MODAL_VISIBLE",
SET_MODAL_CONTEXT: "SET_JOBLINEEDIT_CONTEXT"
};
export default ModalActionTypes;

View File

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

View File

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