Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
warehouse-management
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
1
Merge Requests
1
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
warehouse-management
Commits
115885b5
Commit
115885b5
authored
May 08, 2021
by
Darrick Yong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add session gating
parent
3cf4295f
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
137 additions
and
30 deletions
+137
-30
master.css
frontend/public/stylesheets/master.css
+1
-0
session.css
frontend/public/stylesheets/session.css
+5
-0
App.jsx
frontend/src/App.jsx
+0
-2
Root.jsx
frontend/src/Root.jsx
+26
-0
session_actions.js
frontend/src/actions/session_actions.js
+24
-0
Header.jsx
frontend/src/components/header/Header.jsx
+11
-7
Login.jsx
frontend/src/components/session/Login.jsx
+19
-11
Logout.jsx
frontend/src/components/session/Logout.jsx
+13
-8
index.jsx
frontend/src/index.jsx
+2
-2
root_reducer.js
frontend/src/reducers/root_reducer.js
+2
-0
session_reducer.js
frontend/src/reducers/session/session_reducer.js
+23
-0
session_api_util.jsx
frontend/src/util/session_api_util.jsx
+11
-0
No files found.
frontend/public/stylesheets/master.css
View file @
115885b5
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
@import
'./footer.css'
;
@import
'./footer.css'
;
@import
'./filter.css'
;
@import
'./filter.css'
;
@import
'./order.css'
;
@import
'./order.css'
;
@import
'./session.css'
;
/* background: #2b4162; */
/* background: #2b4162; */
/* background: #4daa57 */
/* background: #4daa57 */
...
...
frontend/public/stylesheets/session.css
0 → 100644
View file @
115885b5
.login
{
padding
:
50px
;
display
:
flex
;
justify-content
:
center
;
}
\ No newline at end of file
frontend/src/App.jsx
View file @
115885b5
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
connect
}
from
"react-redux"
;
import
{
connect
}
from
"react-redux"
;
import
Header
from
"./components/header/Header"
;
import
OrderIndex
from
"./components/order/OrderIndex"
;
import
OrderIndex
from
"./components/order/OrderIndex"
;
import
NoOrders
from
"./components/order/NoOrders"
;
import
NoOrders
from
"./components/order/NoOrders"
;
import
{
fetchOrders
}
from
"./actions/order_actions"
;
import
{
fetchOrders
}
from
"./actions/order_actions"
;
...
@@ -23,7 +22,6 @@ const App = ({ orders, fetchOrders }) => {
...
@@ -23,7 +22,6 @@ const App = ({ orders, fetchOrders }) => {
return
(
return
(
<
div
className=
"app"
>
<
div
className=
"app"
>
<
Header
/>
<
div
className=
"fs-collapse"
>
<
div
className=
"fs-collapse"
>
<
FilterSearch
setOrdersToShow=
{
setOrdersToShow
}
/>
<
FilterSearch
setOrdersToShow=
{
setOrdersToShow
}
/>
<
div
className=
"collapse-expand"
>
<
div
className=
"collapse-expand"
>
...
...
frontend/src/Root.jsx
0 → 100644
View file @
115885b5
import
{
connect
}
from
"react-redux"
;
import
Header
from
"./components/header/Header"
;
import
App
from
"./App"
import
Login
from
"./components/session/Login"
;
const
Root
=
({
isLoggedIn
})
=>
{
return
(
<
div
>
<
Header
/>
{
isLoggedIn
?
<
App
/>
:
<
Login
/>
}
</
div
>
);
}
const
mapStateToProps
=
(
state
)
=>
({
isLoggedIn
:
state
.
session
.
isAuthenticated
,
});
const
mapDispatchToProps
=
(
dispatch
)
=>
({
});
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
Root
);
\ No newline at end of file
frontend/src/actions/session_actions.js
0 → 100644
View file @
115885b5
import
*
as
SessionAPIUtil
from
"../util/session_api_util"
;
export
const
LOGIN_USER
=
'LOGIN_USER'
;
export
const
LOGOUT_USER
=
'LOGOUT_USER'
;
const
receiveLogin
=
(
user
)
=>
({
type
:
LOGIN_USER
,
user
,
})
const
receiveLogout
=
()
=>
({
type
:
LOGOUT_USER
,
})
export
const
login
=
payload
=>
dispatch
=>
{
SessionAPIUtil
.
createSession
(
payload
)
.
then
(
res
=>
{
dispatch
(
receiveLogin
(
res
))
})
}
export
const
logout
=
()
=>
dispatch
=>
{
dispatch
(
receiveLogout
());
}
frontend/src/components/header/Header.jsx
View file @
115885b5
import
React
from
"react
"
;
import
{
connect
}
from
"react-redux
"
;
import
Image
from
"../atoms/Image"
;
import
Image
from
"../atoms/Image"
;
import
Logout
from
"../session/Logout"
;
import
Logout
from
"../session/Logout"
;
const
Header
=
()
=>
{
const
Header
=
(
{
isLoggedIn
,
logout
}
)
=>
{
return
(
return
(
<
div
className=
"header"
>
<
div
className=
"header"
>
<
div
>
<
div
>
<
Image
src=
"https://www.flaticon.com/svg/vstatic/svg/2562/2562296.svg?token=exp=1620448865~hmac=b6bb0b0a072e16f423c481f7a3175fa9"
/>
{
" "
}
<
Image
src=
"https://www.flaticon.com/svg/vstatic/svg/2562/2562296.svg?token=exp=1620448865~hmac=b6bb0b0a072e16f423c481f7a3175fa9"
/>
{
" "
}
<
div
>
<
div
>
Warehouse Management
</
div
>
Warehouse Management
</
div
>
</
div
>
</
div
>
<
Logout
/>
{
isLoggedIn
?
<
Logout
onClick=
{
logout
}
/>
:
null
}
</
div
>
</
div
>
);
);
};
};
export
default
Header
;
const
mapStateToProps
=
(
state
)
=>
({
isLoggedIn
:
state
.
session
.
isAuthenticated
,
});
const
mapDispatchToProps
=
(
dispatch
)
=>
({});
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
Header
);
frontend/src/components/session/Login.jsx
View file @
115885b5
import
React
from
'react'
;
import
React
from
"react"
;
import
{
connect
}
from
"react-redux"
;
import
{
GoogleLogin
}
from
"react-google-login"
;
import
{
GoogleLogin
}
from
"react-google-login"
;
import
keys
from
"../../config/keys_dev"
import
keys
from
"../../config/keys_dev"
;
import
{
login
}
from
"../../actions/session_actions"
;
const
clientId
=
keys
.
clientId
;
const
clientId
=
keys
.
clientId
;
const
Login
=
()
=>
{
const
Login
=
(
{
login
}
)
=>
{
const
responseGoogle
=
(
googleResponse
)
=>
{
const
responseGoogle
=
(
response
)
=>
{
const
{
tokenId
,
profileObj
}
=
googleResponse
;
console
.
log
(
response
);
login
({
token
:
tokenId
,
user
:
profileObj
}
);
};
};
return
(
return
(
<
div
>
<
div
className=
"login"
>
<
GoogleLogin
<
GoogleLogin
clientId=
{
clientId
}
clientId=
{
clientId
}
buttonText=
"Login with Google"
buttonText=
"Login with Google"
onSuccess=
{
responseGoogle
}
onSuccess=
{
responseGoogle
}
onFailure=
{
responseGoogle
}
onFailure=
{
responseGoogle
}
cookiePolicy=
{
"single_host_origin"
}
cookiePolicy=
{
"single_host_origin"
}
//
isSignedIn={true}
isSignedIn=
{
true
}
/>
/>
</
div
>
</
div
>
);
);
}
};
const
mapStateToProps
=
(
state
)
=>
({});
const
mapDispatchToProps
=
(
dispatch
)
=>
({
login
:
(
token
)
=>
dispatch
(
login
(
token
)),
});
export
default
Login
;
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
Login
);
\ No newline at end of file
frontend/src/components/session/Logout.jsx
View file @
115885b5
import
React
from
"react
"
;
import
{
connect
}
from
"react-redux
"
;
import
{
GoogleLogout
}
from
"react-google-login"
;
import
{
GoogleLogout
}
from
"react-google-login"
;
import
{
logout
}
from
"../../actions/session_actions"
;
import
keys
from
"../../config/keys_dev"
;
import
keys
from
"../../config/keys_dev"
;
const
clientId
=
keys
.
clientId
;
const
clientId
=
keys
.
clientId
;
const
Logout
=
()
=>
{
const
Logout
=
({
logout
})
=>
{
const
responseGoogle
=
(
googleResponse
)
=>
{
const
responseGoogle
=
(
response
)
=>
{
logout
();
console
.
log
(
response
);
};
};
return
(
return
(
...
@@ -16,10 +16,15 @@ const Logout = () => {
...
@@ -16,10 +16,15 @@ const Logout = () => {
clientId=
{
clientId
}
clientId=
{
clientId
}
buttonText=
"Logout"
buttonText=
"Logout"
onLogoutSuccess=
{
responseGoogle
}
onLogoutSuccess=
{
responseGoogle
}
isSignedIn=
{
true
}
/>
/>
</
div
>
</
div
>
);
);
};
};
export
default
Logout
;
const
mapStateToProps
=
(
state
)
=>
({});
const
mapDispatchToProps
=
(
dispatch
)
=>
({
logout
:
()
=>
dispatch
(
logout
()),
});
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
Logout
);
frontend/src/index.jsx
View file @
115885b5
import
React
from
'react'
;
import
React
from
'react'
;
import
ReactDOM
from
'react-dom'
;
import
ReactDOM
from
'react-dom'
;
import
App
from
'./App'
;
import
reportWebVitals
from
'./reportWebVitals'
;
import
reportWebVitals
from
'./reportWebVitals'
;
import
configureStore
from
'./store/store'
;
import
configureStore
from
'./store/store'
;
import
{
Provider
}
from
'react-redux'
;
import
{
Provider
}
from
'react-redux'
;
import
Root
from
'./Root'
;
document
.
addEventListener
(
'DOMContentLoaded'
,
()
=>
{
document
.
addEventListener
(
'DOMContentLoaded'
,
()
=>
{
...
@@ -11,7 +11,7 @@ document.addEventListener('DOMContentLoaded', () => {
...
@@ -11,7 +11,7 @@ document.addEventListener('DOMContentLoaded', () => {
ReactDOM
.
render
(
ReactDOM
.
render
(
<
Provider
store=
{
store
}
>
<
Provider
store=
{
store
}
>
<
App
/>
<
Root
/>
</
Provider
>,
</
Provider
>,
document
.
getElementById
(
'root'
)
document
.
getElementById
(
'root'
)
);
);
...
...
frontend/src/reducers/root_reducer.js
View file @
115885b5
import
{
combineReducers
}
from
"redux"
;
import
{
combineReducers
}
from
"redux"
;
import
entities
from
"./entities/entities_reducer"
;
import
entities
from
"./entities/entities_reducer"
;
import
session
from
"./session/session_reducer"
;
const
RootReducer
=
combineReducers
({
const
RootReducer
=
combineReducers
({
entities
,
entities
,
session
,
});
});
export
default
RootReducer
;
export
default
RootReducer
;
frontend/src/reducers/session/session_reducer.js
0 → 100644
View file @
115885b5
import
{
LOGIN_USER
,
LOGOUT_USER
}
from
"../../actions/session_actions"
;
const
initialState
=
{
isAuthenticated
:
false
,
user
:
null
}
const
SessionState
=
(
oldState
=
initialState
,
action
)
=>
{
Object
.
freeze
(
oldState
);
switch
(
action
.
type
)
{
case
LOGIN_USER
:
return
{
isAuthenticated
:
!!
action
.
user
,
user
:
action
.
user
,
}
case
LOGOUT_USER
:
return
initialState
;
default
:
return
oldState
;
}
}
export
default
SessionState
;
\ No newline at end of file
frontend/src/util/session_api_util.jsx
0 → 100644
View file @
115885b5
// import axios from 'axios';
export
const
createSession
=
(
payload
)
=>
{
const
{
token
,
user
}
=
payload
;
// call axios with token
return
new
Promise
((
resolve
,
reject
)
=>
{
resolve
(
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