|
|
'use strict';
|
|
|
|
|
|
import ReactNative from 'react-native';
|
|
|
import CouponService from '../../services/AssociatorGiftService';
|
|
|
import AssociatorGiftService from '../../services/AssociatorGiftService';
|
|
|
const Platform = require('Platform');
|
|
|
|
|
|
const {
|
|
|
SHOWGIFTALERT,
|
|
|
DISMISSGIFTALERT,
|
|
|
|
|
|
COUPONS_BAG_REQUEST,
|
|
|
COUPONS_BAG_SUCCESS,
|
|
|
COUPONS_BAG_FAILURE,
|
|
|
|
|
|
ASSOCIATORGIFT_PRODUCT_REQUEST,
|
|
|
ASSOCIATORGIFT_PRODUCT_SUCCESS,
|
|
|
ASSOCIATORGIFT_PRODUCT_FAILURE,
|
|
|
|
|
|
DRAW_COUPONS_BAG_REQUEST,
|
|
|
DRAW_COUPONS_BAG_SUCCESS,
|
|
|
DRAW_COUPONS_BAG_FAILURE,
|
|
|
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
|
...
|
...
|
@@ -22,3 +35,130 @@ export function hiddenGiftAlert() { |
|
|
type: DISMISSGIFTALERT,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function couponsBagRequest() {
|
|
|
return {
|
|
|
type: COUPONS_BAG_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function couponsBagSuccess(json) {
|
|
|
return {
|
|
|
type: COUPONS_BAG_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function couponsBagFailure(error) {
|
|
|
return {
|
|
|
type: COUPONS_BAG_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function productListForAssociatorGiftRequest() {
|
|
|
return {
|
|
|
type: ASSOCIATORGIFT_PRODUCT_REQUEST,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function productListForAssociatorGiftSuccess(json) {
|
|
|
return {
|
|
|
type: ASSOCIATORGIFT_PRODUCT_SUCCESS,
|
|
|
payload: json,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function productListForAssociatorGiftFailure(error) {
|
|
|
return {
|
|
|
type: ASSOCIATORGIFT_PRODUCT_FAILURE,
|
|
|
payload: error
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function drawCouponsBagRequest() {
|
|
|
return {
|
|
|
type: DRAW_COUPONS_BAG_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function drawCouponsBagSuccess(json) {
|
|
|
return {
|
|
|
type: DRAW_COUPONS_BAG_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function drawCouponsBagFailure(error) {
|
|
|
return {
|
|
|
type: DRAW_COUPONS_BAG_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function getCouponsBagList() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app} = getState();
|
|
|
let fetchCouponsBag = (uid) => {
|
|
|
dispatch(couponsBagRequest());
|
|
|
return new AssociatorGiftService(app.host).fetchCouponsBagList(uid)
|
|
|
.then(json => {
|
|
|
dispatch(couponsBagSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(couponsBagFailure(error));
|
|
|
});
|
|
|
};
|
|
|
|
|
|
let uid = 0;
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
fetchCouponsBag(uid)
|
|
|
})
|
|
|
.catch(error => {
|
|
|
fetchCouponsBag(uid)
|
|
|
});
|
|
|
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function getProductListForAssociatorGift() {
|
|
|
return (dispatch, getstate) => {
|
|
|
let {app} = getstate();
|
|
|
dispatch(productListForAssociatorGiftRequest());
|
|
|
return new AssociatorGiftService(app.host).fetchAssociatorGiftProductList()
|
|
|
.then(json => {
|
|
|
dispatch(productListForAssociatorGiftSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(productListForAssociatorGiftFailure(error));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
export function getDrawCouponsBag() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app} = getState();
|
|
|
let fetchCouponsBag = (uid, couponsBagId) => {
|
|
|
dispatch(drawCouponsBagRequest());
|
|
|
return new AssociatorGiftService(app.host).fetchDrawCouponsBag(uid, couponsBagId)
|
|
|
.then(json => {
|
|
|
dispatch(drawCouponsBagSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(drawCouponsBagFailure(error));
|
|
|
});
|
|
|
};
|
|
|
|
|
|
let uid = 0;
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
fetchCouponsBag(uid)
|
|
|
})
|
|
|
.catch(error => {
|
|
|
fetchCouponsBag(uid)
|
|
|
});
|
|
|
|
|
|
};
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|