From 76eb551debc963b1544bd1cde863698e71a6a1dc Mon Sep 17 00:00:00 2001 From: Hasta Ragil Saputra Date: Sun, 6 Jan 2019 18:21:08 +0700 Subject: [PATCH 1/2] feat: add wallet --- src/common/pages/App/WalletComponent.js | 36 +++++++++++++++++++++++++ src/common/pages/App/index.js | 22 +++------------ src/common/pages/Wallet/index.js | 4 +-- src/common/stores/appstate.js | 13 ++++++++- src/common/stores/authenticaton.js | 3 ++- src/common/stores/wallet.js | 28 +++++++++++++++++++ 6 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 src/common/pages/App/WalletComponent.js create mode 100644 src/common/stores/wallet.js diff --git a/src/common/pages/App/WalletComponent.js b/src/common/pages/App/WalletComponent.js new file mode 100644 index 0000000..9140b1d --- /dev/null +++ b/src/common/pages/App/WalletComponent.js @@ -0,0 +1,36 @@ +import React from 'react'; +import {observer, inject} from 'mobx-react'; +import {Route as RouteDOM} from "react-router-dom"; +import {LINKS} from "../../routes"; +import NumberFormat from "react-number-format"; + +@inject('appstate') +@observer +export default class WalletComponent extends React.Component { + constructor(props) { + super(props); + this.props = props; + } + + render() { + return (
+ {this.props.appstate.wallet.data.wallet} +
+

Voucher

+ ( +

history.push(LINKS.WALLET)} className={'textVoucher'}> + +

+ )} /> +
+
+

Points

+ ( +

history.push(LINKS.WALLET)} className={'textPoints'}> + +

+ )} /> +
+
); + } +} diff --git a/src/common/pages/App/index.js b/src/common/pages/App/index.js index 5170c46..b15a956 100644 --- a/src/common/pages/App/index.js +++ b/src/common/pages/App/index.js @@ -44,6 +44,7 @@ import EmptyComponent from '../EmptyComponent'; import NumberFormat from 'react-number-format'; import faker from 'faker'; import { Route as RouteDOM } from 'react-router-dom' +import WalletComponent from "./WalletComponent"; faker.locale = 'id_ID'; @inject("appstate") @@ -442,24 +443,7 @@ export default class App extends React.Component { -
-
-

Voucher

- ( -

history.push(LINKS.WALLET)} className={'textVoucher'}> - -

- )} /> -
-
-

Points

- ( -

history.push(LINKS.WALLET)} className={'textPoints'}> - -

