import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import ConnectedSiteEntry from './connected-site-row' import TextField from '../../../components/ui/text-field' import Button from '../../../components/ui/button' export default class ConnectionsTab extends PureComponent { static contextTypes = { t: PropTypes.func, metricsEvent: PropTypes.func, } static defaultProps = { activeTab: {}, } static propTypes = { activeTab: PropTypes.object, approvedOrigins: PropTypes.object.isRequired, approveProviderRequestByOrigin: PropTypes.func.isRequired, rejectProviderRequestByOrigin: PropTypes.func.isRequired, showClearApprovalModal: PropTypes.func.isRequired, } state = { input: this.props.activeTab.origin || '', } handleAddOrigin = () => { const newOrigin = this.state.input this.setState({ input: '', }, () => { if (newOrigin && newOrigin.trim()) { this.props.approveProviderRequestByOrigin(newOrigin) } }) } renderNewOriginInput () { const { t } = this.context return (
{ t('addSite') }
{ t('addSiteDescription') }
this.setState({ input: e.target.value })} fullWidth margin="dense" min={0} />
) } renderApprovedOriginsList () { const { t } = this.context const { approvedOrigins, rejectProviderRequestByOrigin, showClearApprovalModal } = this.props const approvedEntries = Object.entries(approvedOrigins) const approvalListEmpty = approvedEntries.length === 0 return (
{ t('connected') } { t('connectedDescription') }
{ approvalListEmpty ?
: null } { approvedEntries.map(([origin, { siteTitle, siteImage }]) => ( { rejectProviderRequestByOrigin(origin) }} /> )) }
) } render () { return (
{ this.renderNewOriginInput() } { this.renderApprovedOriginsList() }
) } }