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:
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;
|
||||
Reference in New Issue
Block a user