Commit 695c4393 authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

change menu selection

parent 6e3f99c0
......@@ -6,15 +6,10 @@ class ItemShoping extends React.Component {
render() {
const { item } = this.props
console.log("ini id itemnya "+item.id)
return (
<View style={{ flex: 1, margin: 10 }} key={item.id} ref={this.props._scrollView}>
<ScrollView ref={view => this._scrollView = view}>
{item.code == 'CATEGORY' ? (
<Text style={{ fontSize: 20, color: '#c9af6d' }}>{item.name}</Text>
): (
<View style={{ flex: 1, margin: 10 }} key={item.id}>
{/* <Text style={{ fontSize: 20, color: '#c9af6d' }}>{item.name}</Text> */}
<View style={{ flexDirection: 'row' }}>
<View >
<Image source={{ uri: item.image }} style={{ height: 100, width: 100, borderRadius: 5, top: 5 }}></Image>
......@@ -31,7 +26,7 @@ class ItemShoping extends React.Component {
<TextInput
style={{ height: 25, padding: 2, textAlign: 'center', margin: 2 }}
autoCapitalize="none">
{item.qty}
{item.quantity}
</TextInput>
<TouchableOpacity onPress={() => this.props.handleAdd()}>
<Text style={{ fontSize: 20, margin: 2 }}> + </Text>
......@@ -40,9 +35,6 @@ class ItemShoping extends React.Component {
</View>
</View>
</View>
)}
</ScrollView>
</View>
)
}
......@@ -111,4 +103,4 @@ const mapStateToProps = (state) => {
}
}
export default connect(mapStateToProps)(Item)
export default connect(mapStateToProps)(ItemShoping)
......@@ -5,9 +5,6 @@ import Item from './Item';
import { connect } from 'react-redux';
import ActionType from '../redux/globalActionType';
import CurrencyFormat from 'react-currency-format';
import Constants from "expo-constants";
import { Ionicons, MaterialCommunityIcons, MaterialIcons, AntDesign } from '@expo/vector-icons';
// import { range } from 'lodash';
import _ from 'lodash';
class MenuSelection extends React.Component {
......@@ -26,9 +23,6 @@ class MenuSelection extends React.Component {
}
componentDidMount() {
this.getMenuList()
// console.log("INI TOTAL ORDER : " + this.props.orders)
// console.log("INI TOTAL QTY :" + this.props.quantity)
console.log("INI OETLET :" + JSON.stringify(this.props.outlet_id))
}
getMenuList() {
......@@ -44,11 +38,9 @@ class MenuSelection extends React.Component {
listMenu: data.menu
})
let last_category = ''
let list_menu = []
for (let i = 0; i < data.menu.length; i++) {
const row = data.menu[i];
......@@ -74,11 +66,6 @@ class MenuSelection extends React.Component {
list_menu.push(row)
}
}
// this.state.listMenu.map((i => {
// i.qty = 0
// }))
console.log('After : ' + JSON.stringify(list_menu))
this.setState({
listMenu: list_menu
})
......@@ -116,47 +103,35 @@ class MenuSelection extends React.Component {
// }
scrollToItem = () => {
// let newData = []
// newData.push(this.state.listMenu)
// console.log("DATA " + JSON.stringify(newData))
// newData.map((item => {
// let abc = item[0].category
// }))
this.props._scrollView.scrollTo({ y: 1 * 100 });
}
handleAdd(item, index) {
console.log('TAMPILIN NIH')
const order_item = {
id: item.id,
code:item.code,
name: item.name,
description: item.description,
note:'jangan garing',
price: item.price,
image: item.image
}
this.props.addToChart(order_item)
// console.log("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 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
// }
// }
if (is_xist) {
quantity = is_xist.quantity
}
const listMenu = [...this.state.listMenu]
// console.log("INI COY YYYY QUANTITY " + quantity)
listMenu[index].qty = quantity
this.setState({
listMenu
......@@ -173,7 +148,6 @@ class MenuSelection extends React.Component {
id: item.id,
name: item.name,
price: item.price,
}
this.props.reduceQuantityItem(order_item)
}
......@@ -280,7 +254,7 @@ const styles = StyleSheet.create({
})
const mapStateToProps = (state) => {
console.log(state)
return {
session_id: state.session_id,
outlet_id: state.outlet_id,
......
......@@ -7,7 +7,11 @@ import { Card } from 'react-native-shadow-cards'
import { Entypo, Ionicons, MaterialCommunityIcons, MaterialIcons, AntDesign, FontAwesome } from '@expo/vector-icons'
import i18n from 'i18n-js';
import CurrencyFormat from 'react-currency-format';
import ItemShoping from './ItemShopingCart';
import Axios from 'axios'
import ActionType from '../redux/globalActionType';
import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['VirtualizedLists should never be nested']);
class ShoppingCart extends React.Component {
constructor(props) {
......@@ -23,39 +27,13 @@ class ShoppingCart extends React.Component {
ongkir: 0,
diskon: 0,
isDelivery: false,
isPickUp: false
isPickUp: false,
order_item: this.props.order_item
// dummyBalance : 155000,
// dummyPoint : 20000
}
}
minusQty(item, index) {
const listMenu = [...this.state.listMenu]
let hasil = [];
if (listMenu[index].qty !== 0) {
listMenu[index].qty -= 1
this.setState({
listMenu
})
// hasil.push(listMenu[index].qty);
// console.log("INI HASILNYA : " + JSON.stringify(hasil))
}
}
plusQty(item, index) {
this.setState({
shopingCart: item
})
const listMenu = [...this.state.listMenu]
listMenu[index].qty += 1
this.setState({
listMenu,
})
}
checkChangeTrans(val) {
console.log('hai lg di sini')
......@@ -74,58 +52,75 @@ class ShoppingCart extends React.Component {
console.log('ini pickup')
}
}
handleAdd(item, index) {
handleMin(item, index) {
const list_order_item = this.props.order_item;
let is_xist = list_order_item.find(row => row.id == item.id)
if (is_xist) {
if (is_xist.quantity != 0) {
const order_item = {
id: item.id,
name: item.name,
price: item.price,
image: item.image
}
this.props.addToChart(order_item)
}
this.props.reduceQuantityItem(order_item)
const list_order_item = this.props.order_item;
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
}
}
const listMenu = [...this.state.listMenu]
listMenu[index].qty = quantity
this.setState({
listMenu
})
}
} else if (is_xist.quantity == 0) {
const order_item = {
id: item.id,
name: item.name,
price: item.price,
}
this.props.removeFromChart(order_item)
}
}
}
handleAdd(item, index) {
handleMin(item, index) {
const order_item = {
id: item.id,
code:item.code,
name: item.name,
description: item.description,
note:'jangan garing',
price: item.price,
image: item.image
}
this.props.reduceQuantityItem(order_item)
this.props.addToChart(order_item)
const list_order_item = this.props.order_item;
let is_xist = list_order_item.find(row => row.id == item.id)
let quantity = 0
if (quantity != 0) {
quantity = quantity - 1
for (let i = 0; i < list_order_item.length; i++) {
const row = list_order_item[i];
if (row.id == item.id) {
quantity = row.quantity
}
if (is_xist) {
quantity = is_xist.quantity
}
const listMenu = [...this.state.listMenu]
listMenu[index].qty = quantity
this.setState({
listMenu
})
}
}
checkedSelection(val) {
// console.log(val)
......@@ -171,7 +166,80 @@ class ShoppingCart extends React.Component {
}
componentDidMount() {
this.getMenuList()
this.getBalance()
// this.getRate()
console.log(" INI RESPONNYA : " +JSON.stringify(this.props.order_item))
}
getMenuList() {
let params = {
outlet_id: "dec1abbb-95d0-46ae-a6cd-2bf306590f15"
}
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/menu/get_list', params).then(res => {
let data = res.data.data
this.setState({
listCategory: data.category,
listMenu: data.menu
})
let last_category = ''
let list_menu = []
for (let i = 0; i < data.menu.length; i++) {
const row = data.menu[i];
// cari sudah ada belum di redux
let is_xist = this.props.order_item.find(item => row.id == item.id)
if (is_xist) {
row['qty'] = is_xist.quantity
} else {
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
} else {
list_menu.push(row)
}
}
this.setState({
listMenu: list_menu
})
})
}
getRate() {
let params = {
session_id: this.props.session_id,
outlet_id: '0cb81ffe0c8242bea42d39c9b92ccaac',
address_id: 'bf06f7e939134f058887b312f8f93435',
order_item: this.props.order_item
}
console.log("INI PARAMETER : " + params);
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/delivery/rate', params).then(res => {
console.log("INI : " + res.data)
}).catch(error => {
console.log('ini error ' + error)
})
}
getBalance() {
......@@ -213,8 +281,6 @@ class ShoppingCart extends React.Component {
<Text style={{ textAlign: 'center' }}>{this.props.address}</Text>
</Card>
) : (
<Card style={{ margin: 5, padding: 10 }}>
<Text style={{ textAlign: 'center' }}> Pesanan kamu dikirim ke</Text>
......@@ -230,40 +296,17 @@ class ShoppingCart extends React.Component {
</TouchableOpacity>
</View>
<View style={styles.order}>
{this.props.order_item.map((item, index) => {
return (
<View style={{ flex: 1, margin: 10 }} key={index}>
<View style={{ flexDirection: 'row' }}>
<View >
<Image source={{ uri: item.image }} style={{ height: 100, width: 100, borderRadius: 5, top: 5 }}></Image>
</View>
<View >
<Text style={{ fontSize: 20, margin: 5, marginRight: 10, fontWeight: 'bold' }}>{item.name}</Text>
<Text style={{ fontSize: 15, margin: 5, marginRight: 10 }}>Rp. {item.price}</Text>
<View style={{ flexDirection: 'row', flex: 1 }}>
<View style={styles.shadowEdit}></View>
<View style={styles.shadowAdd}>
<TouchableOpacity onPress={() => this.props.handleMin(item,index)}>
<Text style={{ fontSize: 20, margin: 2 }}> - </Text>
</TouchableOpacity>
<TextInput
style={{ height: 25, padding: 2, textAlign: 'center', margin: 2 }}
autoCapitalize="none">
{item.quantity}
</TextInput>
<TouchableOpacity onPress={() => this.props.handleAdd(item,index)}>
<Text style={{ fontSize: 20, margin: 2 }}> + </Text>
</TouchableOpacity>
</View>
</View>
</View>
</View>
</View>
)
})}
<FlatList
data={this.state.order_item}
renderItem={({ item, index }) => (
<ItemShoping navigation={this.props.navigation}
item={item}
handleAdd={() => this.handleAdd(item, index)}
handleMin={() => this.handleMin(item, index)}
/>
)}
keyExtractor={item => item.id}
/>
</View>
<View style={styles.voucher}>
<TouchableOpacity>
......@@ -460,7 +503,7 @@ class ShoppingCart extends React.Component {
</View>
</View>
<View style={{ margin: 20, }}>
<Button title='Checkout' color='#ccb46c' onPress={() => this.props.navigation.navigate('Confirm Your Order', {balanceUsed: this.state.balanceused, pointused : this.state.pointsused})} />
<Button title='Checkout' color='#ccb46c' onPress={() => this.getRate()} />
</View>
</View>
</ScrollView>
......@@ -602,6 +645,13 @@ const styles = StyleSheet.create({
const mapDispatchToProps = (dispacth) => {
return {
addToChart: (item) => dispacth({
type: ActionType.ADD_TO_CHART,
data: {
item: item
}
}),
//REDUCE QUANTITY ITEM
reduceQuantityItem: (item) => dispacth({
type: ActionType.REDUCE_QUANTITY_ITEM,
......@@ -609,11 +659,16 @@ const mapDispatchToProps = (dispacth) => {
item: item
}
}),
removeFromChart: (item) => dispacth({
type: ActionType.REMOVE_FROM_CHART,
data: {
item: item
}
}),
}
}
const mapStateToProps = (state) => {
console.log(state)
return {
session_id: state.session_id,
outlet_id: state.outlet_id,
......@@ -621,9 +676,10 @@ const mapStateToProps = (state) => {
order_total: state.order_total,
order_item: state.order_item,
quantity: state.quantity,
address: state.address
address: state.address,
addressId: state.addressId
}
}
export default connect(mapStateToProps,mapDispatchToProps)(ShoppingCart)
export default connect(mapStateToProps, mapDispatchToProps)(ShoppingCart)
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