Commit b5e5ea24 authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

change

parent ddc5c424
...@@ -276,6 +276,7 @@ const rootReducer = (state = globalState, action) => { ...@@ -276,6 +276,7 @@ const rootReducer = (state = globalState, action) => {
if (update.quantity == NaN){ if (update.quantity == NaN){
update.quantity = 1 update.quantity = 1
} }
update.quantity -= 1 update.quantity -= 1
console.log('Update : ' + JSON.stringify(update)) console.log('Update : ' + JSON.stringify(update))
data = {...old_data, ...update} data = {...old_data, ...update}
......
...@@ -4,39 +4,42 @@ import { connect } from 'react-redux'; ...@@ -4,39 +4,42 @@ import { connect } from 'react-redux';
class Item extends React.Component { class Item extends React.Component {
render() { render() {
const { item } = this.props const { item } = this.props
// console.log('ini props nya item : ' + JSON.stringify(item)) console.log("ini id itemnya "+item.id)
const { description, name, image, price, qty, } = item
return ( return (
<View style={{ flex: 1, margin: 10 }}> <View style={{ flex: 1, margin: 10 }} key={item.id} ref={this.props._scrollView}>
<ScrollView ref={view => this._scrollView = view}> <ScrollView ref={view => this._scrollView = view}>
{item.code == 'CATEGORY' ? (
<Text style={{ fontSize: 20, color: '#c9af6d' }}>{item.category.name}</Text> <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> <View style={{ flexDirection: 'row' }}>
</View> <View >
<View > <Image source={{ uri: item.image }} style={{ height: 100, width: 100, borderRadius: 5, top: 5 }}></Image>
<Text style={{ fontSize: 20, margin: 5, marginRight: 10, fontWeight: 'bold' }}>{item.name}</Text> </View>
<Text style={{ fontSize: 15, margin: 5, marginRight: 10 }}>Rp. {item.price}</Text> <View >
<View style={{ flexDirection: 'row', flex: 1 }}> <Text style={{ fontSize: 20, margin: 5, marginRight: 10, fontWeight: 'bold' }}>{item.name}</Text>
<View style={styles.shadowEdit}></View> <Text style={{ fontSize: 15, margin: 5, marginRight: 10 }}>Rp. {item.price}</Text>
<View style={styles.shadowAdd}> <View style={{ flexDirection: 'row', flex: 1 }}>
<TouchableOpacity onPress={() => this.props.handleMin()}> <View style={styles.shadowEdit}></View>
<Text style={{ fontSize: 20, margin: 2 }}> - </Text> <View style={styles.shadowAdd}>
</TouchableOpacity> <TouchableOpacity onPress={() => this.props.handleMin()}>
<Text style={{ fontSize: 20, margin: 2 }}> - </Text>
</TouchableOpacity>
<TextInput <TextInput
style={{ height: 25, padding: 2,textAlign:'center',margin:2 }} style={{ height: 25, padding: 2, textAlign: 'center', margin: 2 }}
autoCapitalize="none"> autoCapitalize="none">
{item.qty} {item.qty}
</TextInput> </TextInput>
<TouchableOpacity onPress={() => this.props.handleAdd()}> <TouchableOpacity onPress={() => this.props.handleAdd()}>
<Text style={{ fontSize: 20, margin: 2 }}> + </Text> <Text style={{ fontSize: 20, margin: 2 }}> + </Text>
</TouchableOpacity> </TouchableOpacity>
</View>
</View> </View>
</View> </View>
</View> </View>
</View> )}
</ScrollView> </ScrollView>
</View> </View>
) )
...@@ -98,12 +101,12 @@ const styles = StyleSheet.create({ ...@@ -98,12 +101,12 @@ const styles = StyleSheet.create({
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
console.log(state) console.log(state)
return { return {
session_id: state.session_id, session_id: state.session_id,
outlet_id: state.outlet_id, outlet_id: state.outlet_id,
order_quantity : state.order_quantity, order_quantity: state.order_quantity,
order_total : state.order_total, order_total: state.order_total,
quantity: state.quantity, quantity: state.quantity,
} }
} }
export default connect(mapStateToProps)(Item) export default connect(mapStateToProps)(Item)
...@@ -44,27 +44,39 @@ class MenuSelection extends React.Component { ...@@ -44,27 +44,39 @@ class MenuSelection extends React.Component {
listMenu: data.menu listMenu: data.menu
}) })
let last_category = '' let last_category = ''
let list_menu = [] let list_menu = []
console.log("INI DATANYA "+JSON.stringify(data.menu))
for (let row in data.menu) { for (let i = 0; i < data.menu.length; i++) {
const row = data.menu[i];
if (last_category != row.category.name) { if (last_category != row.category.name) {
category = { let category = {
"id": 'CATEGORY', "id":row.category.id,
"name": row.category.name "name": row.category.name,
"code" : "CATEGORY"
} }
list_menu.append(category) list_menu.push(category)
list_menu.append(row) list_menu.push(row)
last_category = row.category.name last_category = row.category.name
} else { } else {
// tampilin item list_menu.push(row)
list_menu.append(row)
} }
} }
this.state.listMenu.map((i => {
i.qty=0
}))
console.log('After : ' + JSON.stringify(list_menu))
this.setState({
listMenu:list_menu
})
}) })
} }
renderTabBar = ({ item }) => { renderTabBar = ({ item }) => {
return ( return (
...@@ -144,29 +156,31 @@ class MenuSelection extends React.Component { ...@@ -144,29 +156,31 @@ class MenuSelection extends React.Component {
this.props.reduceQuantityItem(order_item) this.props.reduceQuantityItem(order_item)
const list_order_item = this.props.order_item; const list_order_item = this.props.order_item;
let quantity = 0 let quantity = 0
if (quantity != 0) { if (item.qty == 0) {
quantity = quantity - 1 item.qty = 0
}else{
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];
if (row.id == item.id) { if (row.id == item.id) {
quantity = row.quantity quantity = row.quantity
} }
}
const listMenu = [...this.state.listMenu] const listMenu = [...this.state.listMenu]
listMenu[index].qty = quantity listMenu[index].qty = quantity
this.setState({ this.setState({
listMenu listMenu
}) })
} }
}
} }
render() { render() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<StatusBar hidden={true} /> <StatusBar hidden={true} />
<View style={{ flex: 0.7, height: 90, flexDirection: 'row', borderWidth: 1, }}> <View style={{ flex: 0.7, height: 90, flexDirection: 'row', borderWidth: 1, }}>
<FlatList horizontal={true} style={{ flexDirection: 'row' }} <FlatList horizontal={true} style={{ flexDirection: 'row' }}
showsHorizontalScrollIndicator={false}
data={this.state.listCategory} data={this.state.listCategory}
renderItem={this.renderTabBar} renderItem={this.renderTabBar}
keyExtractor={(item) => item.id} keyExtractor={(item) => item.id}
......
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