-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad407bb
commit 3af340e
Showing
20 changed files
with
925 additions
and
217 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import LoginSession from 'components/LoginSession/LoginSession'; | ||
import LoginSessionContainer from 'components/LoginSession/LoginSessionContainer'; | ||
import SessionManagerField from 'components/SessionManagerField/SessionManagerField'; | ||
import Injector from 'lib/Injector'; | ||
|
||
export default () => { | ||
Injector.component.registerMany({ | ||
LoginSession, | ||
LoginSessionContainer, | ||
SessionManagerField, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
.login-session { | ||
max-height: 100%; | ||
&.hidden { | ||
visibility: hidden; | ||
opacity: 0; | ||
transition: visibility 0s 2s, opacity 2s linear; | ||
max-height: 0; | ||
transition: visibility 0s 1s, opacity 1s linear, max-height 1s linear; | ||
} | ||
|
||
p { | ||
margin: 0; | ||
|
||
&:last-of-type { | ||
padding-bottom: 20px; | ||
} | ||
} | ||
} | ||
|
||
.login-session__logout:not([href]) { | ||
cursor: pointer; | ||
color: $link-color; | ||
.login-session__logout { | ||
font-weight: bold; | ||
outline: none; | ||
|
||
&:hover, &:active { | ||
text-decoration: underline; | ||
} | ||
padding: 0; | ||
} |
88 changes: 88 additions & 0 deletions
88
client/src/components/LoginSession/LoginSessionContainer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import PropTypes from 'prop-types'; | ||
// import React, { Fragment } from 'react'; | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import backend from 'lib/Backend'; | ||
import Config from 'lib/Config'; // eslint-disable-line | ||
import LoginSession from './LoginSession'; | ||
import { success, error } from 'state/toasts/ToastsActions'; | ||
|
||
// Handle communication with server on logout and toast notifications via redux | ||
// Using a class component rather than function component so that LoginSessionContainer-test.js | ||
// can use wrapper.instance() to test logout() | ||
class LoginSessionContainer extends Component { | ||
// | ||
constructor(props) { | ||
super(props); | ||
this.createEndpoint = this.createEndpoint.bind(this); | ||
this.logout = this.logout.bind(this); | ||
} | ||
|
||
createEndpoint() { | ||
return backend.createEndpointFetcher({ | ||
url: `${this.props.LogOutEndpoint}/:id`, | ||
method: 'delete', | ||
payloadSchema: { | ||
id: { urlReplacement: ':id', remove: true }, | ||
SecurityID: { querystring: true } | ||
} | ||
}); | ||
} | ||
|
||
// params are 3x callbacks defined within LoginSession | ||
logout(beforeRequest, receivedResponse, caughtException) { | ||
beforeRequest(); | ||
const endpoint = this.createEndpoint(); | ||
endpoint({ | ||
id: this.props.ID, | ||
SecurityID: Config.get('SecurityID') | ||
}) | ||
.then(response => { | ||
const failed = !response.success; | ||
receivedResponse(failed); | ||
if (failed) { | ||
this.props.displayToastFailure(response.message); | ||
} else { | ||
this.props.displayToastSuccess(response.message); | ||
} | ||
}) | ||
.catch(() => { | ||
caughtException(); | ||
}); | ||
} | ||
|
||
render() { | ||
const { ID, LogoutEndPoint, ...loginSessionProps } = { ...this.props }; | ||
const newProps = { logout: this.logout, ...loginSessionProps }; | ||
return <LoginSession {...newProps} />; | ||
} | ||
} | ||
|
||
LoginSessionContainer.propTypes = { | ||
// LoginSessionContainer specific: | ||
ID: PropTypes.number.isRequired, | ||
LogOutEndpoint: PropTypes.string.isRequired, | ||
displayToastSuccess: PropTypes.func, | ||
displayToastFailure: PropTypes.func, | ||
// Passed on to LoginSession: | ||
IPAddress: PropTypes.string.isRequired, | ||
IsCurrent: PropTypes.bool, | ||
UserAgent: PropTypes.string, | ||
Created: PropTypes.string.isRequired, | ||
LastAccessed: PropTypes.string.isRequired, | ||
}; | ||
|
||
function mapDispatchToProps(dispatch) { | ||
return { | ||
displayToastSuccess(message) { | ||
dispatch(success(message)); | ||
}, | ||
displayToastFailure(message) { | ||
dispatch(error(message)); | ||
}, | ||
}; | ||
} | ||
|
||
export { LoginSessionContainer as Component }; | ||
|
||
export default connect(() => ({}), mapDispatchToProps)(LoginSessionContainer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.