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
f190a1b5
Commit
f190a1b5
authored
May 10, 2021
by
Xiyang Lu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AFP-35] Joe connected frontend and backend/ sent user detail to backend
parent
3bea8ff0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
22 deletions
+38
-22
session_actions.js
ecom-web/src/actions/session_actions.js
+14
-14
header.js
ecom-web/src/components/Header/header.js
+0
-1
session-container.jsx
ecom-web/src/components/session/session-container.jsx
+1
-1
session.jsx
ecom-web/src/components/session/session.jsx
+17
-4
user_reducer.js
ecom-web/src/reducers/user_reducer.js
+1
-1
session-api-util.js
ecom-web/src/util/session-api-util.js
+5
-1
No files found.
ecom-web/src/actions/session_actions.js
View file @
f190a1b5
//
import {postUser} from '../util/session-api-util'
import
{
postUser
}
from
'../util/session-api-util'
export
const
SET_CURRENT_USER
=
"SET_CURRENT_USER"
export
const
LOGOUT_USER
=
"LOGOUT_USER"
export
const
setCurrentUser
=
()
=>
{
return
{
type
:
SET_CURRENT_USER
}
export
const
setCurrentUser
=
(
user
)
=>
{
return
{
type
:
SET_CURRENT_USER
,
user
}
}
export
const
logoutUser
=
()
=>
{
return
{
type
:
LOGOUT_USER
}
}
//
export const login = (user) => dispatch => {
// return postUser(user).then((response)=>
//
dispatch(setCurrentUser(response))
// )
// }
export
const
login
=
()
=>
{
return
(
dispatch
)
=>
{
return
dispatch
(
setCurrentUser
());
};
};
export
const
login
=
(
user
)
=>
dispatch
=>
{
return
postUser
(
user
).
then
((
response
)
=>
(
dispatch
(
setCurrentUser
(
response
))
)
)
}
//
export const login = () => {
//
return (dispatch) => {
//
return dispatch(setCurrentUser());
//
};
//
};
export
const
logOut
=
()
=>
{
return
(
dispatch
)
=>
{
...
...
ecom-web/src/components/Header/header.js
View file @
f190a1b5
import
React
,
{
Component
}
from
'react'
import
Nav
from
'react-bootstrap/Nav'
import
Navbar
from
'react-bootstrap/Navbar'
import
NavDropdown
from
'react-bootstrap/NavDropdown'
import
Session
from
'../session/session-container'
export
default
class
Header
extends
Component
{
...
...
ecom-web/src/components/session/session-container.jsx
View file @
f190a1b5
...
...
@@ -7,7 +7,7 @@ const mSTP = state => ({
});
const
mDTP
=
dispatch
=>
({
login
:
(
)
=>
dispatch
(
login
(
)),
login
:
(
userResponse
)
=>
dispatch
(
login
(
userResponse
)),
logOut
:
()
=>
dispatch
(
logOut
())
});
...
...
ecom-web/src/components/session/session.jsx
View file @
f190a1b5
...
...
@@ -6,14 +6,26 @@ const clientId = `${process.env.REACT_APP_GOOGLE_CLIENT_ID}.apps.googleuserconte
export
default
class
Session
extends
Component
{
constructor
(
props
)
{
super
(
props
)
this
.
state
=
{
logIn
:
false
}
this
.
loginSuccess
=
this
.
loginSuccess
.
bind
(
this
)
this
.
loginFailed
=
this
.
loginFailed
.
bind
(
this
)
this
.
logOutSuccess
=
this
.
logOutSuccess
.
bind
(
this
)
}
// componentDidMount(){
// this.props.logOut()
// }
loginSuccess
=
(
response
)
=>
{
console
.
log
(
'Login Success: currentUser:'
,
response
);
this
.
props
.
login
()
const
{
accessToken
,
tokenId
,
googleId
:
userId
,
profileObj
}
=
response
const
{
email
,
familyName
:
lastName
,
givenName
:
firstName
}
=
profileObj
const
userResponse
=
{
idToken
:
tokenId
,
userId
,
email
,
firstName
,
lastName
,
accessToken
}
this
.
props
.
login
(
userResponse
)
this
.
setState
({
logIn
:
true
})
}
loginFailed
=
(
response
)
=>
{
...
...
@@ -21,14 +33,15 @@ export default class Session extends Component {
}
logOutSuccess
=
(
response
)
=>
{
console
.
log
(
'Logout made successfully'
);
this
.
props
.
logOut
()
this
.
setState
({
logIn
:
false
})
}
render
()
{
return
(
<
div
>
{
this
.
props
.
currentUser
===
null
?
{
console
.
log
(
this
.
props
.
currentUser
)
}
{
!
this
.
state
.
logIn
?
<
GoogleLogin
clientId=
{
clientId
}
buttonText=
"Login"
...
...
ecom-web/src/reducers/user_reducer.js
View file @
f190a1b5
...
...
@@ -6,7 +6,7 @@ const userReducer = (state = initialState, action) => {
let
newState
=
Object
.
assign
({},
state
);
switch
(
action
.
type
)
{
case
SET_CURRENT_USER
:
return
newState
.
currentUser
=
{
emailAddress
:
'fakeEmail@123'
}
;
return
newState
.
currentUser
=
action
.
user
.
data
;
case
LOGOUT_USER
:
return
newState
.
currentUser
=
null
;
...
...
ecom-web/src/util/session-api-util.js
View file @
f190a1b5
import
axios
from
'axios'
;
export
const
postUser
=
(
user
)
=>
{
return
axios
.
post
(
"http://localhost:8080/api/users"
,
user
)
}
// export const postUser = (user) => {
// return
currentUser
// return
fetch("http://localhost:8080/api/users", {method: "POST", body: JSON.stringify(user), headers: {"Content-Type": "application/json"}})
// }
// export const postLogOutUser = (user) => {
...
...
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