Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ecommerce-maven
Project
Project
Details
Activity
Releases
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
Ascend
ecommerce-maven
Commits
8a4d479a
Commit
8a4d479a
authored
May 12, 2021
by
Christopher Cottier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proper state management of order history
parent
0988926b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
10 deletions
+38
-10
order_history_actions.js
ecom-web/src/actions/order_history_actions.js
+16
-0
order-history.jsx
ecom-web/src/components/order-history/order-history.jsx
+13
-10
order_reducer.js
ecom-web/src/reducers/order_reducer.js
+9
-0
No files found.
ecom-web/src/actions/order_history_actions.js
0 → 100644
View file @
8a4d479a
import
OrderHistory
from
"../components/order-history/order-history"
;
import
{
getOrderHistory
}
from
"../util/order_api_util"
;
export
const
SET_USER_HISTORY
=
"SET_USER_HISTORY"
;
export
const
dispatchOrderHistory
=
(
userId
)
=>
async
dispatch
=>
{
const
orderHistory
=
await
getOrderHistory
(
userId
);
return
dispatch
(
orderHistoryAction
(
orderHistory
));
}
const
orderHistoryAction
=
(
orderHistory
)
=>
(
{
type
:
SET_USER_HISTORY
,
orderHistory
}
)
\ No newline at end of file
ecom-web/src/components/order-history/order-history.jsx
View file @
8a4d479a
import
React
,
{
useEffect
,
useState
}
from
'react'
import
{
useSelector
}
from
'react-redux'
;
import
{
useDispatch
,
useSelector
}
from
'react-redux'
;
import
{
dispatchOrderHistory
}
from
'../../actions/order_history_actions'
;
import
{
getOrderHistory
}
from
'../../util/order_api_util'
;
import
Order
from
'./Order'
;
...
...
@@ -7,22 +8,24 @@ import './order-history.css'
const
OrderHistory
=
()
=>
{
const
[
orderHistory
,
setOrderHistory
]
=
useState
([]);
const
[
callMade
,
setCallMade
]
=
useState
(
false
);
const
dispatch
=
useDispatch
();
const
{
currentUser
}
=
useSelector
(
state
=>
state
.
user
);
const
user
=
useSelector
(
state
=>
state
.
user
);
const
{
orderHistory
}
=
useSelector
(
state
=>
state
.
orderStatus
)
//const [callMade, setCallMade] = useState(false);
useEffect
(
async
()
=>
{
if
(
callMade
||
currentUser
===
null
)
return
;
const
userHistory
=
await
getOrderHistory
(
currentUser
.
userId
);
//insert user id from user details stored in redux
setOrderHistory
(
userHistory
);
setCallMade
(
true
);
});
if
(
!
user
)
return
;
if
(
!
user
.
currentUser
)
return
;
dispatch
(
dispatchOrderHistory
(
user
.
currentUser
.
userId
)
);
//
setCallMade(true);
}
,
[
user
]
);
return
(
<
main
>
<
h1
id=
"order-history-header"
>
Order History
</
h1
>
{
currentU
ser
===
null
?
(
{
u
ser
===
null
?
(
<
div
>
Please login to place orders!
</
div
>
)
:
null
}
<
div
id=
"orders"
>
...
...
ecom-web/src/reducers/order_reducer.js
View file @
8a4d479a
import
{
SET_USER_HISTORY
}
from
'../actions/order_history_actions'
;
import
{
LOGOUT_USER
}
from
'../actions/session_actions'
;
import
{
SEND_USER_ORDER
}
from
'./../actions/checkout_actions'
const
initialState
=
{
orderResponse
:
{},
orderHistory
:
[]
}
const
orderReducer
=
(
prevState
=
initialState
,
action
)
=>
{
...
...
@@ -13,6 +16,12 @@ const orderReducer = (prevState = initialState, action) => {
nextState
.
orderResponse
=
action
.
payload
return
nextState
case
SET_USER_HISTORY
:
nextState
.
orderHistory
=
action
.
orderHistory
;
return
nextState
;
case
LOGOUT_USER
:
nextState
.
orderHistory
=
[];
return
nextState
;
default
:
return
nextState
}
...
...
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