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

update

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