guideActions.js 1.46 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 => {
        store.get(CONFIG.storeKey.GUIDE_STATE_KEY)
            .then((state) => {
                if (state) {
                       store.get(CONFIG.storeKey.SESSION_TOKEN_KEY)
                        .then((state) => {
                            if (state) {
                                Actions.Drawer();
                            } else {
                                Actions.Login();
                            }
                        })
                        .catch(error => {
                            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
    };


}