Commit 58fe8ad6 authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

change reward detail

parent 0e7652ba
......@@ -36,7 +36,8 @@ const ActionType = {
CHANGE_QUANTITY: 'CHANGE_QUANTITY',
SET_CORDINAT :'SET_CORDINAT',
SET_TRANS_ID:'SET_TRANS_ID',
CHANGE_TO_CHART:'CHANGE_TO_CHART'
CHANGE_TO_CHART:'CHANGE_TO_CHART',
SET_VOUCHER:'SET_VOUCHER'
}
export default ActionType;
\ No newline at end of file
......@@ -79,7 +79,10 @@ const globalState = {
trans_id:'',
lat:'',
long:''
long:'',
voucher :[],
value_voucher:''
}
......@@ -237,6 +240,14 @@ const rootReducer = (state = globalState, action) => {
selfie: false
}
}
case ActionType.SET_VOUCHER: {
return {
...state,
voucher: action.data.voucher,
value_voucher: action.data.value_voucher
}
}
case ActionType.SET_CHANGE_IMAGE_SELFI: {
return {
...state,
......
......@@ -7,6 +7,8 @@ import Axios from 'axios';
import session from '../function/session';
import HTML from 'react-native-render-html';
import { WebView } from 'react-native-webview';
import ActionType from '../redux/globalActionType';
import moment from 'moment';
class RewardDetail extends React.Component {
constructor(props) {
......@@ -18,8 +20,9 @@ class RewardDetail extends React.Component {
content: "",
expire: '',
code: '',
used:'',
dateNow:''
used: '',
dateNow: '',
value: '',
}
}
......@@ -35,8 +38,6 @@ class RewardDetail extends React.Component {
}
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/reward/get_detail', params).then(res => {
this.setState({
image: res.data.reward.reward.content_image,
title: res.data.reward.reward.title,
......@@ -44,29 +45,74 @@ class RewardDetail extends React.Component {
content: res.data.reward.reward.content,
expire: res.data.reward.expire_time,
code: res.data.reward.verification_number,
used : res.data.reward.used,
used: res.data.reward.used,
value: res.data.reward.reward.value,
})
let date = new Date(this.state.expire);
let year = date.getFullYear();
let month = date.getMonth() + 1;
let dt = date.getDate();
if (dt < 10) {
dt = '0' + dt;
}
if (month < 10) {
month = '0' + month;
}
let hasil = year+'-' + month + '-'+dt;
this.setState({
expire: hasil,
})
})
}
useVoucher(){
useVoucher() {
let params = {
session_id: this.props.session_id,
reward_id: this.props.route.params.rewardId,
lat : this.props.lat,
long : this.props.long
lat: this.props.lat,
long: this.props.long
}
console.log("PARAMETER : " + JSON.stringify(params) )
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/reward/use_reward', params).then(res => {
console.long('RESPONE : ' + res)
let voucherProps = {
value_voucher: this.state.value,
voucher: this.state.code
}
this.props.setVoucher(voucherProps);
Alert.alert(
'',
res.data.message,
[
{ text: 'OK', onPress: () => this.props.navigation.navigate('Home', { screen: 'MENU' }) }
]
)
}).catch(error => {
let response = error.response.data;
Alert.alert(
'',
response.msg,
[
{ text: 'OK' }
]
)
})
// this.props.navigation.navigate('Home',{screen:'MENU'})
}
useDVoucher(){
useDVoucher() {
this.props.navigation.navigate('Order Detail')
}
render() {
......@@ -81,16 +127,18 @@ class RewardDetail extends React.Component {
<Text style={{ fontSize: 30, textAlign: 'center', fontWeight: 'bold', bottom: 5 }}>{this.state.code}</Text>
</View>
<View style={{ height: 70, flex: 1, backgroundColor: 'black', top: -70, marginRight: 10, marginLeft: 10 }}>
<Text style={{ margin: 5 , color:'white'}}>Expired Date : </Text>
<Text style={{ fontSize: 30, textAlign: 'center', fontWeight: 'bold', bottom: 5 ,color:'white' }}>{this.state.expire}</Text>
<Text style={{ margin: 5, color: 'white' }}>Expired Date : </Text>
<Text style={{ fontSize: 30, textAlign: 'center', fontWeight: 'bold', bottom: 5, color: 'white' }}>{this.state.expire}</Text>
</View>
</View>
<View style={{ flex: 1, top: -60, margin: 10 }}>
{
this.state.used == 0 ?(
this.state.used == 0 ? (
<Button title="USE VOUCHER" onPress={() => this.useVoucher()}></Button>
):( <Button title="USED" onPress={()=>this.props.navigation.navigate('Menu Select')()}></Button>)
) : this.state.expire >= Date.now() ? (<Button title="EXPIRED" ></Button>) :
(<Button title="USED" onPress={() => this.props.navigation.navigate('Menu Select')()}></Button>)
}
<HTML html={this.state.title} />
<HTML html={this.state.content} />
</View>
</ScrollView>
......@@ -124,6 +172,22 @@ const styles = StyleSheet.create({
})
const mapDispatchToProps = (dispacth) => {
return {
setVoucher: (voucherProps) => dispacth({
type: ActionType.SET_VOUCHER,
data: {
voucher: voucherProps.voucher,
value_voucher: voucherProps.value_voucher,
}
}),
}
}
const mapStateToProps = (state) => {
return {
......@@ -134,4 +198,4 @@ const mapStateToProps = (state) => {
}
}
export default connect(mapStateToProps)(RewardDetail);
\ No newline at end of file
export default connect(mapStateToProps, mapDispatchToProps)(RewardDetail);
\ No newline at end of file
......@@ -43,6 +43,8 @@ class ShoppingCart extends React.Component {
componentDidMount() {
console.log('INI VOUCHER : ' + this.props.voucher)
console.log('INI VALUE : ' + this.props.value_voucher)
if (!this.props.type_pickup) {
this.getRate()
}
......@@ -854,6 +856,8 @@ const mapDispatchToProps = (dispacth) => {
const mapStateToProps = (state) => {
return {
type_pickup: state.type_pickup,
value_voucher: state.value_voucher,
voucher: state.voucher,
session_id: state.session_id,
outlet_id: state.outlet_id,
name_outlet: state.name_outlet,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment