Commit 40157d4c authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

ini yang terbaru

parent e5d203f6
......@@ -58,7 +58,6 @@ const globalState = {
order_quantity: 0,
order_total: 0,
address:'',
addressId:'',
......@@ -244,6 +243,9 @@ const rootReducer = (state = globalState, action) => {
session_id: action.data.session_id,
}
}
case ActionType.ADD_TO_CHART: {
let addedItem = action.data.item
......@@ -355,6 +357,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 order_item = []
if (is_exist) {
// update
......@@ -371,17 +374,17 @@ const rootReducer = (state = globalState, action) => {
}
order_item = updated_data
let quantity = state.order_quantity
let total = parseInt(state.order_total) - parseInt(addedItem.price)
console.log("UPDATE " + order_item)
}
return {
...state,
order_item: order_item,
order_quantity: quantity,
order_total: total
order_item: new_items,
}
}
default:
return state;
}
......
......@@ -166,6 +166,7 @@ class Auth extends React.Component {
<Stack.Screen name="Menu Select" component={MenuSelection} />
<Stack.Screen name="Card Info" component={CardInfo} />
<Stack.Screen name="Shopping Cart" component={ShoppingCart} />
<Stack.Screen name="Order History" component={OrderHistory} />
</>
)
......
......@@ -44,7 +44,8 @@ class MenuConfirmation extends React.Component {
}
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/transaction/booking', params).then(res => {
Alert.alert(res.data.status, 'Transaksi Berhasil')
Alert.alert( 'Transaksi Anda Berhasil')
this.props.navigation.navigate('Order History');
// console.log(res.data.data)
}).catch(error => {
......
......@@ -120,16 +120,19 @@ class MenuSelection extends React.Component {
price: parseInt(item.price),
}
this.props.addToChart(order_item)
let res = this.props.addToChart(order_item)
// console.log('After add : ' + JSON.stringify(res))
const list_order_item = this.props.order_item;
let is_xist = list_order_item.find(row => row.id == item.id)
let quantity = 0
let quantity = 1
if (is_xist) {
console.log(is_xist.name + ' Item Sudah ada dengan quantity : ' + is_xist.quantity)
quantity = is_xist.quantity
}
const listMenu = [...this.state.listMenu]
listMenu[index].qty = quantity
console.log("HASIL : " + listMenu[index].qty)
......@@ -168,18 +171,23 @@ class MenuSelection extends React.Component {
}
this.props.reduceQuantityItem(order_item)
let quantity = 0
for (let i = 0; i < list_order_item.length; i++) {
const row = list_order_item[i];
if (row.id == item.id) {
quantity = row.quantity
}
// let quantity = 0
console.log("INI TEST YA" + is_xist.quantity)
const listMenu = [...this.state.listMenu]
listMenu[index].qty = quantity
listMenu[index].qty = is_xist.quantity
this.setState({
listMenu
})
}
// for (let i = 0; i < list_order_item.length; i++) {
// const row = list_order_item[i];
// if (row.id == item.id) {
// quantity = row.quantity
// }
// }
}
}
}
......
import React from 'react';
import { View, Text, TextInput, StyleSheet, Button, TouchableOpacity, ScrollView, FlatList, Image } from 'react-native';
import { View, Text, TextInput, StyleSheet, Button, TouchableOpacity, ScrollView, FlatList, Image, Alert } from 'react-native';
import { connect } from 'react-redux'
// import { CheckBox } from 'react-native-elements'
import CheckBox from 'react-native-check-box'
......@@ -28,7 +28,7 @@ class ShoppingCart extends React.Component {
diskon: 0,
isDelivery: false,
isPickUp: false,
order_item: this.props.order_item,
// order_item: this.props.order_item,
grabtype: '',
grabamount: '',
grabpickup: '',
......@@ -58,10 +58,15 @@ class ShoppingCart extends React.Component {
}
}
handleMin(item, index) {
console.log("hai")
const list_order_item = this.props.order_item;
console.log('wakwaw')
let is_xist = list_order_item.find(row => row.id == item.id)
console.log('next')
console.log(JSON.stringify(is_xist))
if (is_xist) {
if (is_xist.quantity != 0) {
const order_item = {
......@@ -75,25 +80,47 @@ class ShoppingCart extends React.Component {
let quantity = 0
for (let i = 0; i < list_order_item.length; i++) {
const row = list_order_item[i];
const qty = list_order_item[i];
if (row.id == item.id) {
quantity = row.quantity
}
}
}else if (is_xist.quantity === 0){
if (quantity == 0) {
const order_item = {
id: item.id,
name: item.name,
price: item.price,
note: item.note,
image: item.image,
description: item.description,
quantity: item.quantity
}
this.props.reduceQuantityItem(order_item)
this.props.removeFromChart(order_item)
// this.props.navigation.navigate('Home', {
// screen: 'Menu Select',
// });
}
}
// else if (is_xist.quantity == 0){
// Alert.alert("Apakah anda akan menghapus pesanan ?")
// const order_item = {
// id: item.id,
// name: item.name,
// price: item.price,
// note: item.note,
// image: item.image,
// description: item.description,
// quantity: item.quantity
// }
// this.props.removeFromChart(order_item)
// console.log(order_item)
// }
}
}
handleAdd(item, index) {
......@@ -111,7 +138,7 @@ class ShoppingCart extends React.Component {
const list_order_item = this.props.order_item;
let is_xist = list_order_item.find(row => row.id == item.id)
console.log("INI YA : "+is_xist)
console.log("INI YA : " + is_xist)
let quantity = 0
if (is_xist) {
......@@ -162,35 +189,32 @@ class ShoppingCart extends React.Component {
componentDidMount() {
this.getBalance()
this.getRate()
console.log("INI PROPS"+ this.props.address)
}
getRate() {
let params = {
session_id: this.props.session_id,
outlet_id: this.props.outlet_id,
address_id: this.props.addressId,
order_item: this.props.order_item
}
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/delivery/rate', params).then(res => {
console.log("INI LHO CUY : " + JSON.stringify(res.data.data.destination.address))
console.log("INI LHO CUY : " + JSON.stringify(res.data.data.outlet_name))
this.setState({
grabtype: res.data.data.quotes[0].service.type,
grabamount: res.data.data.quotes[0].amount,
grabpickup: res.data.data.quotes[0].estimatedTimeline.pickup,
grabdropoff: res.data.data.quotes[0].estimatedTimeline.dropoff,
grabdestination: res.data.data.destination.address,
grabamount: res.data.data.amount,
grabdestination: res.data.data.outlet_name,
})
let setGrabProps = {
grabtype: this.state.grabtype,
grabamount: this.state.grabamount,
grabpickup: this.state.grabpickup,
grabdropoff: this.state.grabdropoff,
// grabtype: this.state.grabtype,
// grabpickup: this.state.grabpickup,
// grabdropoff: this.state.grabdropoff,
grabdestination: this.state.grabdestination,
grabamount: this.state.grabamount,
}
this.props.setGrab(setGrabProps);
......@@ -205,7 +229,6 @@ class ShoppingCart extends React.Component {
}).catch(error => {
console.log('ini error ' + error)
})
}
getBalance() {
......@@ -244,7 +267,7 @@ class ShoppingCart extends React.Component {
this.state.isDelivery == true ? (
<Card style={{ margin: 5, padding: 10 }}>
<Text style={{ textAlign: 'center' }}> Ambil pesanan kamu di</Text>
<Text style={{ textAlign: 'center' }}>{this.props.address}</Text>
<Text style={{ textAlign: 'center' }}>{this.props.grabdestination}</Text>
</Card>
) : (
......@@ -263,7 +286,7 @@ class ShoppingCart extends React.Component {
</View>
<View style={styles.order}>
<FlatList
data={this.state.order_item}
data={this.props.order_item}
renderItem={({ item, index }) => (
<ItemShoping navigation={this.props.navigation}
item={item}
......@@ -457,7 +480,7 @@ class ShoppingCart extends React.Component {
<Text style={{ fontSize: 35, color: '#ccb46c' }}>Total</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>
<View style={{ flexDirection: 'row', marginTop: 10, justifyContent: 'space-between' }}>
......@@ -665,8 +688,8 @@ const mapStateToProps = (state) => {
grabtype: state.grabtype,
grabamount: state.grabamount,
grabpickup: state.grabpickup,
grabdropoff:state.grabdropoff,
grabdestination:state.grabdestination,
grabdropoff: state.grabdropoff,
grabdestination: state.grabdestination,
}
}
......
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