-
Notifications
You must be signed in to change notification settings - Fork 312
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 #3852 from DaleMcGrew/Dale_WebApp_Mar2-2024
Added standard LinkToAdminTools, so we don't have to deal with voter object directly in the components that need a link to administration tools. MERGE READY
- Loading branch information
Showing
5 changed files
with
114 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, { Component, Suspense } from 'react'; | ||
import styled from 'styled-components'; | ||
import { isCordova } from '../../utils/isCordovaOrWebApp'; | ||
import VoterStore from '../../../stores/VoterStore'; | ||
|
||
const OpenExternalWebSite = React.lazy(() => import(/* webpackChunkName: 'OpenExternalWebSite' */ './OpenExternalWebSite')); | ||
|
||
class LinkToAdminTools extends Component { | ||
constructor (props) { | ||
super(props); | ||
this.state = { | ||
voter: null, | ||
}; | ||
} | ||
|
||
componentDidMount () { | ||
this.onVoterStoreChange(); | ||
this.voterStoreListener = VoterStore.addListener(this.onVoterStoreChange.bind(this)); | ||
} | ||
|
||
componentWillUnmount () { | ||
this.voterStoreListener.remove(); | ||
} | ||
|
||
onVoterStoreChange = () => { | ||
this.setState({ | ||
voter: VoterStore.getVoter(), | ||
}); | ||
}; | ||
|
||
render () { | ||
const { adminToolsUrl, linkId, linkTextNode } = this.props; | ||
const { voter } = this.state; | ||
return ( | ||
<LinkToAdminToolsWrapper> | ||
{/* Show links to this candidate in the admin tools */} | ||
{(voter && (voter.is_admin || voter.is_political_data_manager || voter.is_verified_volunteer)) && ( | ||
<span className="u-wrap-links d-print-none"> | ||
Admin only: | ||
<Suspense fallback={<></>}> | ||
<OpenExternalWebSite | ||
linkIdAttribute={linkId || 'linkToAdminTools'} | ||
url={adminToolsUrl} | ||
target="_blank" | ||
className="open-web-site open-web-site__no-right-padding" | ||
body={linkTextNode || <span>edit</span>} | ||
/> | ||
</Suspense> | ||
</span> | ||
)} | ||
</LinkToAdminToolsWrapper> | ||
); | ||
} | ||
} | ||
LinkToAdminTools.propTypes = { | ||
linkId: PropTypes.string, | ||
linkTextNode: PropTypes.node, | ||
adminToolsUrl: PropTypes.string.isRequired, | ||
}; | ||
|
||
const LinkToAdminToolsWrapper = styled('div')` | ||
margin-top: ${() => (isCordova() ? '100px' : '20px')}; | ||
padding-bottom: ${() => (isCordova() ? '100px' : '20px')}; | ||
`; | ||
|
||
export default LinkToAdminTools; |
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