2020-12-29 13:55:04 -08:00
import React from 'react' ;
import { defineMessages , injectIntl } from 'react-intl' ;
import { connect } from 'react-redux' ;
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import PropTypes from 'prop-types' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import Column from '../ui/components/column' ;
2020-12-29 16:22:31 -08:00
import ScrollableList from 'soapbox/components/scrollable_list' ;
2021-07-13 15:59:55 -07:00
import UnapprovedAccount from './components/unapproved_account' ;
import { fetchUsers } from 'soapbox/actions/admin' ;
2020-12-29 13:55:04 -08:00
const messages = defineMessages ( {
heading : { id : 'column.admin.awaiting_approval' , defaultMessage : 'Awaiting Approval' } ,
2020-12-29 16:38:58 -08:00
emptyMessage : { id : 'admin.awaiting_approval.empty_message' , defaultMessage : 'There is nobody waiting for approval. When a new user signs up, you can review them here.' } ,
2020-12-29 13:55:04 -08:00
} ) ;
2021-07-13 15:59:55 -07:00
const mapStateToProps = state => ( {
accountIds : state . getIn ( [ 'admin' , 'awaitingApproval' ] ) ,
} ) ;
2020-12-29 13:55:04 -08:00
export default @ connect ( mapStateToProps )
@ injectIntl
class AwaitingApproval extends ImmutablePureComponent {
static propTypes = {
intl : PropTypes . object . isRequired ,
2021-07-13 15:59:55 -07:00
accountIds : ImmutablePropTypes . orderedSet . isRequired ,
2020-12-29 13:55:04 -08:00
} ;
2020-12-29 16:22:31 -08:00
state = {
isLoading : true ,
}
2020-12-29 13:55:04 -08:00
componentDidMount ( ) {
2020-12-29 16:22:31 -08:00
const { dispatch } = this . props ;
2021-07-13 15:27:11 -07:00
dispatch ( fetchUsers ( [ 'local' , 'need_approval' ] ) )
2020-12-29 16:22:31 -08:00
. then ( ( ) => this . setState ( { isLoading : false } ) )
. catch ( ( ) => { } ) ;
}
2020-12-29 13:55:04 -08:00
render ( ) {
2021-07-13 15:59:55 -07:00
const { intl , accountIds } = this . props ;
2020-12-29 16:22:31 -08:00
const { isLoading } = this . state ;
2021-07-13 15:59:55 -07:00
const showLoading = isLoading && accountIds . count ( ) === 0 ;
2020-12-29 13:55:04 -08:00
return (
2021-10-14 11:38:16 -07:00
< Column icon = 'user' heading = { intl . formatMessage ( messages . heading ) } >
2021-07-13 15:59:55 -07:00
< ScrollableList
isLoading = { isLoading }
showLoading = { showLoading }
scrollKey = 'awaiting-approval'
emptyMessage = { intl . formatMessage ( messages . emptyMessage ) }
>
{ accountIds . map ( id => (
< UnapprovedAccount accountId = { id } key = { id } / >
2020-12-29 16:22:31 -08:00
) ) }
< / S c r o l l a b l e L i s t >
2020-12-29 13:55:04 -08:00
< / C o l u m n >
) ;
}
}