From f1fdbbd6e61131729c8c2ca8c96dd76e6619d271 Mon Sep 17 00:00:00 2001 From: enggar_ganteng Date: Sun, 6 Jan 2019 00:33:30 +0700 Subject: [PATCH] config --- src/common/config/app.js | 8 ++- src/common/pages/Vouchers/index.js | 3 + src/common/stores/appstate.js | 2 + src/common/stores/vouchers.js | 101 +++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 src/common/stores/vouchers.js diff --git a/src/common/config/app.js b/src/common/config/app.js index 8fbdbde..35d4072 100644 --- a/src/common/config/app.js +++ b/src/common/config/app.js @@ -21,8 +21,12 @@ let type = 'akuntiket'; // apiUrl = "https://marketplace-sillyfish-staging-api.asacreative.com/v1/"; // imageUrl = "https://marketplace-sillyfish-staging-api.asacreative.com"; -apiUrl = "https://marketplace-sillyfish-api.asacreative.com/v1/"; -imageUrl = "https://marketplace-sillyfish-api.asacreative.com"; +// apiUrl = "https://marketplace-sillyfish-api.asacreative.com/v1/"; +// imageUrl = "https://marketplace-sillyfish-api.asacreative.com"; + +apiUrl = "https://giift-api.asacreative.com/"; +imageUrl = "https://giift-api.asacreative.com"; + type = 'localhost'; if(window.location.href.includes("localhost") || window.location.href.includes("marketplace-store")){ appUrl = 'http://localhost:7700' diff --git a/src/common/pages/Vouchers/index.js b/src/common/pages/Vouchers/index.js index 5626d8d..769fde5 100644 --- a/src/common/pages/Vouchers/index.js +++ b/src/common/pages/Vouchers/index.js @@ -32,9 +32,12 @@ export default class VouchersComponent extends React.Component { }, }; this.defaultState = Object.assign({}, this.state); + this.vouchersStore = props.appstate.vouchers; } componentDidMount() { + this.vouchersStore.getList(); + console.log('res list component',this.vouchersStore.getList()) } render() { diff --git a/src/common/stores/appstate.js b/src/common/stores/appstate.js index d2156c5..37f1db2 100644 --- a/src/common/stores/appstate.js +++ b/src/common/stores/appstate.js @@ -56,6 +56,7 @@ import {Tags} from './tags'; import Surf from './surf'; import Odoo from './odoo'; +import Vouchers from './vouchers'; export default class AppState { http = new Http(this.token); @@ -101,6 +102,7 @@ export default class AppState { userBanks = new UserBanks(this); stores = new Stores(this); storeList = new StoreList(this); + vouchers = new Vouchers(this); userAddress = new UserAddress(this); item = new ItemStore(this); myStore = new MyStoreStore(this); diff --git a/src/common/stores/vouchers.js b/src/common/stores/vouchers.js new file mode 100644 index 0000000..ba63d59 --- /dev/null +++ b/src/common/stores/vouchers.js @@ -0,0 +1,101 @@ +import { observable, action, computed } from 'mobx'; + +export default class Vouchers { + + @observable list = []; + @observable selected = {}; + @observable istLoading = false; + @observable isSearching = false; + @observable filtered = []; + + constructor(context) { + this.http = context.http; + this.context = context; + } + + @action + getList(){ + console.log('res'); + this.isLoading = true; + return this.http.get("items") + .then(res => { + console.log(res.data,'res list') + this.list = res.data; + this.isLoading = false; + }) + .catch(err => { + this.isLoading = false; + throw err; + }) + } + + @action + getDetail(id){ + this.isLoading = true; + return this.http.get(`stores/${id}`) + .then(res => { + this.selected = res; + this.isLoading = false; + }) + .catch(err => { + this.isLoading = false; + throw err; + }) + } + + @action + post(data){ + this.isLoading = true; + return this.http.post("stores", data) + .then(res => { + this.isLoading = false; + this.getList(); + return res; + }) + .catch(err => { + this.isLoading = false; + throw err; + }) + } + + @action + put(id,data){ + this.isLoading = true; + return this.http.put(`stores/${id}`, data) + .then(res => { + this.isLoading = false; + this.getList(); + return res; + }) + .catch(err => { + this.isLoading = false; + throw err; + }) + } + + @action + delete(id){ + this.isLoading = true; + return this.http.delete(`stores/${id}`) + .then(res => { + this.isLoading = false; + this.getList(); + return res; + }) + .catch(err => { + this.isLoading = false; + throw err; + }) + } + + filterItems = (query) => { + return this.list.filter((el) => + el.name.toLowerCase().indexOf(query.toLowerCase()) > -1 + ); + } + + @action + search(text){ + this.filtered = this.filterItems(text); + } + }