applicationConfig.ts 1.58 KB
Newer Older
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
1
import update from 'immutability-helper';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
2
import {CONFIGURE_APPLICATION, SET_LANG} from 'constants/applicationConfig';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
3
import { LOGIN_APP, LOGIN_USER } from 'constants/login';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
4 5 6


const INITIAL_STATE: {
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
7 8 9
    frontendUrl: string;
    frontendPath: string;
    apiUrl: string;
10
    clientId: string;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
11
    googleClientId: string;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
12
    lang: string,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
13
    anonToken: any,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
14
} = {
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
15
    frontendUrl: 'http://localhost:3000',
16
    frontendPath: '',
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
17 18 19
    apiUrl: process.env.CATALOG_API_URL || 'http://localhost:8080',
    clientId: process.env.CLIENT_ID || 'defaultclient@localhost', // TODO check if '' is required here
    googleClientId: process.env.GOOGLE_CLIENT_ID || '',
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
20
    lang: 'en',
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
21
    anonToken: null,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
22 23 24 25 26 27 28 29 30 31
};

export default function configure(state = INITIAL_STATE, action: { type?: string, payload?: any } = {type: '', payload: {}}) {

    switch (action.type) {
        case CONFIGURE_APPLICATION: {
            return update(state, {
                $set: action.payload,
            });
        }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
32 33 34 35 36
        case SET_LANG: {
            return update(state, {
                lang: {$set:  action.payload},
            });
        }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50
        case LOGIN_USER: {
            const access_token = {...action};
            delete access_token.type;
            return update(state, {
                anonToken: {$set: access_token},
            });
        }
        case LOGIN_APP: {
            const access_token = {...action};
            delete access_token.type;
            return update(state, {
                anonToken: {$set: access_token},
            });
        }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
51 52 53 54 55

        default:
            return state;
    }
}