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

ini yang terbaru

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