-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1259 from sharetribe/login-as-user-banner
Show a banner when user is logged in with limited access
- Loading branch information
Showing
8 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
src/components/LimitedAccessBanner/LimitedAccessBanner.css
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,31 @@ | ||
@import '../../marketplace.css'; | ||
|
||
.root { | ||
background-color: #df492a; | ||
text-align: center; | ||
padding: 10px 20px 9px; | ||
} | ||
|
||
.text { | ||
margin: 0; | ||
display: inline-block; | ||
color: #fff; | ||
font-size: 16px; | ||
margin-bottom: 16px; | ||
line-height: 20px; | ||
} | ||
|
||
.button { | ||
background: #2a3d4b; | ||
margin: 0 16px; | ||
padding: 8px 16px; | ||
border-radius: 4px; | ||
font-size: 14px; | ||
color: #fff; | ||
border: 0; | ||
|
||
&:hover { | ||
text-decoration: none; | ||
background: #364f61; | ||
} | ||
} |
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,68 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import { FormattedMessage } from '../../util/reactIntl'; | ||
import { propTypes } from '../../util/types'; | ||
import { Button } from '../../components'; | ||
import { ensureCurrentUser } from '../../util/data'; | ||
|
||
import css from './LimitedAccessBanner.css'; | ||
|
||
// Due to the layout structure, do not render the banner on the following pages | ||
const disabledPages = ['SearchPage']; | ||
|
||
const LimitedAccessBanner = props => { | ||
const { | ||
rootClassName, | ||
className, | ||
isAuthenticated, | ||
authScopes, | ||
currentUser, | ||
onLogout, | ||
currentPage, | ||
} = props; | ||
const classes = classNames(rootClassName || css.root, className); | ||
const user = ensureCurrentUser(currentUser); | ||
|
||
const showBanner = | ||
user.id && | ||
isAuthenticated && | ||
authScopes.length === 1 && | ||
authScopes[0] === 'user:limited' && | ||
!disabledPages.includes(currentPage); | ||
|
||
const { firstName, lastName } = user.attributes.profile; | ||
|
||
return showBanner ? ( | ||
<div className={classes}> | ||
<p className={css.text}> | ||
<FormattedMessage id="LimitedAccessBanner.message" values={{ firstName, lastName }} /> | ||
</p> | ||
<Button rootClassName={css.button} onClick={onLogout}> | ||
<FormattedMessage id="LimitedAccessBanner.logout" /> | ||
</Button> | ||
</div> | ||
) : null; | ||
}; | ||
|
||
LimitedAccessBanner.defaultProps = { | ||
rootClassName: null, | ||
className: null, | ||
currentUser: null, | ||
authScopes: [], | ||
currentPage: null, | ||
}; | ||
|
||
const { array, bool, func, string } = PropTypes; | ||
|
||
LimitedAccessBanner.propTypes = { | ||
rootClassName: string, | ||
className: string, | ||
isAuthenticated: bool.isRequired, | ||
authScopes: array, | ||
currentUser: propTypes.currentUser, | ||
onLogout: func.isRequired, | ||
currentPage: string, | ||
}; | ||
|
||
export default LimitedAccessBanner; |
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
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
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