Commit 4e3edb32 authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

fungsi expired sudah jalan

parent 58fe8ad6
{ {
"expo": { "expo": {
"name": "Excelso_update v1.11.05.2020", "name": "Excelso_update v1.12.05.2020",
"slug": "excelso-pro", "slug": "excelso-pro",
"privacy": "public", "privacy": "public",
"sdkVersion": "36.0.0", "sdkVersion": "36.0.0",
......
...@@ -294,7 +294,7 @@ class Home extends React.Component { ...@@ -294,7 +294,7 @@ class Home extends React.Component {
<TouchableOpacity style={styles.submitUpgradePemium} activeOpacity={.5} onPress={this.onPress}> <TouchableOpacity style={styles.submitUpgradePemium} activeOpacity={.5} onPress={this.onPress}>
<Text style={{ textAlign: 'center', bottom: 5, color: 'white' }}>TOP BALANCE </Text> <Text style={{ textAlign: 'center', bottom: 5, color: 'white' }}>TOP BALANCE </Text>
</TouchableOpacity> </TouchableOpacity>
<Text>11 May 2019 </Text> <Text>12 May 2019 </Text>
<View style={{ height: 60 }}></View> <View style={{ height: 60 }}></View>
</View> </View>
</View> </View>
......
import React from 'react'; import React from 'react';
import { View, Text, TextInput, StyleSheet, ScrollView, Alert, TouchableOpacity, Image, Button } from 'react-native'; import { View, Text, TextInput, StyleSheet, ScrollView, Alert, TouchableOpacity, Image } from 'react-native';
import { CheckBox, Separator, Grid, Row, Card, Icon, CardItem, Body } from 'native-base';
import { Collapse, CollapseHeader, CollapseBody, AccordionList } from 'accordion-collapse-react-native'
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import Axios from 'axios'; import Axios from 'axios';
import session from '../function/session'; import session from '../function/session';
...@@ -9,6 +7,7 @@ import HTML from 'react-native-render-html'; ...@@ -9,6 +7,7 @@ import HTML from 'react-native-render-html';
import { WebView } from 'react-native-webview'; import { WebView } from 'react-native-webview';
import ActionType from '../redux/globalActionType'; import ActionType from '../redux/globalActionType';
import moment from 'moment'; import moment from 'moment';
import { Button } from 'react-native-elements';
class RewardDetail extends React.Component { class RewardDetail extends React.Component {
constructor(props) { constructor(props) {
...@@ -23,11 +22,21 @@ class RewardDetail extends React.Component { ...@@ -23,11 +22,21 @@ class RewardDetail extends React.Component {
used: '', used: '',
dateNow: '', dateNow: '',
value: '', value: '',
cur_time: '',
exp_time: '',
} }
} }
componentDidMount() { componentDidMount() {
this.detailReward() this.detailReward()
this._unsubscribe = this.props.navigation.addListener('focus', () => {
this.detailReward()
});
}
componentWillUnmount() {
this._unsubscribe()
} }
detailReward() { detailReward() {
...@@ -38,109 +47,102 @@ class RewardDetail extends React.Component { ...@@ -38,109 +47,102 @@ class RewardDetail extends React.Component {
} }
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/reward/get_detail', params).then(res => { Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/reward/get_detail', params).then(res => {
let expire_date = moment(res.data.reward.expire_time).format('DD MMMM YYYY')
let exp_time = new Date(res.data.reward.expire_time)
exp_time.setHours(0, 0, 0, 0);
let cur_time = new Date()
cur_time.setHours(0, 0, 0, 0);
this.setState({ this.setState({
image: res.data.reward.reward.content_image, image: res.data.reward.reward.content_image,
title: res.data.reward.reward.title, title: res.data.reward.reward.title,
subtitle: res.data.reward.reward.subtitle, subtitle: res.data.reward.reward.subtitle,
content: res.data.reward.reward.content, content: res.data.reward.reward.content,
expire: res.data.reward.expire_time, expire: expire_date,
code: res.data.reward.verification_number, code: res.data.reward.verification_number,
used: res.data.reward.used, used: res.data.reward.used,
value: res.data.reward.reward.value, value: res.data.reward.reward.value,
cur_time: cur_time,
exp_time: exp_time
}) })
}).catch(error => {
let date = new Date(this.state.expire); const { navigation } = this.props
let year = date.getFullYear(); let response = error.response.data
let month = date.getMonth() + 1; session(response, navigation)
let dt = date.getDate(); Alert.alert(response.msg);
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 = { let voucherProps = {
value_voucher: this.state.value,
session_id: this.props.session_id, voucher: this.state.code
reward_id: this.props.route.params.rewardId,
lat: this.props.lat,
long: this.props.long
} }
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/reward/use_reward', params).then(res => { this.props.setVoucher(voucherProps);
this.props.navigation.navigate('Home', { screen: 'MENU' })
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' }
]
)
})
} }
useDVoucher() { useDVoucher() {
this.props.navigation.navigate('Order Detail') this.props.navigation.navigate('Order Detail')
} }
render() { render() {
const deskripsi = this.state.deskripsi
return ( return (
<View style={styles.container}> <View style={styles.container}>
<ScrollView style={styles.body}> <ScrollView>
<View style={styles.body}> <View style={styles.body}>
<Image style={{ height: 250, width: '100%' }} source={this.state.image ? { uri: this.state.image } : null} /> <Image style={{ height: 250, width: '100%' }} source={this.state.image ? { uri: this.state.image } : null} />
<View style={{ height: 70, flex: 1, backgroundColor: '#03989E', top: -60, marginRight: 10, marginLeft: 10 }}> <View style={styles.content_code_expire}>
<Text style={{ margin: 5 }}>Voucher code : </Text> <View style={styles.voucher_code}>
<Text style={{ fontSize: 30, textAlign: 'center', fontWeight: 'bold', bottom: 5 }}>{this.state.code}</Text> <Text style={styles.text_voucher}>Voucher Code : </Text>
<Text style={styles.text_c_voucher}>{this.state.code}</Text>
</View>
<View style={styles.expire_time}>
<Text style={styles.text_expire}>Expire Time : </Text>
<Text style={styles.text_c_expire}>{this.state.expire}</Text>
</View>
</View> </View>
<View style={{ height: 70, flex: 1, backgroundColor: 'black', top: -70, marginRight: 10, marginLeft: 10 }}> <View style={styles.content}>
<Text style={{ margin: 5, color: 'white' }}>Expired Date : </Text> {this.state.cur_time >= this.state.exp_time ? (<Button
<Text style={{ fontSize: 30, textAlign: 'center', fontWeight: 'bold', bottom: 5, color: 'white' }}>{this.state.expire}</Text> style={{ margin: 5 }}
title="EXPIRED"
onPress={() => console.log('inin')}
buttonStyle={{ height: 50, backgroundColor: 'red' }}
/>)
: this.state.used == 0 ? (
<Button
style={{ margin: 5 }}
title="USE VOUCHER"
onPress={() => this.useVoucher()}
buttonStyle={{ height: 50, backgroundColor: '#2ead28' }}
/>
) : (
<Button
style={{ margin: 5 }}
title="USED"
onPress={() => this.useDVoucher()}
buttonStyle={{ height: 50, backgroundColor: '#2ead28' }}
/>
)}
<View>
<Text style={{ textAlign: 'center', fontSize: 15, top: 5, fontWeight: 'bold' }}>{this.state.title}</Text>
</View>
<View style={{ margin: 10 }}>
<HTML html={this.state.content} />
</View>
</View> </View>
</View> </View>
<View style={{ flex: 1, top: -60, margin: 10 }}>
{
this.state.used == 0 ? (
<Button title="USE VOUCHER" onPress={() => this.useVoucher()}></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> </ScrollView>
</View> </View>
) )
...@@ -153,23 +155,71 @@ const styles = StyleSheet.create({ ...@@ -153,23 +155,71 @@ const styles = StyleSheet.create({
flex: 1, flex: 1,
backgroundColor: 'white', backgroundColor: 'white',
}, },
header: { body: {
flex: 1,
},
flex: 0.5, content_code_expire: {
top: -140,
flex: 1,
backgroundColor: 'green',
marginRight: 30,
marginLeft: 30,
}, },
images: {
margin: 10,
flex: 2,
justifyContent: 'center', voucher_code: {
height: 70,
backgroundColor: '#01919c',
flex: 1,
}, },
content: {
flex: 2, expire_time: {
flex: 1,
height: 70,
backgroundColor: 'black',
}, },
body: {
flex: 3, text_voucher: {
fontSize: 15,
marginLeft: 10,
top: 5,
color: 'white'
},
text_c_voucher: {
textAlign: 'center',
fontWeight: 'bold',
fontSize: 30,
top: 5,
color: 'white'
},
text_expire: {
fontSize: 15,
marginLeft: 10,
top: 5,
color: 'white'
},
text_c_expire: {
textAlign: 'center',
fontWeight: 'bold',
fontSize: 30,
top: 5,
color: 'white'
}, },
content: {
top: -140,
flex: 1,
},
button: {
flex: 1,
height: 60,
backgroundColor: '#2ead28',
borderRadius: 5,
},
}) })
...@@ -198,4 +248,6 @@ const mapStateToProps = (state) => { ...@@ -198,4 +248,6 @@ const mapStateToProps = (state) => {
} }
} }
export default connect(mapStateToProps, mapDispatchToProps)(RewardDetail); export default connect(mapStateToProps, mapDispatchToProps)(RewardDetail);
\ No newline at end of file
{/* */ }
\ No newline at end of file
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