Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
new_excelso
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Prasetya Saputra
new_excelso
Commits
d47eebb0
Commit
d47eebb0
authored
Apr 27, 2020
by
Wahyu Adjie Prasetyo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ini perubahan menu selection
parent
03cdc02e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
306 additions
and
130 deletions
+306
-130
globalReducer.js
redux/globalReducer.js
+111
-93
Item.js
view/Item.js
+1
-0
ItemShopingCart.js
view/ItemShopingCart.js
+114
-0
MenuSelection.js
view/MenuSelection.js
+80
-37
No files found.
redux/globalReducer.js
View file @
d47eebb0
...
...
@@ -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,58 +90,58 @@ 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
,
}
}
case
ActionType
.
SET_REGISTRATION
:
{
return
{
...
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
}
update
.
quantity
-=
1
console
.
log
(
'Update : '
+
JSON
.
stringify
(
update
))
data
=
{...
old_data
,
...
update
}
if
(
update
.
quantity
===
0
)
{
update
.
quantity
=
0
}
else
{
update
.
quantity
-=
1
console
.
log
(
'Update : '
+
JSON
.
stringify
(
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
]
}
let
quantity
=
state
.
order_quantity
-
1
let
total
=
parseInt
(
state
.
order_total
)
-
parseInt
(
addedItem
.
price
)
if
(
state
.
order_quantity
===
0
&&
state
.
order_total
===
0
)
{
return
{
...
state
,
order_item
:
order_item
,
order_quantity
:
quantity
,
order_total
:
total
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
{
...
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
)
...
...
@@ -322,19 +340,19 @@ const rootReducer = (state = globalState, action) => {
total
+=
(
data
.
quantity
*
data
.
price
)
}
}
order_item
=
updated_data
}
return
{
return
{
...
state
,
order_item
:
order_item
,
order_quantity
:
quantity
,
order_total
:
total
}
}
default
:
return
state
;
}
...
...
view/Item.js
View file @
d47eebb0
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
...
...
view/ItemShopingCart.js
0 → 100644
View file @
d47eebb0
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
)
view/MenuSelection.js
View file @
d47eebb0
...
...
@@ -44,20 +44,28 @@ class MenuSelection extends React.Component {
listMenu
:
data
.
menu
})
let
last_category
=
''
let
list_menu
=
[]
for
(
let
i
=
0
;
i
<
data
.
menu
.
length
;
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
)
{
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
)
...
...
@@ -66,15 +74,15 @@ class MenuSelection extends React.Component {
list_menu
.
push
(
row
)
}
}
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,48 +139,81 @@ 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
)
{
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
;
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
];
if
(
row
.
id
==
item
.
id
)
{
quantity
=
row
.
quantity
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
,
}
const
listMenu
=
[...
this
.
state
.
listMenu
]
listMenu
[
index
].
qty
=
quantity
this
.
setState
({
listMenu
})
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
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
}
const
listMenu
=
[...
this
.
state
.
listMenu
]
listMenu
[
index
].
qty
=
quantity
this
.
setState
({
listMenu
})
}
}
}
// this.clearNegatif(item,index)
// ini buat update list menu
}
render
()
{
...
...
@@ -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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment