From 4c3fc343d51b9c27d3ebab71df648bcf7d7bae59 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 31 Jan 2020 10:26:52 +0100 Subject: [PATCH] Client - empty user data on logout --- fittrackee_client/src/reducers/index.js | 34 +++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/fittrackee_client/src/reducers/index.js b/fittrackee_client/src/reducers/index.js index 5d609a19..41c69938 100644 --- a/fittrackee_client/src/reducers/index.js +++ b/fittrackee_client/src/reducers/index.js @@ -18,6 +18,8 @@ const handleDataAndError = (state, type, action) => { const activities = (state = initial.activities, action) => { switch (action.type) { + case 'LOGOUT': + return initial.activities case 'PUSH_ACTIVITIES': return { ...state, @@ -34,13 +36,17 @@ const activities = (state = initial.activities, action) => { } const calendarActivities = (state = initial.calendarActivities, action) => { - if (action.type === 'UPDATE_CALENDAR') { - return { - ...state, - data: action.activities, - } + switch (action.type) { + case 'LOGOUT': + return initial.calendarActivities + case 'UPDATE_CALENDAR': + return { + ...state, + data: action.activities, + } + default: + return handleDataAndError(state, 'calendarActivities', action) } - return handleDataAndError(state, 'calendarActivities', action) } const chartData = (state = initial.chartData, action) => { @@ -102,8 +108,12 @@ const messages = (state = initial.messages, action) => { } } -const records = (state = initial.records, action) => - handleDataAndError(state, 'records', action) +const records = (state = initial.records, action) => { + if (action.type === 'LOGOUT') { + return initial.records + } + return handleDataAndError(state, 'records', action) +} const sports = (state = initial.sports, action) => handleDataAndError(state, 'sports', action) @@ -122,8 +132,12 @@ const user = (state = initial.user, action) => { } } -const statistics = (state = initial.statistics, action) => - handleDataAndError(state, 'statistics', action) +const statistics = (state = initial.statistics, action) => { + if (action.type === 'LOGOUT') { + return initial.statistics + } + return handleDataAndError(state, 'statistics', action) +} export default history => combineReducers({