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