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

ini perubahan menu selection

parent 03cdc02e
......@@ -7,11 +7,11 @@ const globalState = {
password: '',
//set register
full_name:'',
dob_day:'',
dob_month:'',
dob_year:'',
gender:'',
full_name: '',
dob_day: '',
dob_month: '',
dob_year: '',
gender: '',
//Set device info di set ketika init
fb_token: '',
......@@ -19,46 +19,46 @@ const globalState = {
os_name: '',
os_version: '',
app_version: '',
session_id:'',
session_id: '',
//set change_profile
gender_display:'',
gender_display: '',
//set registration
validation_reg: false,
registration_id:'',
isEmailverif:false,
registration_id: '',
isEmailverif: false,
//set position
position: 'Home',
pageEmailConfirmation:false,
proses:'',
pageEmailConfirmation: false,
proses: '',
language:'id',
language: 'id',
set_card: false,
URI:'',
URI_IDCARD:'',
URI: '',
URI_IDCARD: '',
id_card64: false,
img64: false,
selfie:false,
idcard:false,
selfie: false,
idcard: false,
BASE64_SELFIE:'',
BASE64_ID:'',
BASE64_SELFIE: '',
BASE64_ID: '',
outlet_id:'',
name_outlet:'',
outlet_id: '',
name_outlet: '',
quantity:0,
orders :0,
cart_shop:[],
quantity: 0,
orders: 0,
cart_shop: [],
order_item: [],
order_quantity: 0,
order_total: 0,
address:''
address: ''
}
const rootReducer = (state = globalState, action) => {
......@@ -71,14 +71,14 @@ const rootReducer = (state = globalState, action) => {
session_id: action.data.session_id
}
}
case ActionType.SET_EMAIL_VERIFICATION :{
return{
case ActionType.SET_EMAIL_VERIFICATION: {
return {
...state,
isEmailverif: action.data.isEmailverif,
}
}
case ActionType.SET_PAGE :{
return{
case ActionType.SET_PAGE: {
return {
...state,
pageEmailConfirmation: action.data.pageEmailConfirmation
}
......@@ -90,7 +90,7 @@ const rootReducer = (state = globalState, action) => {
fb_token: action.data.fb_token,
device_id: action.data.device_id,
os_name: action.data.os_name,
os_version:action.data.os_version,
os_version: action.data.os_version,
app_version: action.data.app_version,
}
}
......@@ -100,48 +100,48 @@ const rootReducer = (state = globalState, action) => {
...state,
full_name: action.data,
dob_day: action.dob_day,
dob_month:action.dob_month,
dob_year:action.dob_year,
gender:action.dob_year,
dob_month: action.dob_month,
dob_year: action.dob_year,
gender: action.dob_year,
email: action.data.email,
validation_reg: action.data.validation_reg,
registration_id: action.data.registration_id
}
}
case ActionType.SET_CHANGE_LANGUAGE:{
return{
case ActionType.SET_CHANGE_LANGUAGE: {
return {
...state,
language: action.data.language,
}
}
case ActionType.SET_CHANGE_PROFIL:{
return{
case ActionType.SET_CHANGE_PROFIL: {
return {
...state,
full_name: action.full_name,
gender_display: action.gender_display
}
}
case ActionType.SET_RESET_PASSWORD:{
return{
case ActionType.SET_RESET_PASSWORD: {
return {
...state,
email:action.data.email,
email: action.data.email,
}
}
case ActionType.SET_PROSES:{
return{
case ActionType.SET_PROSES: {
return {
...state,
proses:action.data.proses
proses: action.data.proses
}
}
case ActionType.SET_CHANGE_EMAIL:{
return{
case ActionType.SET_CHANGE_EMAIL: {
return {
...state,
email:action.data.email,
email: action.data.email,
}
}
case ActionType.SET_CHANGE_URI_SELFI:{
return{
case ActionType.SET_CHANGE_URI_SELFI: {
return {
...state,
URI: action.data.URI,
BASE64_SELFIE: action.data.BASE64_SELFIE
......@@ -151,8 +151,8 @@ const rootReducer = (state = globalState, action) => {
}
}
case ActionType.SET_CHANGE_URI_ID:{
return{
case ActionType.SET_CHANGE_URI_ID: {
return {
...state,
URI_IDCARD: action.data.URI_IDCARD,
BASE64_ID: action.data.BASE64_ID
......@@ -162,60 +162,60 @@ const rootReducer = (state = globalState, action) => {
}
}
case ActionType.SET_CHANGE_CAMERA:{
return{
case ActionType.SET_CHANGE_CAMERA: {
return {
...state,
selfie: action.data.selfie,
idcard: false
}
}
case ActionType.SET_CHANGE_IMAGE_ID:{
return{
case ActionType.SET_CHANGE_IMAGE_ID: {
return {
...state,
idcard: action.data.idcard,
selfie: false
}
}
case ActionType.SET_CHANGE_IMAGE_SELFI:{
return{
case ActionType.SET_CHANGE_IMAGE_SELFI: {
return {
...state,
selfie: action.data.selfie
}
}
case ActionType.SET_CARD:{
return{
case ActionType.SET_CARD: {
return {
...state,
set_card: action.data.set_card
}
}
case ActionType.SET_CHANGE_OUTLET:{
return{
case ActionType.SET_CHANGE_OUTLET: {
return {
...state,
outlet_id: action.data.outlet_id,
name_outlet: action.data.name_outlet
}
}
case ActionType.SET_CHANGE_SHOP:{
return{
case ActionType.SET_CHANGE_SHOP: {
return {
...state
}
}
case ActionType.SET_ADDRESS:{
return{
case ActionType.SET_ADDRESS: {
return {
...state,
address: action.data.address
}
}
case ActionType.SET_LOGOUT:{
return{
case ActionType.SET_LOGOUT: {
return {
...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 is_exist = state.order_item.find(item => addedItem.id == item.id)
......@@ -229,12 +229,12 @@ const rootReducer = (state = globalState, action) => {
const data = old_data;
if (old_data.id == addedItem.id) {
update = old_data
if (update.quantity == NaN){
if (update.quantity == NaN) {
update.quantity = 1
}
update.quantity += 1
console.log('Update : ' + JSON.stringify(update))
data = {...old_data, ...update}
data = { ...old_data, ...update }
}
......@@ -251,7 +251,7 @@ const rootReducer = (state = globalState, action) => {
let quantity = state.order_quantity + 1
let total = parseInt(state.order_total) + parseInt(addedItem.price)
return{
return {
...state,
order_item: order_item,
order_quantity: quantity,
......@@ -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 is_exist = state.order_item.find(item => addedItem.id == item.id)
......@@ -273,13 +273,20 @@ const rootReducer = (state = globalState, action) => {
const data = old_data;
if (old_data.id == addedItem.id) {
update = old_data
if (update.quantity == NaN){
if (update.quantity == NaN) {
update.quantity = 1
}
if (update.quantity === 0) {
update.quantity = 0
} else {
update.quantity -= 1
console.log('Update : ' + JSON.stringify(update))
data = {...old_data, ...update}
data = { ...old_data, ...update }
}
}
......@@ -289,22 +296,33 @@ const rootReducer = (state = globalState, action) => {
} else {
// add
addedItem.quantity = 1
console.log('Baru : ' + JSON.stringify(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 total = parseInt(state.order_total) - parseInt(addedItem.price)
return{
return {
...state,
order_item: order_item,
order_quantity: quantity,
order_total: total
}
}
case ActionType.REMOVE_FROM_CHART:{
case ActionType.REMOVE_FROM_CHART: {
let addedItem = action.data.item
let is_exist = state.order_item.find(item => addedItem.id == item.id)
......@@ -326,7 +344,7 @@ const rootReducer = (state = globalState, action) => {
order_item = updated_data
}
return{
return {
...state,
order_item: order_item,
order_quantity: quantity,
......
import React from 'react';
import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, TextInput } from 'react-native';
import { connect } from 'react-redux';
class Item extends React.Component {
render() {
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 {
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,
"id": row.category.id,
"name": row.category.name,
"code" : "CATEGORY"
"code": "CATEGORY"
}
list_menu.push(category)
list_menu.push(row)
......@@ -67,12 +75,12 @@ class MenuSelection extends React.Component {
}
}
this.state.listMenu.map((i => {
i.qty=0
}))
// this.state.listMenu.map((i => {
// i.qty = 0
// }))
console.log('After : ' + JSON.stringify(list_menu))
this.setState({
listMenu:list_menu
listMenu: list_menu
})
})
......@@ -121,6 +129,7 @@ class MenuSelection extends React.Component {
}
handleAdd(item, index) {
console.log('TAMPILIN NIH')
const order_item = {
id: item.id,
name: item.name,
......@@ -130,23 +139,36 @@ class MenuSelection extends React.Component {
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
}
// 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
})
}
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 = {
id: item.id,
name: item.name,
......@@ -154,13 +176,29 @@ class MenuSelection extends React.Component {
}
this.props.reduceQuantityItem(order_item)
}
}
}
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,
}
this.props.reduceQuantityItem(order_item)
let quantity = 0
if (item.qty == 0) {
item.qty = 0
}else{
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
}
......@@ -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 {
</View>
<View style={{ flex: 3 }}>
<FlatList
data={this.state.listMenu}
renderItem={({ item, index }) => (
<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