Commit 26b1db78 authored by Trisno's avatar Trisno

update use balance

parent 729e7c9a
......@@ -523,7 +523,19 @@ class Auth extends React.Component {
{/* <Stack.Screen name="Card Activation" component={CardActivation} /> */}
<Stack.Screen name="Confirm Mobile" component={ConfirmMobile} />
<Stack.Screen name="Balance" component={Balance} />
<Stack.Screen name="Redeem Code" component={RedeemCode} />
<Stack.Screen name="Redeem Code" component={RedeemCode}
options={{
headerStyle: { backgroundColor: "#CFB368" },
headerBackTitleStyle: { color: 'white' },
headerTintColor: '#fff',
headerTitleAlign: 'center',
headerTitleStyle: {
fontFamily: 'Gotham-Black',
color: 'white',
fontSize: 20,
},
title: 'REDEEM CODE'
}} />
<Stack.Screen name="Transaction History" component={TransactionHistory}
options={{
headerStyle: { backgroundColor: "#CFB368" },
......
import React from 'react';
import { View, Text, TextInput, StyleSheet, Button } from 'react-native';
import { View, Text, TextInput, StyleSheet, Button, TouchableOpacity, Alert, } from 'react-native';
import { connect } from 'react-redux';
import Axios from 'axios';
class RedeemCode extends React.Component {
constructor(props) {
super(props);
this.state = {
}
}
cancel() {
let params = {
session_id: this.props.session_id,
}
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/point/refund', params).then(res => {
console.log(res.data)
Alert.alert('', 'Berhasil dibatalkan')
this.props.navigation.navigate('Home', { screen: 'HOME' });
}).catch(error => {
let response = error.response.data
if (response.code === "EMPTY_PIN") {
Alert.alert('Error', response.msg)
} else {
let response = error.response.data;
Alert.alert('', response.msg);
}
})
}
export default class RedeemCode extends React.Component {
render() {
console.log(this.props)
return (
<View style={styles.container}>
<View style={styles.header}>
{/* <View style={styles.header}>
<Text style={{ textAlign: 'center', fontSize: 25 }}>Payment Code</Text>
</View>
<View>
<Text style={{ fontSize: 25, textAlign: 'center' }}>XY2313</Text>
<View style={{ borderWidth: 1, marginRight: 20, marginLeft: 20 }}></View>
</View> */}
<View style={{ marginTop: 50 }}>
<Text style={{ fontFamily: 'Gotham-Black', color: '#838383', fontSize: 26, textAlign: 'center' }}>{this.props.route.params.redeemCode}</Text>
<View style={{ borderWidth: 1, marginRight: 20, marginLeft: 20, borderColor: '#838383' }}></View>
</View>
<View style={styles.body}>
<View style={styles.current_balance}>
<View style={{ flex: 1, margin: 10 }}>
<Text style={{ fontSize: 20 }} >Current Balance</Text>
<Text style={{ fontSize: 20, fontFamily: 'Gotham-Black', color: '#838383' }} >Balance</Text>
</View>
<View style={{ flex: 1, margin: 10 }}>
<Text style={{ fontSize: 20 }}>xxxxxxxxxxx</Text>
<Text style={{ fontSize: 20, fontFamily: 'Gotham-Black', color: '#838383' }}>{this.props.route.params.balanceUsed}</Text>
</View>
</View>
<View style={styles.redeem}>
<View style={styles.current_balance}>
<View style={{ flex: 1, margin: 10 }}>
<Text style={{ fontSize: 20, fontFamily: 'Gotham-Black', color: '#838383' }} >Points</Text>
</View>
<View style={{ flex: 1, margin: 10 }}>
<Text style={{ fontSize: 20, fontFamily: 'Gotham-Black', color: '#838383' }}>{this.props.route.params.pointUsed}</Text>
</View>
</View>
{/* <View style={styles.redeem}>
<View style={{ flex: 1, margin: 10 }}>
<Text style={{ fontSize: 20 }} >Time</Text>
</View>
<View style={{ flex: 1, margin: 10 }}>
<Text style={{ fontSize: 20 }}>0:30</Text>
</View>
</View>
</View> */}
<TouchableOpacity onPress={() => this.cancel()}>
<View style={styles.button}>
<Button title="Cancel Payment" color="red" />
<Text style={{ color: 'white', fontSize: 16, fontFamily: 'Gotham-Black' }}>Cancel Payment</Text>
</View>
</TouchableOpacity>
</View>
</View>
)
......@@ -69,9 +112,22 @@ const styles = StyleSheet.create({
button: {
height: 50,
margin: 10,
backgroundColor: '#d34343',
height: 40,
marginTop: 25,
marginHorizontal: 20,
borderRadius: 10,
paddingVertical: 5,
alignItems: 'center',
justifyContent: 'center'
},
})
const mapStateToProps = (state) => {
return {
session_id: state.session_id,
}
}
})
\ No newline at end of file
export default connect(mapStateToProps)(RedeemCode);
\ No newline at end of file
......@@ -2,6 +2,9 @@ import React from 'react';
import { View, Text, TextInput, StyleSheet, Button, Alert, TouchableOpacity, Image, Modal } from 'react-native';
import { connect } from 'react-redux';
import Axios from 'axios';
import { Card } from 'react-native-shadow-cards'
import CheckBox from 'react-native-check-box'
import { Entypo, Ionicons, MaterialCommunityIcons, MaterialIcons, AntDesign, FontAwesome } from '@expo/vector-icons'
import ActionType from '../redux/globalActionType';
import Spinner from 'react-native-loading-spinner-overlay';
import PinRequest from './PinRequest'
......@@ -11,12 +14,21 @@ class UseBalance extends React.Component {
constructor(props) {
super(props);
this.state = {
kasproBalance: 0,
kasproPoint: 0,
current_balance: 0,
kaspro_point: 0,
input_redeem: 0,
redeem_balance: 0,
redeem_point: 0,
modalVisible: false,
pin: ''
pin: '',
checkedBalance: false,
checkedPoint: false,
checkedBalancePoint: false,
balanceused: 0,
pointsused: 0,
}
}
......@@ -30,7 +42,7 @@ class UseBalance extends React.Component {
}
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/member/get_profile', params).then(res => {
console.log('ini res ' + JSON.stringify(res.data))
// console.log('ini res ' + JSON.stringify(res.data))
const dataCard = res.data
......@@ -41,16 +53,42 @@ class UseBalance extends React.Component {
this.setState({
current_balance: balances,
kaspro_point: points
current_balance: dataCard.kaspro_balance,
kaspro_point: dataCard.kaspro_point,
kasproBalance: dataCard.kaspro_balance.replace(/,/g, ''),
kasproPoint: dataCard.kaspro_point.replace(/,/g, '')
})
// console.log(this.state.kasproBalance)
// console.log(this.state.kasproPoint)
}).catch(error => {
// console.log('ini error ' + error)
})
}
checkedSelection(val) {
// console.log(val)
if (val == 'balance') {
this.setState({
checkedBalance: true,
checkedPoint: false,
checkedBalancePoint: false,
})
} else if (val == 'point') {
this.setState({
checkedBalance: false,
checkedPoint: true,
checkedBalancePoint: false,
})
} else {
this.setState({
checkedBalance: false,
checkedPoint: false,
checkedBalancePoint: true,
})
}
}
handleBack() {
this.setState({
modalVisible: false
......@@ -71,24 +109,83 @@ class UseBalance extends React.Component {
}
redeem() {
if (this.state.redeem_balance > this.state.current_balance) {
if (this.state.checkedBalance == false && this.state.checkedPoint == false && this.state.checkedBalancePoint == false) {
Alert.alert('Error', 'Silahkan pilih metode pembayaran')
} else {
if (this.state.checkedBalance) {
if (parseInt(this.state.input_redeem) > parseInt(this.state.kasproBalance)) {
Alert.alert('', 'Maaf Balance tidak cukup')
} else if (this.state.redeem_point > this.state.kaspro_point) {
} else {
let params = {
session_id: this.props.session_id,
pin: this.state.pin,
balance: this.state.input_redeem,
point: 0
}
// console.log(params)
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/point/redeem', params).then(res => {
// console.log(res.data)
let respon = res.data
Alert.alert('', 'Sukses Redeem')
this.props.navigation.navigate('Redeem Code', {redeemCode : respon.redeem_code,
balanceUsed : respon.use_balance,
pointUsed : respon.use_point})
}).catch(error => {
let response = error.response.data
if (response.code === "EMPTY_PIN") {
Alert.alert('Error', response.msg)
} else {
let response = error.response.data;
Alert.alert('', response.msg);
}
})
}
} else if (this.state.checkedPoint) {
if (parseInt(this.state.input_redeem) > parseInt(this.state.kasproPoint)) {
Alert.alert('', 'Maaf Point tidak cukup')
} else {
let params = {
session_id: this.props.session_id,
pin: this.state.pin,
balance: this.state.redeem_balance,
point: this.state.redeem_point
balance: 0,
point: this.state.input_redeem
}
console.log(params)
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/point/redeem', params).then(res => {
Alert.alert('', 'Sukses Redeem')
}).catch(error => {
let response = error.response.data
if (response.code === "EMPTY_PIN") {
Alert.alert('Error', response.msg)
} else {
let response = error.response.data;
Alert.alert('', response.msg);
}
})
}
} else {
if (parseInt(this.state.input_redeem) > parseInt(parseInt(this.state.kasproPoint) + parseInt(this.state.kasproBalance))) {
Alert.alert('', 'Maaf Balance dan Point tidak cukup')
} else {
let params = {
session_id: this.props.session_id,
pin: this.state.pin,
balance: 0,
point: this.state.kasproPoint
}
console.log(params)
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/point/redeem', params).then(res => {
Alert.alert('', 'Sukses Redeem')
}).catch(error => {
let response = error.response.data
if (response.code === "EMPTY_PIN") {
this.modal()
Alert.alert('Error', response.msg)
} else {
let response = error.response.data;
Alert.alert('', response.msg);
......@@ -98,7 +195,40 @@ class UseBalance extends React.Component {
}
}
// if (parseInt(this.state.input_redeem) > parseInt(this.state.kasproBalance)) {
// Alert.alert('', 'Maaf Balance tidak cukup')
// } else if (parseInt(this.state.input_redeem) > parseInt(this.state.kasproPoint)) {
// Alert.alert('', 'Maaf Point tidak cukup')
// } else {
// let params = {
// session_id: this.props.session_id,
// pin: this.state.pin,
// balance: this.state.input_redeem,
// point: 0
// }
// console.log(params)
// Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/point/redeem', params).then(res => {
// Alert.alert('', 'Sukses Redeem')
// }).catch(error => {
// let response = error.response.data
// if (response.code === "EMPTY_PIN") {
// Alert.alert('Error', response.msg)
// } else {
// let response = error.response.data;
// Alert.alert('', response.msg);
// }
// })
// }
}
}
render() {
// console.log(parseInt(this.state.input_redeem) > parseInt(parseInt(this.state.kasproPoint) + parseInt(this.state.kasproBalance)))
return (
<View style={styles.container}>
<Modal animationType="slide"
......@@ -143,15 +273,144 @@ class UseBalance extends React.Component {
</Modal>
<View style={{ flex: 3 }}>
<View style={{ flex: 1, marginRight: 30, marginLeft: 30, top: 50 }}>
<Text style={{ fontFamily: 'Gotham-Black', color: '#CFB368', fontSize: 20, textAlign: 'center', margin: 3 }}>Current Balance</Text>
<TextInput style={{ height: 40, borderWidth: 1, padding: 5, margin: 10, borderRadius: 10, borderColor: 'grey', fontFamily: 'Gotham-Black', textAlign: 'center', color: 'grey', fontWeight: 'bold', fontSize: 20 }}
<Text style={{ fontFamily: 'Gotham-Black', color: '#CFB368', fontSize: 20, textAlign: 'center', margin: 3 }}>Balance</Text>
<Text style={{ fontFamily: 'Gotham-Black', color: '#838383', fontSize: 18, textAlign: 'center', margin: 1 }}>IDR {this.state.current_balance}</Text>
<Text style={{ fontFamily: 'Gotham-Black', color: '#CFB368', fontSize: 20, textAlign: 'center', margin: 3, marginTop: 10 }}>Points</Text>
<Text style={{ fontFamily: 'Gotham-Black', color: '#838383', fontSize: 18, textAlign: 'center', margin: 1 }}>IDR {this.state.kaspro_point}</Text>
{/* <TextInput style={{ height: 40, borderWidth: 1, padding: 5, margin: 10, borderRadius: 10, borderColor: 'grey', fontFamily: 'Gotham-Black', textAlign: 'center', color: 'grey', fontWeight: 'bold', fontSize: 20 }}
onChangeText={(redeem_balance) => this.setState({ redeem_balance })}
keyboardType='numeric'>{this.state.current_balance}</TextInput>
<Text style={{ fontFamily: 'Gotham-Black', color: '#CFB368', fontSize: 20, textAlign: 'center', margin: 3 }}>Redeem</Text>
<TextInput style={{ height: 40, borderWidth: 1, padding: 5, margin: 10, borderRadius: 10, borderColor: 'grey', fontFamily: 'Gotham-Black', textAlign: 'center', color: 'grey', fontWeight: 'bold', fontSize: 20 }}
onChangeText={(redeem_point) => this.setState({ redeem_point })}
keyboardType='numeric'>{this.state.current_balance}</TextInput> */}
<Text style={{ fontFamily: 'Gotham-Black', color: '#CFB368', fontSize: 20, textAlign: 'center', margin: 3, marginTop: 10 }}>Redeem</Text>
<TextInput style={{ height: 40, borderWidth: 1, padding: 5, margin: 3, marginBottom: 20, borderRadius: 10, borderColor: 'grey', fontFamily: 'Gotham-Black', textAlign: 'center', color: 'grey', fontWeight: 'bold', fontSize: 20 }}
onChangeText={(input_redeem) => this.setState({ input_redeem })}
placeholder='0'
placeholderTextColor='#838383'
autoCapitalize="none"
keyboardType='numeric'>{this.state.kaspro_point}</TextInput>
keyboardType='numeric' />
<View style={{ alignItems: 'center' }}>
{
this.state.input_redeem == 0 ? (
<Card style={{ margin: 5, padding: 10, backgroundColor: 'gray' }}>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
<View>
<Text style={{ fontSize: 12, fontFamily: 'Gotham-Black', color: 'white' }}>EXCELSO BALANCE</Text>
</View>
<View>
<FontAwesome name='circle-o' size={30} color={'#ccb46c'} />
</View>
</View>
</Card>
) : (
<TouchableOpacity onPress={() => {
this.checkedSelection('balance')
}}>
<Card style={{ margin: 5, padding: 10 }}>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
<View>
<Text style={{ fontSize: 12, fontFamily: 'Gotham-Black', color: 'grey' }}>EXCELSO BALANCE</Text>
</View>
<View>
<CheckBox
onClick={() => {
this.checkedSelection('balance')
}}
isChecked={this.state.checkedBalance}
checkedImage={<FontAwesome name='check-circle' size={30} color={'#ccb46c'} />}
unCheckedImage={<FontAwesome name='circle-o' size={30} color={'#ccb46c'} />}
/>
</View>
</View>
</Card>
</TouchableOpacity>
)
}
</View>
<View style={{ alignItems: 'center' }}>
{
this.state.input_redeem == 0 ? (
<Card style={{ margin: 5, padding: 10, backgroundColor: 'gray' }}>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
<View>
<Text style={{ fontSize: 12, fontFamily: 'Gotham-Black', color: 'white' }}>EXCELSO POINTS</Text>
</View>
<View>
<FontAwesome name='circle-o' size={30} color={'#ccb46c'} />
</View>
</View>
</Card>
) : (
<TouchableOpacity onPress={() => {
this.checkedSelection('point')
}}>
<Card style={{ margin: 5, padding: 10 }}>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
<View>
<Text style={{ fontSize: 12, fontFamily: 'Gotham-Black', color: 'grey' }}>EXCELSO POINTS</Text>
</View>
<View>
<CheckBox
onClick={() => {
this.checkedSelection('point')
}}
isChecked={this.state.checkedPoint}
checkedImage={<FontAwesome name='check-circle' size={30} color={'#ccb46c'} />}
unCheckedImage={<FontAwesome name='circle-o' size={30} color={'#ccb46c'} />}
/>
</View>
</View>
</Card>
</TouchableOpacity>
)
}
</View>
<View style={{ alignItems: 'center' }}>
{
this.state.input_redeem != 0 ? (
<TouchableOpacity onPress={() => {
this.checkedSelection('balancepoint')
}}>
<Card style={{ margin: 5, padding: 10 }}>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
<View>
<Text style={{ fontSize: 12, fontFamily: 'Gotham-Black', color: 'grey' }}>EXCELSO BALANCE + POINTS</Text>
</View>
<View>
<CheckBox
onClick={() => {
this.checkedSelection('balancepoint')
}}
isChecked={this.state.checkedBalancePoint}
checkedImage={<FontAwesome name='check-circle' size={30} color={'#ccb46c'} />}
unCheckedImage={<FontAwesome name='circle-o' size={30} color={'#ccb46c'} />}
/>
</View>
</View>
</Card>
</TouchableOpacity>
) : (
<Card style={{ margin: 5, padding: 10, backgroundColor: 'gray' }}>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
<View>
<Text style={{ fontSize: 12, fontFamily: 'Gotham-Black', color: 'white' }}>EXCELSO BALANCE + POINTS</Text>
</View>
<View>
<FontAwesome name='circle-o' size={30} color={'#ccb46c'} />
</View>
</View>
</Card>
)
}
</View>
<TouchableOpacity style={{ height: 100 }} onPress={() => this.redeem()}>
<View style={{ backgroundColor: '#CFB368', height: 40, top: 20, borderRadius: 10, marginRight: 50, marginLeft: 50 }}>
<Text style={{ alignSelf: 'center', top: 10, color: 'white', fontFamily: 'Gotham-Black', fontSize: 20 }}>REDEEM</Text>
......@@ -159,7 +418,7 @@ class UseBalance extends React.Component {
</TouchableOpacity>
</View>
</View>
</View>
</View >
)
}
}
......
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