addCouponActions.js
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
import ReactNative from 'react-native';
import AddCouponService from '../../services/AddCouponService';
const {
ADD_COUPON_REQUEST,
ADD_COUPON_SUCCESS,
ADD_COUPON_FAILURE,
RESETRECEIVECOUPONRES,
} = require('../../constants/actionTypes').default;
export function resetReceiveCouponResult() {
return {
type: RESETRECEIVECOUPONRES,
}
}
export function addCouponRequest() {
return {
type: ADD_COUPON_REQUEST,
};
}
export function addCouponSuccess(json) {
return {
type: ADD_COUPON_SUCCESS,
payload: json
}
}
export function addCouponFailure(error) {
return {
type: ADD_COUPON_FAILURE,
payload: error
}
}
export function addCoupon(coupon_code) {
return (dispatch, getState) => {
let {app, addCoupon} = getState();
let fetchAddCoupon = (uid) => {
dispatch(addCouponRequest());
return new AddCouponService(app.host).addCoupon(uid,coupon_code)
.then(json => {
dispatch(addCouponSuccess(json));
ReactNative.NativeModules.YH_MyAssetsViewHelper.needUpdateCoupon();
})
.catch(error => {
dispatch(addCouponFailure(error));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
fetchAddCoupon(uid);
})
.catch(error => {
});
};
}