diff options
| author | gabrhr <[email protected]> | 2022-04-20 10:19:29 -0500 |
|---|---|---|
| committer | gabrhr <[email protected]> | 2022-04-20 10:19:29 -0500 |
| commit | e13e630cd6e4fc0b1ff92098a28a770794c7bb9a (patch) | |
| tree | e68ad2f947d1b3ec454529b35f37ca2f223e5431 /front/odiparpack/app/redux/modules/calendar.js | |
| parent | 457816ac1129fcc6019d2fc795b6693ee6776d59 (diff) | |
| download | DP1_project-e13e630cd6e4fc0b1ff92098a28a770794c7bb9a.tar.gz DP1_project-e13e630cd6e4fc0b1ff92098a28a770794c7bb9a.tar.bz2 DP1_project-e13e630cd6e4fc0b1ff92098a28a770794c7bb9a.zip | |
AƱadir plantilla
Base para front
Diffstat (limited to 'front/odiparpack/app/redux/modules/calendar.js')
| -rw-r--r-- | front/odiparpack/app/redux/modules/calendar.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/front/odiparpack/app/redux/modules/calendar.js b/front/odiparpack/app/redux/modules/calendar.js new file mode 100644 index 0000000..fb1291d --- /dev/null +++ b/front/odiparpack/app/redux/modules/calendar.js @@ -0,0 +1,79 @@ +import { fromJS, List, Map } from 'immutable'; +import notif from 'ba-api/notifMessage'; +import { + FETCH_CALENDAR_DATA, + ADD_EVENT, + DISCARD_EVENT, + SUBMIT_EVENT, + DELETE_EVENT, + CLOSE_NOTIF +} from 'ba-actions/actionTypes'; + +const initialState = { + events: List([]), + openFrm: false, + formValues: Map(), + notifMsg: '', +}; + +const initForm = Map({ + title: '', + start: new Date(), + end: new Date(), + hexColor: 'F8BBD0', +}); + +const initialImmutableState = fromJS(initialState); +export default function reducer(state = initialImmutableState, action = {}) { + switch (action.type) { + case FETCH_CALENDAR_DATA: + return state.withMutations((mutableState) => { + const items = fromJS(action.items); + mutableState.set('events', items); + }); + case ADD_EVENT: + return state.withMutations((mutableState) => { + mutableState + .set('openFrm', true) + .set('formValues', initForm); + }); + case DISCARD_EVENT: + return state.withMutations((mutableState) => { + mutableState + .set('openFrm', false) + .set('formValues', Map()) + .set('notifMsg', notif.discard); + }); + case SUBMIT_EVENT: + return state.withMutations((mutableState) => { + const initItem = Map(action.newEvent); + const id = (+new Date() + Math.floor(Math.random() * 999999)).toString(36); + const newItem = initItem + .update('id', (val = id) => val) + .set('start', action.newEvent.get('start')._d || action.newEvent.get('start')) + .set('end', action.newEvent.get('end')._d || action.newEvent.get('end')); + mutableState.update('events', events => events.push(newItem)); + mutableState + .set('formValues', Map()) + .set('openFrm', false) + .set('notifMsg', notif.saved); + }); + case DELETE_EVENT: + return state.withMutations((mutableState) => { + const eventItem = state.get('events') + .find(obj => ( + obj.get('id') === action.event.id + )); + const index = state.get('events').indexOf(eventItem); + mutableState + .update('events', events => events.splice(index, 1)) + .set('notifMsg', notif.removed); + }); + case CLOSE_NOTIF: + return state.withMutations((mutableState) => { + mutableState.set('notifMsg', ''); + }); + default: + return state; + } +} |
