aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/ducks/ui/header.js
blob: 25dfe6027c6e1e0c941e88d600928cc536437d50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import * as flowsActions from '../flows'

export const SET_ACTIVE_MENU = 'UI_SET_ACTIVE_MENU'


const defaultState = {
    activeMenu: 'Start',
    isFlowSelected: false,
}

export default function reducer(state = defaultState, action) {
    switch (action.type) {

        case SET_ACTIVE_MENU:
            return {
                ...state,
                activeMenu: action.activeMenu,
            }

        case flowsActions.SELECT:
            // First Select
            if (action.flowIds.length && !state.isFlowSelected) {
                return {
                    ...state,
                    activeMenu: 'Flow',
                    isFlowSelected: true,
                }
            }

            // Deselect
            if (!action.flowIds.length && state.isFlowSelected) {
                let activeMenu = state.activeMenu
                if (activeMenu == 'Flow') {
                    activeMenu = 'Start'
                }
                return {
                    ...state,
                    activeMenu,
                    isFlowSelected: false,
                }
            }
            return state
        default:
            return state
    }
}

export function setActiveMenu(activeMenu) {
    return { type: SET_ACTIVE_MENU, activeMenu }
}