Refactor purgatory list items into own component

pull/10616/head
Alex P 2017-11-14 12:15:25 -08:00
parent ed3200c718
commit 9dc309c0cc
2 changed files with 54 additions and 29 deletions

View File

@ -5,7 +5,7 @@ import {withRouter} from 'react-router'
import {meChangeOrganizationAsync} from 'shared/actions/auth'
import {MEMBER_ROLE} from 'src/auth/Authorized'
import PurgatoryAuthItem from 'src/auth/PurgatoryAuthItem'
const getRoleNameByOrgID = (id, roles) => {
const role = roles.find(r => r.organization === id)
@ -60,34 +60,12 @@ class Purgatory extends Component {
</h6>
{rolesAndOrgs.length
? <div className="auth--list">
{rolesAndOrgs.map(rag =>
<div
key={rag.organization.id}
className={
rag.currentOrganization
? 'auth--list-item current'
: 'auth--list-item'
}
>
<div className="auth--list-info">
<div className="auth--list-org">
{rag.organization.name}
</div>
<div className="auth--list-role">
{rag.role}
</div>
</div>
{rag.role === MEMBER_ROLE
? <span className="auth--list-blocked">
Contact your Admin<br />for access
</span>
: <button
className="btn btn-sm btn-primary"
onClick={this.handleClickLogin(rag.organization)}
>
Login
</button>}
</div>
{rolesAndOrgs.map((rag, i) =>
<PurgatoryAuthItem
key={i}
roleAndOrg={rag}
onClickLogin={this.handleClickLogin}
/>
)}
</div>
: <p>You are a Lost Soul</p>}

View File

@ -0,0 +1,47 @@
import React, {PropTypes} from 'react'
import {MEMBER_ROLE} from 'src/auth/Authorized'
const PurgatoryAuthItem = ({roleAndOrg, onClickLogin}) =>
<div
className={
roleAndOrg.currentOrganization
? 'auth--list-item current'
: 'auth--list-item'
}
>
<div className="auth--list-info">
<div className="auth--list-org">
{roleAndOrg.organization.name}
</div>
<div className="auth--list-role">
{roleAndOrg.role}
</div>
</div>
{roleAndOrg.role === MEMBER_ROLE
? <span className="auth--list-blocked">
Contact your Admin<br />for access
</span>
: <button
className="btn btn-sm btn-primary"
onClick={onClickLogin(roleAndOrg.organization)}
>
Login
</button>}
</div>
const {bool, func, shape, string} = PropTypes
PurgatoryAuthItem.propTypes = {
roleAndOrg: shape({
organization: shape({
name: string,
id: string,
}),
role: string,
currentOrganization: bool,
}).isRequired,
onClickLogin: func.isRequired,
}
export default PurgatoryAuthItem