Commit 1b3ca2f8 authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

update

parent 7854ba1a
{ {
"expo": { "expo": {
"name": "Excelso_update v1_malam", "name": "Excelso_update v1.06062020",
"slug": "excelso-pro", "slug": "excelso-pro",
"privacy": "public", "privacy": "public",
"sdkVersion": "36.0.0", "sdkVersion": "36.0.0",
......
...@@ -33,7 +33,8 @@ const ActionType = { ...@@ -33,7 +33,8 @@ const ActionType = {
SET_RECALCULATE: 'SET_RECALCULATE', SET_RECALCULATE: 'SET_RECALCULATE',
SET_ORDER_FINISH: 'SET_ORDER_FINISH', SET_ORDER_FINISH: 'SET_ORDER_FINISH',
UPDATE_MENU: 'UPDATE_MENU', UPDATE_MENU: 'UPDATE_MENU',
SET_TRANS_ID:'SET_TRANS_ID' SET_TRANS_ID:'SET_TRANS_ID',
CHANGE_TO_CHART:'CHANGE_TO_CHART'
} }
export default ActionType; export default ActionType;
\ No newline at end of file
...@@ -340,6 +340,64 @@ const rootReducer = (state = globalState, action) => { ...@@ -340,6 +340,64 @@ const rootReducer = (state = globalState, action) => {
} }
} }
case ActionType.CHANGE_TO_CHART: {
let addedItem = action.data.item
let is_exist = state.order_item.find(item => addedItem.id == item.id)
let order_item = []
if (is_exist) {
// update
updated_data = []
for (let i = 0; i < state.order_item.length; i++) {
const old_data = state.order_item[i];
const data = old_data;
if (old_data.id == addedItem.id) {
update = old_data
if (update.quantity == NaN) {
update.quantity = 1
}
console.log('Update : ' + JSON.stringify(update))
data = { ...old_data, ...update }
}
updated_data.push(data)
}
order_item = updated_data
} else {
// addcd ..
order_item = [...state.order_item]
}
let quantity = state.order_quantity
let menu_item = []
for (let i = 0; i < state.menu_item.length; i++) {
const row = state.menu_item[i];
if (row.id == addedItem.id) {
let is_exist = order_item.find(item => addedItem.id == item.id)
if (is_exist) {
row.qty = is_exist.quantity
}
}
menu_item.push(row)
}
return {
...state,
menu_item: menu_item,
order_item: order_item,
order_quantity: quantity,
}
}
case ActionType.REDUCE_QUANTITY_ITEM: { case ActionType.REDUCE_QUANTITY_ITEM: {
let addedItem = action.data.item let addedItem = action.data.item
......
...@@ -284,7 +284,7 @@ class Home extends React.Component { ...@@ -284,7 +284,7 @@ class Home extends React.Component {
<TouchableOpacity style={styles.submitUpgradePemium} activeOpacity={.5} onPress={this.onPress}> <TouchableOpacity style={styles.submitUpgradePemium} activeOpacity={.5} onPress={this.onPress}>
<Text style={{ textAlign: 'center', bottom: 5, color: 'white' }}>TOP BALANCE </Text> <Text style={{ textAlign: 'center', bottom: 5, color: 'white' }}>TOP BALANCE </Text>
</TouchableOpacity> </TouchableOpacity>
<Text>APP.V2.APRIL</Text> <Text>UPDATE SORE </Text>
<View style={{ height: 60 }}></View> <View style={{ height: 60 }}></View>
</View> </View>
</View> </View>
......
import React from 'react'; import React from 'react';
import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, TextInput } from 'react-native'; import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, TextInput } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import ActionType from '../redux/globalActionType';
class Item extends React.Component { class Item extends React.Component {
onChange(item, value) {
console.log()
// const order_item = {
// id: item.id,
// code: item.code,
// name: item.name,
// description: item.description,
// note: 'jangan garing',
// image: item.image,
// quantity: value,
// price: parseInt(item.price),
// }
// let res = this.props.setChangeQuantity(order_item)
}
render() { render() {
const { item } = this.props const { item } = this.props
// console.log("ini id itemnya "+item.id) // console.log("ini id itemnya "+item.id)
...@@ -12,7 +29,7 @@ class Item extends React.Component { ...@@ -12,7 +29,7 @@ class Item extends React.Component {
<ScrollView ref={view => this._scrollView = view}> <ScrollView ref={view => this._scrollView = view}>
{item.code == 'CATEGORY' ? ( {item.code == 'CATEGORY' ? (
<Text style={{ fontSize: 20, color: '#c9af6d' }}>{item.name}</Text> <Text style={{ fontSize: 20, color: '#c9af6d' }}>{item.name}</Text>
): ( ) : (
<View style={{ flexDirection: 'row' }}> <View style={{ flexDirection: 'row' }}>
<View > <View >
...@@ -29,7 +46,8 @@ class Item extends React.Component { ...@@ -29,7 +46,8 @@ class Item extends React.Component {
</TouchableOpacity> </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"
onChangeText={(value) => this.onChange(item, value)}>
{item.qty} {item.qty}
</TextInput> </TextInput>
<TouchableOpacity onPress={() => this.props.handleAdd()}> <TouchableOpacity onPress={() => this.props.handleAdd()}>
...@@ -99,6 +117,16 @@ const styles = StyleSheet.create({ ...@@ -99,6 +117,16 @@ const styles = StyleSheet.create({
} }
}) })
const mapDispatchToProps = (dispacth) => {
return {
setChangeQuantity: (item) => dispacth({
type: ActionType.CHANGE_TO_CHART,
data: {
item: item
}
}),
}
}
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
// console.log(state) // console.log(state)
return { return {
...@@ -110,4 +138,4 @@ const mapStateToProps = (state) => { ...@@ -110,4 +138,4 @@ const mapStateToProps = (state) => {
} }
} }
export default connect(mapStateToProps)(Item) export default connect(mapStateToProps, mapDispatchToProps)(Item)
...@@ -3,9 +3,14 @@ import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, TextInput ...@@ -3,9 +3,14 @@ import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, TextInput
import { connect } from 'react-redux'; import { connect } from 'react-redux';
class ItemShoping extends React.Component { class ItemShoping extends React.Component {
constructor(props){
super(props)
}
render() { render() {
const { item } = this.props const { item } = this.props
this.state = {
quantity: item.quantity
}
return ( return (
<View style={{ flex: 1, margin: 10 }} key={item.id}> <View style={{ flex: 1, margin: 10 }} key={item.id}>
...@@ -23,10 +28,8 @@ class ItemShoping extends React.Component { ...@@ -23,10 +28,8 @@ class ItemShoping extends React.Component {
<TouchableOpacity onPress={() => this.props.handleMin()}> <TouchableOpacity onPress={() => this.props.handleMin()}>
<Text style={{ fontSize: 20, margin: 2 }}> - </Text> <Text style={{ fontSize: 20, margin: 2 }}> - </Text>
</TouchableOpacity> </TouchableOpacity>
<TextInput <TextInput style={{ height: 25, padding: 2, textAlign: 'center', margin: 2 }} onChange={this.props.onChange()}>
style={{ height: 25, padding: 2, textAlign: 'center', margin: 2 }} {this.state.quantity}
autoCapitalize="none">
{item.quantity}
</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>
......
...@@ -24,6 +24,8 @@ class MenuSelection extends React.Component { ...@@ -24,6 +24,8 @@ class MenuSelection extends React.Component {
order_list: [], order_list: [],
list_cart: [], list_cart: [],
indicator: true, indicator: true,
my_lat: 0,
my_long: 0
} }
} }
...@@ -36,17 +38,16 @@ class MenuSelection extends React.Component { ...@@ -36,17 +38,16 @@ class MenuSelection extends React.Component {
indicator: true indicator: true
}) })
this._getPermissions() this._getPermissions()
this.getMenuList()
} }
// console.log("INI OUTLET : "+ this.props.outlet_id) // console.log("INI OUTLET : "+ this.props.outlet_id)
this._unsubscribe = this.props.navigation.addListener('focus', () => { this._unsubscribe = this.props.navigation.addListener('focus', () => {
if (this.props.outlet_id != '') { if (this.props.outlet_id != '') {
this.getMenuList()
} else {
this.setState({ this.setState({
indicator:true indicator: true
}) })
this._getPermissions() this._getPermissions()
this.getMenuList()
} }
}); });
} }
...@@ -166,9 +167,9 @@ class MenuSelection extends React.Component { ...@@ -166,9 +167,9 @@ class MenuSelection extends React.Component {
}) })
}).catch(error => { }).catch(error => {
const {navigation} = this.props const { navigation } = this.props
let response = error.response.data let response = error.response.data
session(response,navigation) session(response, navigation)
Alert.alert(response.msg); Alert.alert(response.msg);
}) })
...@@ -188,6 +189,12 @@ class MenuSelection extends React.Component { ...@@ -188,6 +189,12 @@ class MenuSelection extends React.Component {
this.setState({ isFetching: true }, function () { this.getMenuList() }); this.setState({ isFetching: true }, function () { this.getMenuList() });
} }
scrollToItem = () => {
this.props._scrollView.scrollTo({ y: 1 * 100 });
}
handleAdd(item, index) { handleAdd(item, index) {
const order_item = { const order_item = {
...@@ -201,29 +208,42 @@ class MenuSelection extends React.Component { ...@@ -201,29 +208,42 @@ class MenuSelection extends React.Component {
} }
let res = 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)
onChange(value){ // let quantity = 1
console.log( "INI TEXT NYA :"+ JSON.stringify(value)) // 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)
// this.setState({
// listMenu
// })
} }
// clearNegatif(item, index) {
// const list_order_item = this.props.order_item;
// for (let i = 0; i < list_order_item.length; index++) {
// const row = list_order_item[i];
// if (row.quantity !== 0) {
// const order_item = {
// id: item.id,
// name: item.name,
// price: item.price,
// }
// this.props.reduceQuantityItem(order_item)
// }
// } clearNegatif(item, index) {
// } const list_order_item = this.props.order_item;
for (let i = 0; i < list_order_item.length; index++) {
const row = list_order_item[i];
if (row.quantity !== 0) {
const order_item = {
id: item.id,
name: item.name,
price: item.price,
}
this.props.reduceQuantityItem(order_item)
}
}
}
handleMin(item, index) { handleMin(item, index) {
const list_order_item = this.props.order_item; const list_order_item = this.props.order_item;
...@@ -274,7 +294,6 @@ class MenuSelection extends React.Component { ...@@ -274,7 +294,6 @@ class MenuSelection extends React.Component {
item={item} item={item}
handleAdd={() => this.handleAdd(item, index)} handleAdd={() => this.handleAdd(item, index)}
handleMin={() => this.handleMin(item, index)} handleMin={() => this.handleMin(item, index)}
onChange={() => this.onChange(item,index)}
/> />
)} )}
keyExtractor={item => item.id} keyExtractor={item => item.id}
...@@ -284,7 +303,7 @@ class MenuSelection extends React.Component { ...@@ -284,7 +303,7 @@ class MenuSelection extends React.Component {
<View style={styles.shadow}> <View style={styles.shadow}>
{ {
this.state.indicator == true ? (<ActivityIndicator style={{ top: 10 }} size="large" color="#c9af6d" />):( this.state.indicator == true ? (<ActivityIndicator style={{ top: 10 }} size="large" color="#c9af6d" />) : (
<View style={{ flexDirection: 'row', }}> <View style={{ flexDirection: 'row', }}>
<Text style={{ fontSize: 12, margin: 10 }}> Price Estimation / Item {this.props.order_quantity} </Text> <Text style={{ fontSize: 12, margin: 10 }}> Price Estimation / Item {this.props.order_quantity} </Text>
...@@ -368,36 +387,7 @@ const mapDispatchToProps = (dispacth) => { ...@@ -368,36 +387,7 @@ const mapDispatchToProps = (dispacth) => {
name_outlet: OutletChange.name_outlet, name_outlet: OutletChange.name_outlet,
} }
}), }),
setChangeQuantity: (item) => dispacth({
type: ActionType.CHANGE_TO_CHART,
data: {
item:item
}
}),
} }
} }
export default connect(mapStateToProps, mapDispatchToProps)(MenuSelection) export default connect(mapStateToProps, mapDispatchToProps)(MenuSelection)
...@@ -107,6 +107,11 @@ class ShoppingCart extends React.Component { ...@@ -107,6 +107,11 @@ class ShoppingCart extends React.Component {
} }
} }
onChange(params){
console.log(params);
}
handleMin(item, index) { handleMin(item, index) {
this.setState({ this.setState({
checkedBalance: false, checkedBalance: false,
...@@ -277,6 +282,9 @@ class ShoppingCart extends React.Component { ...@@ -277,6 +282,9 @@ class ShoppingCart extends React.Component {
} }
getRate() { getRate() {
let params = { let params = {
...@@ -323,6 +331,10 @@ class ShoppingCart extends React.Component { ...@@ -323,6 +331,10 @@ class ShoppingCart extends React.Component {
} }
onChange(){
}
checkOut() { checkOut() {
if (this.props.order_item.length == 0){ if (this.props.order_item.length == 0){
Alert.alert('Error', 'Please choose your order first') Alert.alert('Error', 'Please choose your order first')
...@@ -399,6 +411,7 @@ class ShoppingCart extends React.Component { ...@@ -399,6 +411,7 @@ class ShoppingCart extends React.Component {
item={item} item={item}
handleAdd={() => this.handleAdd(item, index)} handleAdd={() => this.handleAdd(item, index)}
handleMin={() => this.handleMin(item, index)} handleMin={() => this.handleMin(item, index)}
onChange={()=> this.onChange(item,index)}
/> />
)} )}
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