- )} /> -
-
+ {window.location.pathname.split("/")[2] == "shop" ? ( ) : (
)} - + ; - const points = ; + const voucher = ; + const points = ; const data = [ { diff --git a/src/common/stores/appstate.js b/src/common/stores/appstate.js index 08cc0a5..8caad67 100644 --- a/src/common/stores/appstate.js +++ b/src/common/stores/appstate.js @@ -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: '', diff --git a/src/common/stores/authenticaton.js b/src/common/stores/authenticaton.js index de6f12c..c89120f 100644 --- a/src/common/stores/authenticaton.js +++ b/src/common/stores/authenticaton.js @@ -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 diff --git a/src/common/stores/wallet.js b/src/common/stores/wallet.js new file mode 100644 index 0000000..efae738 --- /dev/null +++ b/src/common/stores/wallet.js @@ -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; + }) + } +} From 8dd6e49337553a416b6ec6a62a7f8b34b9265eaf Mon Sep 17 00:00:00 2001 From: Rifqy Zacky Ariadhy Date: Sun, 6 Jan 2019 18:27:04 +0700 Subject: [PATCH 2/2] update: history voucher --- src/common/pages/Transaction/ItemList/index.js | 18 +++++++++++------- src/common/pages/Transaction/index.js | 18 +++++++++++++++--- src/common/stores/appstate.js | 2 ++ src/common/stores/purchased_item_voucher.js | 11 +++++++++++ 4 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 src/common/stores/purchased_item_voucher.js diff --git a/src/common/pages/Transaction/ItemList/index.js b/src/common/pages/Transaction/ItemList/index.js index a335c29..21b96fd 100644 --- a/src/common/pages/Transaction/ItemList/index.js +++ b/src/common/pages/Transaction/ItemList/index.js @@ -4,6 +4,7 @@ import {inject, observer} from "mobx-react"; import faker from "faker"; import './style.scss'; +import moment from "moment"; @inject("appstate") @observer @@ -17,13 +18,16 @@ export default class ItemList extends React.Component { const { data = { transaction_id: '', + transaction: {}, + item: {}, + item_sku: {}, created_at: '', updated_at: '', deleted_at: '', name: '', status: '', price: '', - voucher_code: ``, + voucher_code: `-`, } } = this.props; @@ -32,24 +36,24 @@ export default class ItemList extends React.Component {
-

{data.transaction_id}

-

{data.updated_at}

+

{`INV/20190101/VII/X/${data.transaction_id.split('-')[0].toUpperCase()}`}

+

{moment(data.updated_at).format("dddd, MMMM Do YYYY, HH:mm:ss")}

-

{data.name}

+

{data.item.name + " : " + data.item_sku.name}

Price

-

{(+data.price).toFixed(0)} BTN Reward

+

{(+data.item_sku.price).toFixed(0)} Points

Voucher Code

-

{data.voucher_code}

+

{data.voucher_code || '-'}

Status

-

{data.status}

+

{data.transaction.status}

diff --git a/src/common/pages/Transaction/index.js b/src/common/pages/Transaction/index.js index 66e37ed..cb6bd9f 100644 --- a/src/common/pages/Transaction/index.js +++ b/src/common/pages/Transaction/index.js @@ -7,6 +7,7 @@ import {FlatButton} from "material-ui"; import './style.scss'; import ItemList from "./ItemList"; import moment from 'moment'; +import EmptyComponent from "../EmptyComponent"; @inject("appstate") @observer @@ -14,6 +15,11 @@ export default class TransactionPage extends React.Component { constructor(props){ super(props); this.props = props; + this.purchasedVoucher = props.appstate.purchased_voucher; + } + + componentDidMount() { + this.purchasedVoucher.getAll().then((res) => console.log(res, 'ini purchased voucher')) } render() { @@ -84,9 +90,15 @@ export default class TransactionPage extends React.Component {
- {data.map(item => { - return - })} + { + (this.purchasedVoucher.data.length > 0) ? + this.purchasedVoucher.data.map(item => { + return + }) : + ( + + ) + }
diff --git a/src/common/stores/appstate.js b/src/common/stores/appstate.js index 08cc0a5..a223ae9 100644 --- a/src/common/stores/appstate.js +++ b/src/common/stores/appstate.js @@ -58,6 +58,7 @@ import Odoo from './odoo'; import Vouchers from './vouchers'; import {PurchasedItemStore} from "./purchased_item"; +import {PurchasedItemVouchserStore} from "./purchased_item_voucher"; export default class AppState { http = new Http(this.token); @@ -117,6 +118,7 @@ export default class AppState { tags = new Tags(this); surf_turf = new Surf(this); purchased_items = new PurchasedItemStore(this); + purchased_voucher = new PurchasedItemVouchserStore(this); constructor(initialState) { this.token = initialState.token; diff --git a/src/common/stores/purchased_item_voucher.js b/src/common/stores/purchased_item_voucher.js new file mode 100644 index 0000000..2ca165e --- /dev/null +++ b/src/common/stores/purchased_item_voucher.js @@ -0,0 +1,11 @@ +import { BaseStore } from "./base_store"; +import {observable, action} from "mobx/lib/mobx"; + +export class PurchasedItemVouchserStore extends BaseStore { + + constructor(context) { + super(context); + this.url = "purchased_items/vouchers"; + } + +}