From b240f38d661e6e11428e3f09258ba29bcbf228bb Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Fri, 25 Aug 2017 16:27:59 +0200 Subject: Clean timetable dates after updating day types --- .../es6_browserified/time_tables/reducers/timetable.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'app/assets/javascripts') diff --git a/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js b/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js index 64db1ccc1..84d90d53c 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js +++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js @@ -59,6 +59,17 @@ const timetable = (state = {}, action) => { }) newState = _.assign({}, state, {current_month: newCMe, time_table_dates: newDates}) return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.dayTypes)}) + case 'UPDATE_DAY_TYPES': + // We get the week days of the activated day types to reject the out_dates that that are out of newDayTypes + let weekDays = _.reduce(action.dayTypes, (array, dt, i) => { + if (dt) array.push(i) + return array + }, []) + + newDates = _.reject(state.time_table_dates, (d) => { + return d.in_out == false && !weekDays.includes(new Date(d.date).getDay()) + }) + return _.assign({}, state, {time_table_dates: newDates}) case 'UPDATE_CURRENT_MONTH_FROM_DAYTYPES': return _.assign({}, state, {current_month: actions.updateSynthesis(state, action.dayTypes)}) case 'VALIDATE_PERIOD_FORM': -- cgit v1.2.3