feat: add wallet

This commit is contained in:
Hasta Ragil Saputra
2019-01-06 18:21:08 +07:00
parent 21c56ad40f
commit 76eb551deb
6 changed files with 83 additions and 23 deletions

View File

@@ -58,6 +58,7 @@ import Odoo from './odoo';
import Vouchers from './vouchers';
import {PurchasedItemStore} from "./purchased_item";
import WalletStore from "./wallet";
export default class AppState {
http = new Http(this.token);
@@ -117,6 +118,8 @@ export default class AppState {
tags = new Tags(this);
surf_turf = new Surf(this);
purchased_items = new PurchasedItemStore(this);
wallet = new WalletStore(this);
constructor(initialState) {
this.token = initialState.token;
@@ -129,6 +132,9 @@ export default class AppState {
this.user.getUserGeolocation();
}
}
if(this.token) {
this.loadDataAfterLogin();
}
}
@action
@@ -153,8 +159,13 @@ export default class AppState {
this.items.push(item);
}
@action
loadDataAfterLogin() {
this.wallet.getData();
}
@computed get userData() {
const token = localStorage.getItem('id_token');
const token = this.token;
if (!token) {
return {
user_id: '',

View File

@@ -51,6 +51,7 @@ export class Authentication {
.then(res => {
this.isLoggingIn = false;
this.context.setToken(res.token);
this.context.loadDataAfterLogin();
})
.catch(err => {
this.isLoggingIn = false;
@@ -96,7 +97,7 @@ export class Authentication {
// .catch(err => {
// throw err;
// })
}
@action

View File

@@ -0,0 +1,28 @@
import { observable, action, computed } from 'mobx';
export default class WalletStore {
@observable isLoading = false;
@observable data = {
wallet: 1,
point: 1
};
constructor(context) {
this.context = context;
this.http = context.http;
}
@action
getData() {
this.isLoading = true;
return this.http.get("wallet")
.then(res => {
this.isLoading = false;
this.data = res;
return res;
})
.catch(err => {
this.isLoading = false;
throw err;
})
}
}