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

ini perubahan menu selection

parent 03cdc02e
...@@ -7,11 +7,11 @@ const globalState = { ...@@ -7,11 +7,11 @@ const globalState = {
password: '', password: '',
//set register //set register
full_name:'', full_name: '',
dob_day:'', dob_day: '',
dob_month:'', dob_month: '',
dob_year:'', dob_year: '',
gender:'', gender: '',
//Set device info di set ketika init //Set device info di set ketika init
fb_token: '', fb_token: '',
...@@ -19,46 +19,46 @@ const globalState = { ...@@ -19,46 +19,46 @@ const globalState = {
os_name: '', os_name: '',
os_version: '', os_version: '',
app_version: '', app_version: '',
session_id:'', session_id: '',
//set change_profile //set change_profile
gender_display:'', gender_display: '',
//set registration //set registration
validation_reg: false, validation_reg: false,
registration_id:'', registration_id: '',
isEmailverif:false, isEmailverif: false,
//set position //set position
position: 'Home', position: 'Home',
pageEmailConfirmation:false, pageEmailConfirmation: false,
proses:'', proses: '',
language:'id', language: 'id',
set_card: false, set_card: false,
URI:'', URI: '',
URI_IDCARD:'', URI_IDCARD: '',
id_card64: false, id_card64: false,
img64: false, img64: false,
selfie:false, selfie: false,
idcard:false, idcard: false,
BASE64_SELFIE:'', BASE64_SELFIE: '',
BASE64_ID:'', BASE64_ID: '',
outlet_id:'', outlet_id: '',
name_outlet:'', name_outlet: '',
quantity:0, quantity: 0,
orders :0, orders: 0,
cart_shop:[], cart_shop: [],
order_item: [], order_item: [],
order_quantity: 0, order_quantity: 0,
order_total: 0, order_total: 0,
address:'' address: ''
} }
const rootReducer = (state = globalState, action) => { const rootReducer = (state = globalState, action) => {
...@@ -71,14 +71,14 @@ const rootReducer = (state = globalState, action) => { ...@@ -71,14 +71,14 @@ const rootReducer = (state = globalState, action) => {
session_id: action.data.session_id session_id: action.data.session_id
} }
} }
case ActionType.SET_EMAIL_VERIFICATION :{ case ActionType.SET_EMAIL_VERIFICATION: {
return{ return {
...state, ...state,
isEmailverif: action.data.isEmailverif, isEmailverif: action.data.isEmailverif,
} }
} }
case ActionType.SET_PAGE :{ case ActionType.SET_PAGE: {
return{ return {
...state, ...state,
pageEmailConfirmation: action.data.pageEmailConfirmation pageEmailConfirmation: action.data.pageEmailConfirmation
} }
...@@ -90,7 +90,7 @@ const rootReducer = (state = globalState, action) => { ...@@ -90,7 +90,7 @@ const rootReducer = (state = globalState, action) => {
fb_token: action.data.fb_token, fb_token: action.data.fb_token,
device_id: action.data.device_id, device_id: action.data.device_id,
os_name: action.data.os_name, os_name: action.data.os_name,
os_version:action.data.os_version, os_version: action.data.os_version,
app_version: action.data.app_version, app_version: action.data.app_version,
} }
} }
...@@ -100,48 +100,48 @@ const rootReducer = (state = globalState, action) => { ...@@ -100,48 +100,48 @@ const rootReducer = (state = globalState, action) => {
...state, ...state,
full_name: action.data, full_name: action.data,
dob_day: action.dob_day, dob_day: action.dob_day,
dob_month:action.dob_month, dob_month: action.dob_month,
dob_year:action.dob_year, dob_year: action.dob_year,
gender:action.dob_year, gender: action.dob_year,
email: action.data.email, email: action.data.email,
validation_reg: action.data.validation_reg, validation_reg: action.data.validation_reg,
registration_id: action.data.registration_id registration_id: action.data.registration_id
} }
} }
case ActionType.SET_CHANGE_LANGUAGE:{ case ActionType.SET_CHANGE_LANGUAGE: {
return{ return {
...state, ...state,
language: action.data.language, language: action.data.language,
} }
} }
case ActionType.SET_CHANGE_PROFIL:{ case ActionType.SET_CHANGE_PROFIL: {
return{ return {
...state, ...state,
full_name: action.full_name, full_name: action.full_name,
gender_display: action.gender_display gender_display: action.gender_display
} }
} }
case ActionType.SET_RESET_PASSWORD:{ case ActionType.SET_RESET_PASSWORD: {
return{ return {
...state, ...state,
email:action.data.email, email: action.data.email,
} }
} }
case ActionType.SET_PROSES:{ case ActionType.SET_PROSES: {
return{ return {
...state, ...state,
proses:action.data.proses proses: action.data.proses
} }
} }
case ActionType.SET_CHANGE_EMAIL:{ case ActionType.SET_CHANGE_EMAIL: {
return{ return {
...state, ...state,
email:action.data.email, email: action.data.email,
} }
} }
case ActionType.SET_CHANGE_URI_SELFI:{ case ActionType.SET_CHANGE_URI_SELFI: {
return{ return {
...state, ...state,
URI: action.data.URI, URI: action.data.URI,
BASE64_SELFIE: action.data.BASE64_SELFIE BASE64_SELFIE: action.data.BASE64_SELFIE
...@@ -151,8 +151,8 @@ const rootReducer = (state = globalState, action) => { ...@@ -151,8 +151,8 @@ const rootReducer = (state = globalState, action) => {
} }
} }
case ActionType.SET_CHANGE_URI_ID:{ case ActionType.SET_CHANGE_URI_ID: {
return{ return {
...state, ...state,
URI_IDCARD: action.data.URI_IDCARD, URI_IDCARD: action.data.URI_IDCARD,
BASE64_ID: action.data.BASE64_ID BASE64_ID: action.data.BASE64_ID
...@@ -162,60 +162,60 @@ const rootReducer = (state = globalState, action) => { ...@@ -162,60 +162,60 @@ const rootReducer = (state = globalState, action) => {
} }
} }
case ActionType.SET_CHANGE_CAMERA:{ case ActionType.SET_CHANGE_CAMERA: {
return{ return {
...state, ...state,
selfie: action.data.selfie, selfie: action.data.selfie,
idcard: false idcard: false
} }
} }
case ActionType.SET_CHANGE_IMAGE_ID:{ case ActionType.SET_CHANGE_IMAGE_ID: {
return{ return {
...state, ...state,
idcard: action.data.idcard, idcard: action.data.idcard,
selfie: false selfie: false
} }
} }
case ActionType.SET_CHANGE_IMAGE_SELFI:{ case ActionType.SET_CHANGE_IMAGE_SELFI: {
return{ return {
...state, ...state,
selfie: action.data.selfie selfie: action.data.selfie
} }
} }
case ActionType.SET_CARD:{ case ActionType.SET_CARD: {
return{ return {
...state, ...state,
set_card: action.data.set_card set_card: action.data.set_card
} }
} }
case ActionType.SET_CHANGE_OUTLET:{ case ActionType.SET_CHANGE_OUTLET: {
return{ return {
...state, ...state,
outlet_id: action.data.outlet_id, outlet_id: action.data.outlet_id,
name_outlet: action.data.name_outlet name_outlet: action.data.name_outlet
} }
} }
case ActionType.SET_CHANGE_SHOP:{ case ActionType.SET_CHANGE_SHOP: {
return{ return {
...state ...state
} }
} }
case ActionType.SET_ADDRESS:{ case ActionType.SET_ADDRESS: {
return{ return {
...state, ...state,
address: action.data.address address: action.data.address
} }
} }
case ActionType.SET_LOGOUT:{ case ActionType.SET_LOGOUT: {
return{ return {
...state, ...state,
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
let is_exist = state.order_item.find(item => addedItem.id == item.id) let is_exist = state.order_item.find(item => addedItem.id == item.id)
...@@ -229,12 +229,12 @@ const rootReducer = (state = globalState, action) => { ...@@ -229,12 +229,12 @@ const rootReducer = (state = globalState, action) => {
const data = old_data; const data = old_data;
if (old_data.id == addedItem.id) { if (old_data.id == addedItem.id) {
update = old_data update = old_data
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 }
} }
...@@ -251,7 +251,7 @@ const rootReducer = (state = globalState, action) => { ...@@ -251,7 +251,7 @@ const rootReducer = (state = globalState, action) => {
let quantity = state.order_quantity + 1 let quantity = state.order_quantity + 1
let total = parseInt(state.order_total) + parseInt(addedItem.price) let total = parseInt(state.order_total) + parseInt(addedItem.price)
return{ return {
...state, ...state,
order_item: order_item, order_item: order_item,
order_quantity: quantity, order_quantity: quantity,
...@@ -259,7 +259,7 @@ const rootReducer = (state = globalState, action) => { ...@@ -259,7 +259,7 @@ const rootReducer = (state = globalState, action) => {
} }
} }
case ActionType.REDUCE_QUANTITY_ITEM:{ case ActionType.REDUCE_QUANTITY_ITEM: {
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)
...@@ -273,13 +273,20 @@ const rootReducer = (state = globalState, action) => { ...@@ -273,13 +273,20 @@ const rootReducer = (state = globalState, action) => {
const data = old_data; const data = old_data;
if (old_data.id == addedItem.id) { if (old_data.id == addedItem.id) {
update = old_data update = old_data
if (update.quantity == NaN){ if (update.quantity == NaN) {
update.quantity = 1 update.quantity = 1
} }
if (update.quantity === 0) {
update.quantity = 0
} else {
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 }
}
} }
...@@ -289,22 +296,33 @@ const rootReducer = (state = globalState, action) => { ...@@ -289,22 +296,33 @@ const rootReducer = (state = globalState, action) => {
} else { } else {
// add // add
addedItem.quantity = 1 addedItem.quantity = 1
console.log('Baru : ' + JSON.stringify(addedItem)) console.log('Baru : ' + JSON.stringify(addedItem))
order_item = [...state.order_item, addedItem] order_item = [...state.order_item, addedItem]
} }
if (state.order_quantity === 0 && state.order_total === 0) {
state.order_quantity = 0
state.order_total = 0
console.log("MASUK INI")
}
let quantity = state.order_quantity - 1 let quantity = state.order_quantity - 1
let total = parseInt(state.order_total) - parseInt(addedItem.price) let total = parseInt(state.order_total) - parseInt(addedItem.price)
return{ return {
...state, ...state,
order_item: order_item, order_item: order_item,
order_quantity: quantity, order_quantity: quantity,
order_total: total order_total: total
} }
} }
case ActionType.REMOVE_FROM_CHART:{ case ActionType.REMOVE_FROM_CHART: {
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)
...@@ -326,7 +344,7 @@ const rootReducer = (state = globalState, action) => { ...@@ -326,7 +344,7 @@ const rootReducer = (state = globalState, action) => {
order_item = updated_data order_item = updated_data
} }
return{ return {
...state, ...state,
order_item: order_item, order_item: order_item,
order_quantity: quantity, order_quantity: quantity,
......
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';
class Item extends React.Component { class Item extends React.Component {
render() { render() {
const { item } = this.props const { item } = this.props
......
import React from 'react';
import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, TextInput } from 'react-native';
import { connect } from 'react-redux';
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={{ 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>
</View>
</View>
</View>
)}
</ScrollView>
</View>
)
}
}
const styles = StyleSheet.create({
shadowEdit: {
height: 30,
width: 25,
borderWidth: 1,
borderRadius: 2,
borderColor: '#ddd',
borderBottomWidth: 0,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 1,
marginLeft: 5,
marginRight: 5,
marginTop: 10,
},
shadowAdd: {
height: 30,
width: 75,
borderWidth: 1,
borderRadius: 2,
borderColor: '#ddd',
borderBottomWidth: 0,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 1,
marginLeft: 5,
marginRight: 5,
marginTop: 10,
flexDirection: 'row'
},
shadowMin: {
height: 20,
width: 20,
borderWidth: 1,
borderRadius: 2,
borderColor: '#ddd',
borderBottomWidth: 0,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 1,
marginLeft: 5,
marginRight: 5,
marginTop: 10,
}
})
const mapStateToProps = (state) => {
console.log(state)
return {
session_id: state.session_id,
outlet_id: state.outlet_id,
order_quantity: state.order_quantity,
order_total: state.order_total,
quantity: state.quantity,
}
}
export default connect(mapStateToProps)(Item)
...@@ -53,11 +53,19 @@ class MenuSelection extends React.Component { ...@@ -53,11 +53,19 @@ class MenuSelection extends React.Component {
const row = data.menu[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) { if (last_category != row.category.name) {
let category = { let category = {
"id":row.category.id, "id": row.category.id,
"name": row.category.name, "name": row.category.name,
"code" : "CATEGORY" "code": "CATEGORY"
} }
list_menu.push(category) list_menu.push(category)
list_menu.push(row) list_menu.push(row)
...@@ -67,12 +75,12 @@ class MenuSelection extends React.Component { ...@@ -67,12 +75,12 @@ class MenuSelection extends React.Component {
} }
} }
this.state.listMenu.map((i => { // this.state.listMenu.map((i => {
i.qty=0 // i.qty = 0
})) // }))
console.log('After : ' + JSON.stringify(list_menu)) console.log('After : ' + JSON.stringify(list_menu))
this.setState({ this.setState({
listMenu:list_menu listMenu: list_menu
}) })
}) })
...@@ -121,6 +129,7 @@ class MenuSelection extends React.Component { ...@@ -121,6 +129,7 @@ class MenuSelection extends React.Component {
} }
handleAdd(item, index) { handleAdd(item, index) {
console.log('TAMPILIN NIH')
const order_item = { const order_item = {
id: item.id, id: item.id,
name: item.name, name: item.name,
...@@ -130,23 +139,36 @@ class MenuSelection extends React.Component { ...@@ -130,23 +139,36 @@ class MenuSelection extends React.Component {
this.props.addToChart(order_item) this.props.addToChart(order_item)
// console.log("ORDER ITEM " + this.props.order_item)
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 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];
if (row.id == item.id) { // if (row.id == item.id) {
quantity = row.quantity // quantity = row.quantity
} // }
// }
if (is_xist) {
quantity = is_xist.quantity
} }
const listMenu = [...this.state.listMenu] const listMenu = [...this.state.listMenu]
// console.log("INI COY YYYY QUANTITY " + quantity)
listMenu[index].qty = quantity listMenu[index].qty = quantity
this.setState({ this.setState({
listMenu listMenu
}) })
} }
handleMin(item, index) {
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 = { const order_item = {
id: item.id, id: item.id,
name: item.name, name: item.name,
...@@ -154,13 +176,29 @@ class MenuSelection extends React.Component { ...@@ -154,13 +176,29 @@ class MenuSelection extends React.Component {
} }
this.props.reduceQuantityItem(order_item) this.props.reduceQuantityItem(order_item)
}
}
}
handleMin(item, index) {
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)
if (is_xist) {
if (is_xist.quantity != 0) {
const order_item = {
id: item.id,
name: item.name,
price: item.price,
}
this.props.reduceQuantityItem(order_item)
let quantity = 0 let quantity = 0
if (item.qty == 0) {
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];
const qty = list_order_item[i];
if (row.id == item.id) { if (row.id == item.id) {
quantity = row.quantity quantity = row.quantity
} }
...@@ -171,6 +209,10 @@ class MenuSelection extends React.Component { ...@@ -171,6 +209,10 @@ class MenuSelection extends React.Component {
}) })
} }
} }
}
// this.clearNegatif(item,index)
// ini buat update list menu
} }
...@@ -188,6 +230,7 @@ class MenuSelection extends React.Component { ...@@ -188,6 +230,7 @@ class MenuSelection extends React.Component {
</View> </View>
<View style={{ flex: 3 }}> <View style={{ flex: 3 }}>
<FlatList <FlatList
data={this.state.listMenu} data={this.state.listMenu}
renderItem={({ item, index }) => ( renderItem={({ item, index }) => (
<Item navigation={this.props.navigation} <Item navigation={this.props.navigation}
......
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