Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
clone_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
clone_excelso
Commits
e1aa0de1
Commit
e1aa0de1
authored
May 07, 2020
by
Afid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change quantity
parent
004e96f7
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
10 deletions
+105
-10
globalActionType.js
redux/globalActionType.js
+2
-1
globalReducer.js
redux/globalReducer.js
+60
-1
Item.js
view/Item.js
+21
-4
ItemShopingCart.js
view/ItemShopingCart.js
+22
-4
No files found.
redux/globalActionType.js
View file @
e1aa0de1
...
@@ -32,7 +32,8 @@ const ActionType = {
...
@@ -32,7 +32,8 @@ const ActionType = {
SET_TRANS_TYPE
:
'SET_TRANS_TYPE'
,
SET_TRANS_TYPE
:
'SET_TRANS_TYPE'
,
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'
,
CHANGE_QUANTITY
:
'CHANGE_QUANTITY'
}
}
export
default
ActionType
;
export
default
ActionType
;
\ No newline at end of file
redux/globalReducer.js
View file @
e1aa0de1
...
@@ -529,6 +529,65 @@ const rootReducer = (state = globalState, action) => {
...
@@ -529,6 +529,65 @@ const rootReducer = (state = globalState, action) => {
}
}
}
}
case
ActionType
.
CHANGE_QUANTITY
:
{
const
item
=
action
.
data
.
item
;
const
new_quantity
=
action
.
data
.
new_quantity
;
let
total
=
0
let
quantity
=
0
let
list_menu
=
[]
let
list_item
=
[]
// ini kalau sudah ada diupdate
if
(
!
isNaN
(
parseInt
(
new_quantity
)))
{
exist
=
false
for
(
let
i
=
0
;
i
<
state
.
order_item
.
length
;
i
++
)
{
const
row
=
state
.
order_item
[
i
];
if
(
row
.
id
==
item
.
id
)
{
// Update Price in Cart
row
.
quantity
=
parseInt
(
new_quantity
)
exist
=
true
}
quantity
+=
parseInt
(
row
.
quantity
)
total
+=
parseInt
(
row
.
price
)
*
parseInt
(
row
.
quantity
)
if
(
row
.
quantity
!=
0
)
{
list_item
.
push
(
row
)
}
}
// kalo belum ada
if
(
!
exist
)
{
list_item
.
push
(
item
)
}
for
(
let
i
=
0
;
i
<
state
.
menu_item
.
length
;
i
++
)
{
const
row
=
state
.
menu_item
[
i
];
console
.
log
(
'MENU : '
+
JSON
.
stringify
(
row
))
// cari sudah ada belum di redux
let
is_xist
=
list_item
.
find
(
it
=>
it
.
id
==
row
.
id
)
if
(
is_xist
)
{
row
[
'qty'
]
=
is_xist
.
quantity
}
else
{
row
[
'qty'
]
=
0
}
list_menu
.
push
(
row
)
}
return
{
...
state
,
menu_item
:
list_menu
,
order_total
:
total
,
order_quantity
:
quantity
,
order_item
:
list_item
,
}
}
}
default
:
default
:
return
state
;
return
state
;
}
}
...
...
view/Item.js
View file @
e1aa0de1
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
{
handleChangeQuantity
=
(
item
,
quantity
)
=>
{
this
.
props
.
changeQuantity
({
item
:
item
,
quantity
:
quantity
})
}
render
()
{
render
()
{
const
{
item
}
=
this
.
props
const
{
item
}
=
this
.
props
// console.log("ini id itemnya "+item.id)
// console.log("ini id itemnya "+item.id)
...
@@ -29,9 +35,8 @@ class Item extends React.Component {
...
@@ -29,9 +35,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"
>
keyboardType
=
{
'numeric'
}
{
item
.
qty
}
onChangeText
=
{(
qty
)
=>
this
.
handleChangeQuantity
(
item
,
qty
)}
>
{
item
.
qty
}
<
/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
>
<
/TouchableOpacity
>
<
/TouchableOpacity
>
...
@@ -110,4 +115,16 @@ const mapStateToProps = (state) => {
...
@@ -110,4 +115,16 @@ const mapStateToProps = (state) => {
}
}
}
}
export
default
connect
(
mapStateToProps
)(
Item
)
const
mapDispatchToProps
=
(
dispacth
)
=>
{
return
{
changeQuantity
:
(
params
)
=>
dispacth
({
type
:
ActionType
.
CHANGE_QUANTITY
,
data
:
{
item
:
params
.
item
,
new_quantity
:
params
.
quantity
}
}),
}
}
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
Item
)
view/ItemShopingCart.js
View file @
e1aa0de1
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
ItemShoping
extends
React
.
Component
{
class
ItemShoping
extends
React
.
Component
{
handleChangeQuantity
=
(
item
,
quantity
)
=>
{
console
.
log
(
'CHange Quantity Shopping CHart : '
+
JSON
.
stringify
(
item
))
console
.
log
(
'new quantity : '
+
quantity
)
this
.
props
.
changeQuantity
({
item
:
item
,
quantity
:
quantity
})
}
render
()
{
render
()
{
const
{
item
}
=
this
.
props
const
{
item
}
=
this
.
props
...
@@ -25,9 +32,8 @@ class ItemShoping extends React.Component {
...
@@ -25,9 +32,8 @@ class ItemShoping 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"
>
keyboardType
=
{
'numeric'
}
{
item
.
quantity
}
onChangeText
=
{(
quantity
)
=>
this
.
handleChangeQuantity
(
item
,
quantity
)}
>
{
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
>
<
/TouchableOpacity
>
<
/TouchableOpacity
>
...
@@ -103,4 +109,16 @@ const mapStateToProps = (state) => {
...
@@ -103,4 +109,16 @@ const mapStateToProps = (state) => {
}
}
}
}
export
default
connect
(
mapStateToProps
)(
ItemShoping
)
const
mapDispatchToProps
=
(
dispacth
)
=>
{
return
{
changeQuantity
:
(
params
)
=>
dispacth
({
type
:
ActionType
.
CHANGE_QUANTITY
,
data
:
{
item
:
params
.
item
,
new_quantity
:
params
.
quantity
}
}),
}
}
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
ItemShoping
)
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