Commit 30e1d19e authored by Trisno's avatar Trisno

update shopping cart

parent 2ef8194c
......@@ -29,16 +29,14 @@ class ShoppingCart extends React.Component {
pointsused: 0,
ongkir: 0,
diskon: 0,
isDelivery: false,
isPickUp: false,
// order_item: this.props.order_item,
grabtype: '',
grabamount: '',
grabpickup: '',
grabdropoff: '',
grabdestination: '',
my_lat:0,
my_long:0
my_lat: 0,
my_long: 0
// dummyBalance : 155000,
// dummyPoint : 20000
}
......@@ -48,20 +46,30 @@ class ShoppingCart extends React.Component {
checkChangeTrans(val) {
console.log('hai lg di sini')
console.log(val)
if (val == 'delivery') {
let typeProps = {
type_pickup: false,
}
this.props.setTypePickup(typeProps);
this.setState({
isDelivery: true,
isPickUp: false
checkedBalance: false,
checkedPoint: false,
checkedBalancePoint: false,
pointsused: 0,
balanceused: 0
})
console.log('ini delivery')
} else {
let typeProps = {
type_pickup: true,
}
this.props.setTypePickup(typeProps);
this.setState({
isPickUp: true,
isDelivery: false
checkedBalance: false,
checkedPoint: false,
checkedBalancePoint: false,
pointsused: 0,
balanceused: 0
})
console.log('ini pickup')
}
}
......@@ -156,6 +164,15 @@ class ShoppingCart extends React.Component {
checkedSelection(val) {
// console.log(val)
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({
checkedBalance: true,
checkedPoint: false,
......@@ -163,7 +180,17 @@ class ShoppingCart extends React.Component {
balanceused: this.props.order_total + this.props.grabamount,
pointsused: 0
})
}
} 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({
checkedBalance: false,
checkedPoint: true,
......@@ -171,14 +198,26 @@ class ShoppingCart extends React.Component {
pointsused: this.props.order_total + this.props.grabamount,
balanceused: 0
})
}
} else {
this.setState({
checkedBalance: false,
checkedPoint: false,
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) {
this.setState({
pointsused: this.props.order_total + this.props.grabamount
......@@ -191,6 +230,7 @@ class ShoppingCart extends React.Component {
}
}
}
}
componentDidMount() {
this._getPermissions()
......@@ -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 })
}
}
getBalance() {
......@@ -310,11 +351,11 @@ class ShoppingCart extends React.Component {
</View>
<View style={{ alignItems: 'center' }}>
{
this.state.isDelivery == true ? (
this.props.type_pickup == true ? (
<TouchableOpacity >
<Card style={{ margin: 5, padding: 10 }}>
<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>
</TouchableOpacity>
......@@ -513,7 +554,7 @@ class ShoppingCart extends React.Component {
</View>
{this.props.type_pickup == true ? (
null
):(
) : (
<View style={{ flexDirection: 'row', marginTop: 10, justifyContent: 'space-between' }}>
<View>
......@@ -540,9 +581,9 @@ class ShoppingCart extends React.Component {
<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>
</View>
): (
) : (
<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>
......@@ -555,7 +596,7 @@ class ShoppingCart extends React.Component {
</View>
</View>
<View style={{ margin: 20, }}>
<Button title='Checkout' color='#ccb46c' onPress={() => this.checkOut() } />
<Button title='Checkout' color='#ccb46c' onPress={() => this.checkOut()} />
</View>
</View>
</ScrollView>
......@@ -734,12 +775,20 @@ const mapDispatchToProps = (dispacth) => {
pointused: setOrdersProps.pointused,
}
}),
setTypePickup: (typeProps) => dispacth({
type: ActionType.SET_TYPE,
data: {
type_pickup: typeProps.type_pickup
}
}),
}
}
const mapStateToProps = (state) => {
return {
type_pickup : state.type_pickup,
type_pickup: state.type_pickup,
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