Last active
October 7, 2015 17:44
-
-
Save guilhermemmb/01900da334601fa7411d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import flux from '../flux'; | |
| import Fetcher from 'utils/Fetcher'; | |
| import AuthenticationHelper from 'utils/AuthenticationHelper'; | |
| class VtexActions { | |
| checkLogin() { | |
| Fetcher.checkVtexIdAuth().then((userData) => { | |
| Fetcher.getProfileSystemData('omniera', userData.user).then((response) => { | |
| const data = { | |
| user: userData, | |
| store: response | |
| }; | |
| this.actions.VtexIdAuthSuccess(data); | |
| }, (err) => { | |
| console.log('error on get user profile data', err); | |
| AuthenticationHelper.login(this.actions.checkLogin); | |
| }); | |
| }, (err) => { | |
| console.log('error on check user auth', err); | |
| AuthenticationHelper.login(this.actions.checkLogin); | |
| }); | |
| } | |
| VtexIdAuthSuccess(data){ | |
| data.logged = true; | |
| this.dispatch(data); | |
| } | |
| VtexIdAuthFail(error){ | |
| this.dispatch(error); | |
| } | |
| getStoreInfo(storeId) { | |
| let promise = new Promise((resolve, reject) => { | |
| if(!storeId) { | |
| const reason = 'storeId is undefined. We\'ll use default trade policy'; | |
| this.actions.GetStoreInfoFail({message: reason}); | |
| reject(reason); | |
| } | |
| Fetcher.getStoreData('omniera', storeId).then((response) => { | |
| this.actions.GetStoreInfoSuccess(response); | |
| resolve(response); | |
| }).catch((err) => { | |
| const reason = 'Fail on get trade policy. We\'ll use default trade policy'; | |
| this.actions.GetStoreInfoFail({message: reason}); | |
| reject(reason); | |
| }); | |
| }); | |
| return promise; | |
| } | |
| GetStoreInfoSuccess(data){ | |
| this.dispatch(data); | |
| } | |
| GetStoreInfoFail(error){ | |
| console.log(error.message); | |
| this.dispatch(error); | |
| } | |
| } | |
| export default flux.createActions(VtexActions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment