Commit 30e1d19e authored by Trisno's avatar Trisno

update shopping cart

parent 2ef8194c
...@@ -29,16 +29,14 @@ class ShoppingCart extends React.Component { ...@@ -29,16 +29,14 @@ class ShoppingCart extends React.Component {
pointsused: 0, pointsused: 0,
ongkir: 0, ongkir: 0,
diskon: 0, diskon: 0,
isDelivery: false,
isPickUp: false,
// order_item: this.props.order_item, // order_item: this.props.order_item,
grabtype: '', grabtype: '',
grabamount: '', grabamount: '',
grabpickup: '', grabpickup: '',
grabdropoff: '', grabdropoff: '',
grabdestination: '', grabdestination: '',
my_lat:0, my_lat: 0,
my_long:0 my_long: 0
// dummyBalance : 155000, // dummyBalance : 155000,
// dummyPoint : 20000 // dummyPoint : 20000
} }
...@@ -48,20 +46,30 @@ class ShoppingCart extends React.Component { ...@@ -48,20 +46,30 @@ class ShoppingCart extends React.Component {
checkChangeTrans(val) { checkChangeTrans(val) {
console.log('hai lg di sini')
console.log(val)
if (val == 'delivery') { if (val == 'delivery') {
let typeProps = {
type_pickup: false,
}
this.props.setTypePickup(typeProps);
this.setState({ this.setState({
isDelivery: true, checkedBalance: false,
isPickUp: false checkedPoint: false,
checkedBalancePoint: false,
pointsused: 0,
balanceused: 0
}) })
console.log('ini delivery')
} else { } else {
let typeProps = {
type_pickup: true,
}
this.props.setTypePickup(typeProps);
this.setState({ this.setState({
isPickUp: true, checkedBalance: false,
isDelivery: false checkedPoint: false,
checkedBalancePoint: false,
pointsused: 0,
balanceused: 0
}) })
console.log('ini pickup')
} }
} }
...@@ -156,6 +164,15 @@ class ShoppingCart extends React.Component { ...@@ -156,6 +164,15 @@ class ShoppingCart extends React.Component {
checkedSelection(val) { checkedSelection(val) {
// console.log(val) // console.log(val)
if (val == 'balance') { if (val == 'balance') {
if (this.props.type_pickup == true) {
this.setState({
checkedBalance: true,
checkedPoint: false,
checkedBalancePoint: false,
balanceused: this.props.order_total,
pointsused: 0
})
} else {
this.setState({ this.setState({
checkedBalance: true, checkedBalance: true,
checkedPoint: false, checkedPoint: false,
...@@ -163,7 +180,17 @@ class ShoppingCart extends React.Component { ...@@ -163,7 +180,17 @@ class ShoppingCart extends React.Component {
balanceused: this.props.order_total + this.props.grabamount, balanceused: this.props.order_total + this.props.grabamount,
pointsused: 0 pointsused: 0
}) })
}
} else if (val == 'point') { } else if (val == 'point') {
if (this.props.type_pickup == true) {
this.setState({
checkedBalance: false,
checkedPoint: true,
checkedBalancePoint: false,
pointsused: this.props.order_total,
balanceused: 0
})
} else {
this.setState({ this.setState({
checkedBalance: false, checkedBalance: false,
checkedPoint: true, checkedPoint: true,
...@@ -171,14 +198,26 @@ class ShoppingCart extends React.Component { ...@@ -171,14 +198,26 @@ class ShoppingCart extends React.Component {
pointsused: this.props.order_total + this.props.grabamount, pointsused: this.props.order_total + this.props.grabamount,
balanceused: 0 balanceused: 0
}) })
}
} else { } else {
this.setState({ this.setState({
checkedBalance: false, checkedBalance: false,
checkedPoint: false, checkedPoint: false,
checkedBalancePoint: true, checkedBalancePoint: true,
// balanceused : this.props.order_total - this.state.dummyPoint,
// pointsused : this.props.order_total,
}) })
if (this.props.type_pickup == true) {
if (this.state.kasproPoint - this.props.order_total >= -1) {
this.setState({
pointsused: this.props.order_total
})
} else {
this.setState({
balanceused: this.props.order_total - this.state.kasproPoint,
pointsused: this.state.kasproPoint
})
}
} else {
if (this.state.kasproPoint - (this.props.order_total + this.props.grabamount) >= -1) { if (this.state.kasproPoint - (this.props.order_total + this.props.grabamount) >= -1) {
this.setState({ this.setState({
pointsused: this.props.order_total + this.props.grabamount pointsused: this.props.order_total + this.props.grabamount
...@@ -191,6 +230,7 @@ class ShoppingCart extends React.Component { ...@@ -191,6 +230,7 @@ class ShoppingCart extends React.Component {
} }
} }
} }
}
componentDidMount() { componentDidMount() {
this._getPermissions() this._getPermissions()
...@@ -267,11 +307,12 @@ class ShoppingCart extends React.Component { ...@@ -267,11 +307,12 @@ class ShoppingCart extends React.Component {
}) })
} }
checkOut(){ checkOut() {
if (this.state.checkedBalance == false && this.state.checkedPoint == false && this.state.checkedBalancePoint == false) {
Alert.alert('Error', 'Please insert payment methods')
} else {
this.props.navigation.navigate('Confirm Your Order', { balanceUsed: this.state.balanceused, pointused: this.state.pointsused }) this.props.navigation.navigate('Confirm Your Order', { balanceUsed: this.state.balanceused, pointused: this.state.pointsused })
}
} }
getBalance() { getBalance() {
...@@ -310,11 +351,11 @@ class ShoppingCart extends React.Component { ...@@ -310,11 +351,11 @@ class ShoppingCart extends React.Component {
</View> </View>
<View style={{ alignItems: 'center' }}> <View style={{ alignItems: 'center' }}>
{ {
this.state.isDelivery == true ? ( this.props.type_pickup == true ? (
<TouchableOpacity > <TouchableOpacity >
<Card style={{ margin: 5, padding: 10 }}> <Card style={{ margin: 5, padding: 10 }}>
<Text style={{ textAlign: 'center' }}> Ambil pesanan kamu di</Text> <Text style={{ textAlign: 'center' }}> Ambil pesanan kamu di</Text>
<Text style={{ textAlign: 'center' }}>{this.props.name_outlet}</Text> <Text style={{ textAlign: 'center', fontSize: 12, top: 5, fontWeight: 'bold' }}>Excelso {this.props.name_outlet}</Text>
</Card> </Card>
</TouchableOpacity> </TouchableOpacity>
...@@ -513,7 +554,7 @@ class ShoppingCart extends React.Component { ...@@ -513,7 +554,7 @@ class ShoppingCart extends React.Component {
</View> </View>
{this.props.type_pickup == true ? ( {this.props.type_pickup == true ? (
null null
):( ) : (
<View style={{ flexDirection: 'row', marginTop: 10, justifyContent: 'space-between' }}> <View style={{ flexDirection: 'row', marginTop: 10, justifyContent: 'space-between' }}>
<View> <View>
...@@ -540,9 +581,9 @@ class ShoppingCart extends React.Component { ...@@ -540,9 +581,9 @@ class ShoppingCart extends React.Component {
<View style={{ marginTop: 15, paddingRight: 30, paddingTop: 10, alignItems: 'flex-end' }}> <View style={{ marginTop: 15, paddingRight: 30, paddingTop: 10, alignItems: 'flex-end' }}>
<Text style={{ fontSize: 35, color: '#ccb46c' }}>{this.props.order_total + this.state.diskon}</Text> <Text style={{ fontSize: 35, color: '#ccb46c' }}>{this.props.order_total + this.state.diskon}</Text>
</View> </View>
): ( ) : (
<View style={{ marginTop: 15, paddingRight: 30, paddingTop: 10, alignItems: 'flex-end' }}> <View style={{ marginTop: 15, paddingRight: 30, paddingTop: 10, alignItems: 'flex-end' }}>
<Text style={{ fontSize: 35, color: '#ccb46c' }}>{this.props.order_total +this.props.grabamount + this.state.diskon }</Text> <Text style={{ fontSize: 35, color: '#ccb46c' }}>{this.props.order_total + this.props.grabamount + this.state.diskon}</Text>
</View> </View>
)} )}
</View> </View>
...@@ -555,7 +596,7 @@ class ShoppingCart extends React.Component { ...@@ -555,7 +596,7 @@ class ShoppingCart extends React.Component {
</View> </View>
</View> </View>
<View style={{ margin: 20, }}> <View style={{ margin: 20, }}>
<Button title='Checkout' color='#ccb46c' onPress={() => this.checkOut() } /> <Button title='Checkout' color='#ccb46c' onPress={() => this.checkOut()} />
</View> </View>
</View> </View>
</ScrollView> </ScrollView>
...@@ -734,12 +775,20 @@ const mapDispatchToProps = (dispacth) => { ...@@ -734,12 +775,20 @@ const mapDispatchToProps = (dispacth) => {
pointused: setOrdersProps.pointused, pointused: setOrdersProps.pointused,
} }
}), }),
setTypePickup: (typeProps) => dispacth({
type: ActionType.SET_TYPE,
data: {
type_pickup: typeProps.type_pickup
}
}),
} }
} }
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
return { return {
type_pickup : state.type_pickup, type_pickup: state.type_pickup,
session_id: state.session_id, session_id: state.session_id,
outlet_id: state.outlet_id, outlet_id: state.outlet_id,
name_outlet: state.name_outlet, 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