guideActions.js 1.28 KB
/**
 * # guideActions.js
 *
 * App user guide
 *
 */
'use strict';

/**
 * ## Imports
 *
 * The actions supported
 */
const {
    GET_GUIDE_DISPLAY,
    SET_GUIDE_DISPLAY
} = require('../../constants/actionTypes').default;


import {Actions} from 'react-native-router-flux';
import store from 'react-native-simple-store';
import CONFIG from '../../constants/config';

/**
 * ## check guide has displayed or not
 *
 */
export function getGuideDisplayState() {

    return (dispatch, getState) => {
        store.get(CONFIG.storeKey.GUIDE_STATE_KEY)
            .then((state) => {
                if (state && state.isDisplay) {
                    const {user} = getState();
                    if (user.getIn(['profile', 'sessionKey']) !== '') {
                        Actions.Drawer();
                    } else {
                        Actions.Login();
                    }
                } else {
                    Actions.Guide();
                }
            })
            .catch(error => {
                Actions.Guide();
            });
    };
}
/**
 * ## set guide has displayed
 *
 */
export function setGuideDisplayState() {

    store.save(CONFIG.storeKey.GUIDE_STATE_KEY, {isDisplay: true});

    Actions.Login();
    return {
        type: SET_GUIDE_DISPLAY,
        payload: true
    };


}