Commit c03e6b0e authored by Trisno's avatar Trisno

update fix error

parent c5f58433
import ActionType from './globalActionType';
import {Alert} from 'react-native';
import { Alert } from 'react-native';
const globalState = {
......@@ -50,9 +50,9 @@ const globalState = {
outlet_id: '',
name_outlet: '',
type_pickup:true,
type_trans:'',
type_pickup: true,
type_trans: '',
quantity: 0,
orders: 0,
......@@ -64,26 +64,26 @@ const globalState = {
order_quantity: 0,
order_total: 0,
address:'',
addressId:'',
address: '',
addressId: '',
grabtype: '',
grabamount: '',
grabpickup: '',
grabdropoff: '',
grabdestination: '',
grabtype:'',
grabamount:'',
grabpickup:'',
grabdropoff:'',
grabdestination:'',
balanceUsed: '',
pointused: '',
balanceUsed:'',
pointused:'',
trans_id: '',
trans_id:'',
lat: '',
long: '',
lat:'',
long:'',
voucher: [],
value_voucher: ''
voucher :[],
value_voucher:''
}
const rootReducer = (state = globalState, action) => {
......@@ -146,7 +146,7 @@ const rootReducer = (state = globalState, action) => {
type_trans: action.data.type_trans
}
}
case ActionType.SET_DEVICE_INFO: {
return {
...state,
......@@ -286,7 +286,7 @@ const rootReducer = (state = globalState, action) => {
return {
...state,
address: action.data.address,
addressId:action.data.addressId
addressId: action.data.addressId
}
}
case ActionType.SET_TRANS_ID: {
......@@ -301,7 +301,7 @@ const rootReducer = (state = globalState, action) => {
session_id: action.data.session_id,
}
}
case ActionType.ADD_TO_CHART: {
let addedItem = action.data.item
......@@ -380,7 +380,7 @@ const rootReducer = (state = globalState, action) => {
if (update.quantity == NaN) {
update.quantity = 1
}
console.log('Update : ' + JSON.stringify(update))
data = { ...old_data, ...update }
}
......@@ -395,7 +395,7 @@ const rootReducer = (state = globalState, action) => {
}
let quantity = state.order_quantity
let menu_item = []
......@@ -439,7 +439,7 @@ const rootReducer = (state = globalState, action) => {
}
if (update.quantity == 0) {
update.quantity = 0
} else {
......@@ -459,12 +459,12 @@ const rootReducer = (state = globalState, action) => {
}
}
order_item = updated_data
// } else {
// // add
// addedItem.quantity = 1
// } else {
// // add
// addedItem.quantity = 1
// console.log('Baru : ' + JSON.stringify(addedItem))
// order_item = [...state.order_item, addedItem]
// console.log('Baru : ' + JSON.stringify(addedItem))
// order_item = [...state.order_item, addedItem]
}
// if (state.order_quantity === 0 && state.order_total === 0) {
......@@ -507,7 +507,7 @@ const rootReducer = (state = globalState, action) => {
let addedItem = action.data.item
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 = []
if (is_exist) {
// update
......@@ -541,7 +541,7 @@ const rootReducer = (state = globalState, action) => {
order_total: action.data.order_total,
order_quantity: action.data.order_quantity,
order_item: action.data.order_item
}
}
case ActionType.SET_ORDER_FINISH: {
......@@ -554,8 +554,10 @@ const rootReducer = (state = globalState, action) => {
grabamount: 0,
outlet_id: '',
name_outlet: '',
address_id: ''
address_id: '',
voucher: [],
value_voucher: ''
}
}
case ActionType.UPDATE_MENU: {
......@@ -568,13 +570,13 @@ const rootReducer = (state = globalState, action) => {
for (let i = 0; i < state.order_item.length; i++) {
const row = state.order_item[i];
let is_updated = menu.find(item => item.id == row.id)
// Update Price in Cart
if (is_updated) {
row.price = parseInt(is_updated.price)
}
}
quantity += parseInt(row.quantity)
total += parseInt(row.price) * parseInt(row.quantity)
......@@ -588,24 +590,24 @@ const rootReducer = (state = globalState, action) => {
// cari sudah ada belum di redux
let is_xist = list_item.find(item => row.id == item.id)
if (is_xist) {
row['qty'] = is_xist.quantity
row['qty'] = is_xist.quantity
} else {
row['qty'] = 0
row['qty'] = 0
}
if (last_category != row.category.name) {
let category = {
"id": row.category.id,
"name": row.category.name,
"code": "CATEGORY"
}
list_menu.push(category)
list_menu.push(row)
last_category = row.category.name
let category = {
"id": row.category.id,
"name": row.category.name,
"code": "CATEGORY"
}
list_menu.push(category)
list_menu.push(row)
last_category = row.category.name
} else {
list_menu.push(row)
list_menu.push(row)
}
}
}
return {
...state,
......@@ -613,7 +615,7 @@ const rootReducer = (state = globalState, action) => {
order_total: total,
order_quantity: quantity,
order_item: list_item,
}
}
......@@ -626,18 +628,18 @@ const rootReducer = (state = globalState, action) => {
let list_menu = []
let list_item = []
if (!isNaN(parseInt(new_quantity))) {
if (!isNaN(parseInt(new_quantity))) {
console.log('Number : ' + parseInt(new_quantity))
exist = false
for (let i = 0; i < state.order_item.length; i++) {
const row = state.order_item[i];
if (row.id == item.id) {
// Update Price in Cart
// Update Price in Cart
row.quantity = parseInt(new_quantity)
exist = true
}
}
if (row.quantity > 0) {
quantity += parseInt(row.quantity)
......
......@@ -48,74 +48,143 @@ class MenuConfirmation extends React.Component {
}
// console.log(is_pickup)
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: [{
value: this.props.voucher.reward.value,
verification_number: this.props.voucher.verification_number
}],
payment: {
balance: this.props.route.params.balanceUsed,
point: this.props.route.params.pointused
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)
console.log(params)
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/transaction/booking', params).then(res => {
let data_order = res.data.data.id
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/transaction/booking', params).then(res => {
let data_order = res.data.data.id
this.setState({
spinner: false,
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,
})
})
let transIdProps = {
trans_id: data_order
} else {
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: [{
value: this.props.voucher.reward.value,
verification_number: this.props.voucher.verification_number
}],
payment: {
balance: this.props.route.params.balanceUsed,
point: this.props.route.params.pointused
}
}
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,
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,
})
})
})
}
}
orderSuccess = () => {
......@@ -168,7 +237,14 @@ class MenuConfirmation extends React.Component {
<Text>Voucher Discount</Text>
</View>
<View style={{ margin: 10 }}>
<Text>{this.props.voucher.reward.value}</Text>
{
this.props.value_voucher == '' ? (
<Text>0</Text>
) : (
<Text>{this.props.voucher.reward.value}</Text>
)
}
</View>
</View>
<View style={{ flexDirection: 'row', margin: 10, justifyContent: 'space-between' }}>
......@@ -194,11 +270,24 @@ class MenuConfirmation extends React.Component {
</View>
{this.props.type_pickup == true ? (
<View style={{ margin: 10 }}>
<Text>{Math.max(0, this.props.order_total - this.props.voucher.reward.value)}</Text>
{
this.props.value_voucher == '' ? (
<Text>{this.props.order_total}</Text>
) : (
<Text>{Math.max(0, this.props.order_total - this.props.voucher.reward.value)}</Text>
)
}
</View>
) : (
<View style={{ margin: 10 }}>
<Text>{this.props.order_total + this.props.grabamount + this.state.diskon}</Text>
{
this.props.value_voucher == '' ? (
<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>
)}
......
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