Commit 1ec20d07 authored by Trisno's avatar Trisno

tambah method balance + point

parent e1e40707
import React from 'react'; import React from 'react';
import { View, Text, TextInput, StyleSheet, Button, Alert, TouchableOpacity, Image, Modal } from 'react-native'; import { View, Text, TextInput, StyleSheet, Button, Alert, TouchableOpacity, Image, Modal, ScrollView } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import Axios from 'axios'; import Axios from 'axios';
import { Card } from 'react-native-shadow-cards' import { Card } from 'react-native-shadow-cards'
...@@ -59,7 +59,7 @@ class UseBalance extends React.Component { ...@@ -59,7 +59,7 @@ class UseBalance extends React.Component {
kasproPoint: dataCard.kaspro_point.replace(/,/g, '') kasproPoint: dataCard.kaspro_point.replace(/,/g, '')
}) })
console.log("INI SESSION "+this.props.session_id) console.log("INI SESSION " + this.props.session_id)
// console.log(this.state.kasproPoint) // console.log(this.state.kasproPoint)
}).catch(error => { }).catch(error => {
// console.log('ini error ' + error) // console.log('ini error ' + error)
...@@ -167,7 +167,7 @@ class UseBalance extends React.Component { ...@@ -167,7 +167,7 @@ class UseBalance extends React.Component {
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/point/redeem', params).then(res => { Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/point/redeem', params).then(res => {
// console.log(res.data) // console.log(res.data)
let respon = res.data let respon = res.data
console.log("INI DATANYA "+ respon) console.log("INI DATANYA " + respon)
// Alert.alert('', 'Sukses Redeem') // Alert.alert('', 'Sukses Redeem')
let redeemProps = { let redeemProps = {
in_payment: true, in_payment: true,
...@@ -195,65 +195,87 @@ class UseBalance extends React.Component { ...@@ -195,65 +195,87 @@ class UseBalance extends React.Component {
if (parseInt(this.state.input_redeem) > parseInt(parseInt(this.state.kasproPoint) + parseInt(this.state.kasproBalance))) { if (parseInt(this.state.input_redeem) > parseInt(parseInt(this.state.kasproPoint) + parseInt(this.state.kasproBalance))) {
Alert.alert('', 'Maaf Balance dan Point tidak cukup') Alert.alert('', 'Maaf Balance dan Point tidak cukup')
} else { } else {
let params = { if (parseInt(this.state.kasproPoint) - parseInt(this.state.input_redeem) <= -1) {
session_id: this.props.session_id, // Alert.alert('masuk coy')
pin: this.state.pin, let params = {
balance: 0, session_id: this.props.session_id,
point: this.state.kasproPoint pin: this.state.pin,
} balance: parseInt(this.state.input_redeem) - parseInt(this.state.kasproPoint),
console.log(params) point: this.state.kasproPoint
}
console.log(params)
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/point/redeem', params).then(res => {
let respon = res.data
console.log("INI DATANYA " + respon)
// Alert.alert('', 'Sukses Redeem')
let redeemProps = {
in_payment: true,
redeem_code: respon.redeem_code,
balance_redeem: respon.use_balance,
point_redeem: respon.use_point
}
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/point/redeem', params).then(res => { this.props.setRedeem(redeemProps)
Alert.alert('', 'Sukses Redeem')
}).catch(error => { this.props.navigation.navigate('Redeem Code')
let response = error.response.data
if (response.code === "EMPTY_PIN") { }).catch(error => {
Alert.alert('Error', response.msg) let response = error.response.data
} else { if (response.code === "EMPTY_PIN") {
let response = error.response.data; Alert.alert('Error', response.msg)
Alert.alert('', response.msg); } else {
let response = error.response.data;
Alert.alert('', response.msg);
}
})
} 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 => {
let respon = res.data
console.log("INI DATANYA " + respon)
// Alert.alert('', 'Sukses Redeem')
let redeemProps = {
in_payment: true,
redeem_code: respon.redeem_code,
balance_redeem: respon.use_balance,
point_redeem: respon.use_point
}
}) this.props.setRedeem(redeemProps)
}
}
this.props.navigation.navigate('Redeem Code')
}).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);
}
})
}
}
}
// 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() { render() {
// console.log(parseInt(this.state.input_redeem) > parseInt(parseInt(this.state.kasproPoint) + parseInt(this.state.kasproBalance))) console.log(parseInt(this.state.kasproPoint) - parseInt(this.state.input_redeem))
return ( return (
<View style={styles.container}> <ScrollView style={styles.container}>
<Modal animationType="slide" <Modal animationType="slide"
transparent={false} transparent={false}
visible={this.state.modalVisible} visible={this.state.modalVisible}
...@@ -396,7 +418,7 @@ class UseBalance extends React.Component { ...@@ -396,7 +418,7 @@ class UseBalance extends React.Component {
</View> </View>
<View style={{ alignItems: 'center' }}> <View style={{ alignItems: 'center' }}>
{ {
this.state.input_redeem == 98 ? ( this.state.input_redeem != 0 ? (
<TouchableOpacity onPress={() => { <TouchableOpacity onPress={() => {
this.checkedSelection('balancepoint') this.checkedSelection('balancepoint')
}}> }}>
...@@ -434,14 +456,14 @@ class UseBalance extends React.Component { ...@@ -434,14 +456,14 @@ class UseBalance extends React.Component {
) )
} }
</View> </View>
<TouchableOpacity style={{ height: 100 }} onPress={() => this.redeem()}> <TouchableOpacity style={{ height: 150 }} onPress={() => this.redeem()}>
<View style={{ backgroundColor: '#CFB368', height: 40, top: 20, borderRadius: 10, marginRight: 50, marginLeft: 50 }}> <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> <Text style={{ alignSelf: 'center', top: 10, color: 'white', fontFamily: 'Gotham-Black', fontSize: 20 }}>REDEEM</Text>
</View> </View>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
</View> </View>
</View > </ScrollView >
) )
} }
} }
...@@ -529,7 +551,7 @@ const mapStateToProps = (state) => { ...@@ -529,7 +551,7 @@ const mapStateToProps = (state) => {
const mapDispatchToProps = (dispacth) => { const mapDispatchToProps = (dispacth) => {
return { return {
setRedeem: (redeemProps) => dispacth({ setRedeem: (redeemProps) => dispacth({
type: ActionType.SET_REEDEM, type: ActionType.SET_REEDEM,
data: { data: {
in_payment: redeemProps.in_payment, in_payment: redeemProps.in_payment,
......
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