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
aa56680d
Commit
aa56680d
authored
Apr 22, 2020
by
Wahyu Adjie Prasetyo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ini
parent
0881d4c0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
27 deletions
+38
-27
globalActionType.js
redux/globalActionType.js
+1
-0
globalReducer.js
redux/globalReducer.js
+25
-9
MenuSelection.js
view/MenuSelection.js
+12
-18
No files found.
redux/globalActionType.js
View file @
aa56680d
...
...
@@ -22,6 +22,7 @@ const ActionType = {
SET_CHANGE_CAMERA_ID
:
'SET_CHANGE_CAMERA_ID'
,
SET_CHANGE_OUTLET
:
'SET_CHANGE_OUTLET'
,
SET_CHANGE_SHOP
:
'SET_CHANGE_SHOP'
,
ADD_TO_CHART
:
'ADD_TO_CHART'
,
}
...
...
redux/globalReducer.js
View file @
aa56680d
...
...
@@ -53,6 +53,10 @@ const globalState = {
quantity
:
0
,
orders
:
0
,
cart_shop
:[],
order_item
:
[],
order_quantity
:
0
,
order_total
:
0
}
const
rootReducer
=
(
state
=
globalState
,
action
)
=>
{
...
...
@@ -192,16 +196,8 @@ const rootReducer = (state = globalState, action) => {
}
}
case
ActionType
.
SET_CHANGE_SHOP
:{
let
is_exists
=
cart_shop
.
find
(
item
=>
item
.
id
===
action
.
data
.
id
)
if
(
is_exists
)
{
// update
}
else
{
// add
}
return
{
...
state
}
}
case
ActionType
.
SET_LOGOUT
:{
...
...
@@ -210,6 +206,26 @@ const rootReducer = (state = globalState, action) => {
session_id
:
action
.
data
.
session_id
,
}
}
case
ActionType
.
ADD_TO_CHART
:{
let
addedItem
=
action
.
data
.
order_item
let
is_exist
=
cart_shop
.
find
(
item
=>
addedItem
.
id
==
item
.
id
)
if
(
is_exist
)
{
// update
addedItem
.
quantity
+=
1
}
else
{
// add
addedItem
.
quantity
=
1
}
let
quantity
=
order_quantity
+
1
let
total
=
order_total
+
addedItem
.
price
return
{
...
state
,
order_item
:
[...
state
.
order_item
,
addedItem
],
order_quantity
:
quantity
,
order_total
:
total
}
}
default
:
...
...
view/MenuSelection.js
View file @
aa56680d
...
...
@@ -79,25 +79,13 @@ class MenuSelection extends React.Component {
}
handleAdd
(
item
,
index
)
{
// const listMenu = [...this.state.listMenu]
// listMenu[index].qty += 1
const
order
=
{
handleAdd
(
item
)
{
const
order_item
=
{
id
:
item
.
id
,
name
:
item
.
name
,
price
:
item
.
price
,
quantity
:
1
}
this
.
state
.
list_orders
.
push
(
order
);
this
.
setState
({
listMenu
})
let
InsertCart
=
{
cart_shop
:
this
.
state
.
list_orders
}
this
.
props
.
setCartInsert
(
InsertCart
)
this
.
props
.
addToChart
(
order_item
)
}
...
...
@@ -128,7 +116,7 @@ class MenuSelection extends React.Component {
renderItem
=
{({
item
,
index
})
=>
(
<
Item
navigation
=
{
this
.
props
.
navigation
}
item
=
{
item
}
handleAdd
=
{()
=>
this
.
handleAdd
(
item
,
index
)}
handleAdd
=
{()
=>
this
.
handleAdd
(
item
)}
handleRemove
=
{()
=>
this
.
handleRemove
(
item
,
index
)}
refreshing
=
{
this
.
state
.
isFetching
}
/
>
...
...
@@ -190,10 +178,16 @@ const mapStateToProps = (state) => {
const
mapDispatchToProps
=
(
dispacth
)
=>
{
return
{
setCartInsert
:
(
InsertCart
)
=>
dispacth
({
setCartInsert
:
(
data
)
=>
dispacth
({
type
:
ActionType
.
SET_CHANGE_SHOP
,
data
:
{
cart_shop
:
InsertCart
.
cart_shop
id
:
data
.
cart_shop
}
}),
addToChart
:
(
order_item
)
=>
dispacth
({
type
:
ActionType
.
ADD_TO_CHART
,
data
:
{
order_item
:
order_item
}
}),
}
...
...
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