2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-05-07 06:55:24 +01:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
2020-04-08 02:06:59 +01:00
|
|
|
import debounce from 'lodash.debounce'
|
2020-08-07 05:14:13 +01:00
|
|
|
import isObject from 'lodash.isobject'
|
2019-07-16 20:57:35 +01:00
|
|
|
import {
|
2020-02-24 23:25:55 +00:00
|
|
|
fetchRemovedAccounts,
|
|
|
|
expandRemovedAccounts,
|
|
|
|
removeRemovedAccount,
|
2020-12-21 00:28:32 +00:00
|
|
|
fetchGroupRemovedAccountsAdminSearch,
|
2020-05-07 06:55:24 +01:00
|
|
|
} from '../actions/groups'
|
|
|
|
import { FormattedMessage } from 'react-intl'
|
|
|
|
import Account from '../components/account'
|
2020-08-07 05:14:13 +01:00
|
|
|
import Block from '../components/block'
|
2020-12-20 17:27:24 +00:00
|
|
|
import Input from '../components/input'
|
2020-08-07 05:14:13 +01:00
|
|
|
import BlockHeading from '../components/block_heading'
|
|
|
|
import ColumnIndicator from '../components/column_indicator'
|
2020-05-07 06:55:24 +01:00
|
|
|
import ScrollableList from '../components/scrollable_list'
|
2019-07-16 21:18:23 +01:00
|
|
|
|
2019-07-16 20:57:35 +01:00
|
|
|
class GroupRemovedAccounts extends ImmutablePureComponent {
|
|
|
|
|
2020-12-21 00:28:32 +00:00
|
|
|
state = {
|
|
|
|
query: '',
|
|
|
|
}
|
|
|
|
|
2020-02-24 23:25:55 +00:00
|
|
|
componentWillMount() {
|
2020-05-07 06:55:24 +01:00
|
|
|
const { groupId } = this.props
|
2019-07-16 20:57:35 +01:00
|
|
|
|
2020-08-07 05:14:13 +01:00
|
|
|
this.props.onFetchRemovedAccounts(groupId)
|
2019-07-16 20:57:35 +01:00
|
|
|
}
|
|
|
|
|
2020-02-24 23:25:55 +00:00
|
|
|
componentWillReceiveProps(nextProps) {
|
2020-05-07 06:55:24 +01:00
|
|
|
if (nextProps.groupId !== this.props.groupId) {
|
2020-08-07 05:14:13 +01:00
|
|
|
this.props.onFetchRemovedAccounts(nextProps.groupId)
|
2020-02-24 23:25:55 +00:00
|
|
|
}
|
2019-07-16 20:57:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleLoadMore = debounce(() => {
|
2020-08-07 05:14:13 +01:00
|
|
|
this.props.onExpandRemovedAccounts(this.props.groupId)
|
2020-05-07 06:55:24 +01:00
|
|
|
}, 300, { leading: true })
|
2019-07-16 20:57:35 +01:00
|
|
|
|
2020-12-21 00:28:32 +00:00
|
|
|
handleOnChange = (query) => {
|
|
|
|
this.setState({ query })
|
|
|
|
this.props.onChange(this.props.groupId, query)
|
|
|
|
}
|
|
|
|
|
2020-02-24 23:25:55 +00:00
|
|
|
render() {
|
2020-08-07 05:14:13 +01:00
|
|
|
const {
|
2020-12-21 00:28:32 +00:00
|
|
|
listAccountIds,
|
|
|
|
searchAcountIds,
|
2020-08-07 05:14:13 +01:00
|
|
|
hasMore,
|
|
|
|
group,
|
|
|
|
} = this.props
|
2020-12-21 00:28:32 +00:00
|
|
|
const { query } = this.state
|
2020-08-07 05:14:13 +01:00
|
|
|
|
|
|
|
if (!group) return <ColumnIndicator type='loading' />
|
2019-07-16 20:57:35 +01:00
|
|
|
|
2020-12-21 00:28:32 +00:00
|
|
|
const accountIds = !!query ? searchAcountIds : listAccountIds
|
|
|
|
|
2020-02-24 23:25:55 +00:00
|
|
|
return (
|
2020-08-07 05:14:13 +01:00
|
|
|
<Block>
|
|
|
|
<BlockHeading title='Removed Accounts' />
|
2020-12-20 17:27:24 +00:00
|
|
|
<div className={[_s.d, _s.jcCenter, _s.px15, _s.my5, _s.borderBottom1PX, _s.borderColorSecondary, _s.pt5, _s.pb15].join(' ')}>
|
|
|
|
<Input
|
|
|
|
id='group-member-search'
|
|
|
|
placeholder='Search removed group members'
|
|
|
|
prependIcon='search'
|
2020-12-21 00:28:32 +00:00
|
|
|
value={query}
|
2020-12-20 17:27:24 +00:00
|
|
|
onChange={this.handleOnChange}
|
|
|
|
autoComplete='off'
|
|
|
|
/>
|
|
|
|
</div>
|
2020-08-07 05:14:13 +01:00
|
|
|
<ScrollableList
|
|
|
|
scrollKey='removed_accounts'
|
|
|
|
hasMore={hasMore}
|
|
|
|
showLoading={(!group || !accountIds)}
|
|
|
|
onLoadMore={this.handleLoadMore}
|
2020-09-10 21:22:48 +01:00
|
|
|
emptyMessage={<FormattedMessage id='group.removed_accounts.empty' defaultMessage='This group does not have any removed accounts.' />}
|
2020-08-07 05:14:13 +01:00
|
|
|
>
|
|
|
|
{
|
|
|
|
accountIds && accountIds.map((id) => (
|
|
|
|
<Account
|
2020-12-21 00:28:32 +00:00
|
|
|
compact
|
2020-08-07 05:14:13 +01:00
|
|
|
key={id}
|
|
|
|
id={id}
|
|
|
|
onActionClick={() => this.props.onRemoveRemovedAccount(group.get('id'), id)}
|
2020-12-21 00:28:32 +00:00
|
|
|
actionTitle='Allow to join'
|
2020-08-07 05:14:13 +01:00
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</ScrollableList>
|
|
|
|
</Block>
|
2020-02-24 23:25:55 +00:00
|
|
|
)
|
2019-07-16 20:57:35 +01:00
|
|
|
}
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2019-07-16 20:57:35 +01:00
|
|
|
}
|
2020-08-19 01:22:15 +01:00
|
|
|
|
|
|
|
const mapStateToProps = (state, { params }) => {
|
|
|
|
const groupId = isObject(params) ? params['id'] : -1
|
|
|
|
const group = groupId === -1 ? null : state.getIn(['groups', groupId])
|
|
|
|
|
|
|
|
return {
|
|
|
|
group,
|
|
|
|
groupId,
|
2020-12-21 00:28:32 +00:00
|
|
|
listAccountIds: state.getIn(['user_lists', 'group_removed_accounts', groupId, 'items']),
|
|
|
|
searchAcountIds: state.getIn(['group_lists', 'removed_search_accounts']),
|
2020-09-10 21:24:38 +01:00
|
|
|
hasMore: !!state.getIn(['user_lists', 'group_removed_accounts', groupId, 'next']),
|
2020-08-19 01:22:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
2020-12-21 00:28:32 +00:00
|
|
|
onChange(groupId, query) {
|
|
|
|
dispatch(fetchGroupRemovedAccountsAdminSearch(groupId, query))
|
|
|
|
},
|
2020-08-19 01:22:15 +01:00
|
|
|
onFetchRemovedAccounts(groupId) {
|
|
|
|
dispatch(fetchRemovedAccounts(groupId))
|
|
|
|
},
|
|
|
|
onExpandRemovedAccounts(groupId) {
|
|
|
|
dispatch(expandRemovedAccounts(groupId))
|
|
|
|
},
|
|
|
|
onRemoveRemovedAccount(groupId, accountId) {
|
|
|
|
dispatch(removeRemovedAccount(groupId, accountId))
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
GroupRemovedAccounts.propTypes = {
|
|
|
|
groupId: PropTypes.string.isRequired,
|
|
|
|
accountIds: ImmutablePropTypes.list,
|
|
|
|
hasMore: PropTypes.bool,
|
|
|
|
onFetchRemovedAccounts: PropTypes.func.isRequired,
|
|
|
|
onExpandRemovedAccounts: PropTypes.func.isRequired,
|
|
|
|
onRemoveRemovedAccount: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
2020-12-21 00:28:32 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(GroupRemovedAccounts)
|