Commit 3cfeaef7 authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo
parents b165c5d6 c03e6b0e
import ActionType from './globalActionType'; import ActionType from './globalActionType';
import {Alert} from 'react-native'; import { Alert } from 'react-native';
const globalState = { const globalState = {
...@@ -50,9 +50,9 @@ const globalState = { ...@@ -50,9 +50,9 @@ const globalState = {
outlet_id: '', outlet_id: '',
name_outlet: '', name_outlet: '',
type_pickup:true, type_pickup: true,
type_trans:'', type_trans: '',
quantity: 0, quantity: 0,
orders: 0, orders: 0,
...@@ -64,25 +64,25 @@ const globalState = { ...@@ -64,25 +64,25 @@ const globalState = {
order_quantity: 0, order_quantity: 0,
order_total: 0, order_total: 0,
address:'', address: '',
addressId:'', addressId: '',
grabtype:'', grabtype: '',
grabamount:'', grabamount: '',
grabpickup:'', grabpickup: '',
grabdropoff:'', grabdropoff: '',
grabdestination:'', grabdestination: '',
balanceUsed:'', balanceUsed: '',
pointused:'', pointused: '',
trans_id:'', trans_id: '',
lat:'', lat: '',
long:'', long: '',
voucher :[], voucher: [],
value_voucher:'' value_voucher: ''
} }
...@@ -286,7 +286,7 @@ const rootReducer = (state = globalState, action) => { ...@@ -286,7 +286,7 @@ const rootReducer = (state = globalState, action) => {
return { return {
...state, ...state,
address: action.data.address, address: action.data.address,
addressId:action.data.addressId addressId: action.data.addressId
} }
} }
case ActionType.SET_TRANS_ID: { case ActionType.SET_TRANS_ID: {
...@@ -507,7 +507,7 @@ const rootReducer = (state = globalState, action) => { ...@@ -507,7 +507,7 @@ const rootReducer = (state = globalState, action) => {
let addedItem = action.data.item let addedItem = action.data.item
let is_exist = state.order_item.find(item => addedItem.id == item.id) let is_exist = state.order_item.find(item => addedItem.id == item.id)
let new_items = state.order_item.filter(item=> addedItem.id !== item.id) let new_items = state.order_item.filter(item => addedItem.id !== item.id)
let order_item = [] let order_item = []
if (is_exist) { if (is_exist) {
// update // update
...@@ -554,7 +554,9 @@ const rootReducer = (state = globalState, action) => { ...@@ -554,7 +554,9 @@ const rootReducer = (state = globalState, action) => {
grabamount: 0, grabamount: 0,
outlet_id: '', outlet_id: '',
name_outlet: '', name_outlet: '',
address_id: '' address_id: '',
voucher: [],
value_voucher: ''
} }
} }
......
...@@ -48,6 +48,74 @@ class MenuConfirmation extends React.Component { ...@@ -48,6 +48,74 @@ class MenuConfirmation extends React.Component {
} }
// console.log(is_pickup) // console.log(is_pickup)
if (this.props.value == '') {
let params = {
session_id: this.props.session_id,
outlet_id: this.props.outlet_id,
address_id: this.props.addressId,
trans_type: this.state.type,
order_item: this.props.order_item,
delivery_charge: this.props.grabamount,
voucher: [],
payment: {
balance: this.props.route.params.balanceUsed,
point: this.props.route.params.pointused
}
}
console.log(params)
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/transaction/booking', params).then(res => {
let data_order = res.data.data.id
this.setState({
spinner: false,
})
let transIdProps = {
trans_id: data_order
}
this.props.setTransId(transIdProps);
// add API use voucher here
// let param = {
// session_id: this.props.session_id,
// reward_id: this.props.voucher.id,
// lat: this.props.lat,
// long: this.props.long
// }
// Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/reward/use_reward', param).then(res => {
// console.log(res.data)
// }).catch(error => {
// const { navigation } = this.props
// let response = error.response.data
// session(response, navigation)
// Alert.alert(response.msg);
// this.setState({
// spinner: false,
// })
// })
Alert.alert(
"Berhasil",
"Transaksi sudah berhasil, terimakasih sudah menggunakan excelso untuk ngopi",
[
{ text: "OK", onPress: () => this.orderSuccess() }
],
{ cancelable: false }
);
}).catch(error => {
const { navigation } = this.props
let response = error.response.data
session(response, navigation)
Alert.alert(response.msg);
this.setState({
spinner: false,
})
})
} else {
let params = { let params = {
session_id: this.props.session_id, session_id: this.props.session_id,
outlet_id: this.props.outlet_id, outlet_id: this.props.outlet_id,
...@@ -117,6 +185,7 @@ class MenuConfirmation extends React.Component { ...@@ -117,6 +185,7 @@ class MenuConfirmation extends React.Component {
}) })
}) })
} }
}
orderSuccess = () => { orderSuccess = () => {
this.props.setOrderFinish() this.props.setOrderFinish()
...@@ -168,7 +237,14 @@ class MenuConfirmation extends React.Component { ...@@ -168,7 +237,14 @@ class MenuConfirmation extends React.Component {
<Text>Voucher Discount</Text> <Text>Voucher Discount</Text>
</View> </View>
<View style={{ margin: 10 }}> <View style={{ margin: 10 }}>
{
this.props.value_voucher == '' ? (
<Text>0</Text>
) : (
<Text>{this.props.voucher.reward.value}</Text> <Text>{this.props.voucher.reward.value}</Text>
)
}
</View> </View>
</View> </View>
<View style={{ flexDirection: 'row', margin: 10, justifyContent: 'space-between' }}> <View style={{ flexDirection: 'row', margin: 10, justifyContent: 'space-between' }}>
...@@ -194,11 +270,24 @@ class MenuConfirmation extends React.Component { ...@@ -194,11 +270,24 @@ class MenuConfirmation extends React.Component {
</View> </View>
{this.props.type_pickup == true ? ( {this.props.type_pickup == true ? (
<View style={{ margin: 10 }}> <View style={{ margin: 10 }}>
{
this.props.value_voucher == '' ? (
<Text>{this.props.order_total}</Text>
) : (
<Text>{Math.max(0, this.props.order_total - this.props.voucher.reward.value)}</Text> <Text>{Math.max(0, this.props.order_total - this.props.voucher.reward.value)}</Text>
)
}
</View> </View>
) : ( ) : (
<View style={{ margin: 10 }}> <View style={{ margin: 10 }}>
{
this.props.value_voucher == '' ? (
<Text>{this.props.order_total + this.props.grabamount + this.state.diskon}</Text> <Text>{this.props.order_total + this.props.grabamount + this.state.diskon}</Text>
) : (
<Text>{Math.max(this.props.order_total + this.props.grabamount - this.props.voucher.reward.value)}</Text>
)
}
</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