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'
|
2019-07-16 20:57:35 +01:00
|
|
|
import {
|
2020-02-24 23:25:55 +00:00
|
|
|
fetchRemovedAccounts,
|
|
|
|
expandRemovedAccounts,
|
|
|
|
removeRemovedAccount,
|
2020-05-07 06:55:24 +01:00
|
|
|
} from '../actions/groups'
|
|
|
|
import { FormattedMessage } from 'react-intl'
|
|
|
|
import Account from '../components/account'
|
|
|
|
import ScrollableList from '../components/scrollable_list'
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
2019-07-16 21:18:23 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2020-02-24 23:25:55 +00:00
|
|
|
remove: { id: 'groups.removed_accounts', defaultMessage: 'Allow joining' },
|
2020-05-07 06:55:24 +01:00
|
|
|
})
|
2019-07-16 20:57:35 +01:00
|
|
|
|
2020-05-07 06:55:24 +01:00
|
|
|
const mapStateToProps = (state, { groupId }) => ({
|
|
|
|
group: state.getIn(['groups', groupId]),
|
|
|
|
accountIds: state.getIn(['user_lists', 'groups_removed_accounts', groupId, 'items']),
|
|
|
|
hasMore: !!state.getIn(['user_lists', 'groups_removed_accounts', groupId, 'next']),
|
|
|
|
})
|
2019-07-16 20:57:35 +01:00
|
|
|
|
2020-02-25 16:04:44 +00:00
|
|
|
export default
|
|
|
|
@connect(mapStateToProps)
|
2019-07-16 21:18:23 +01:00
|
|
|
@injectIntl
|
2019-07-16 20:57:35 +01:00
|
|
|
class GroupRemovedAccounts extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
2020-05-07 06:55:24 +01:00
|
|
|
groupId: PropTypes.string.isRequired,
|
2020-02-24 23:25:55 +00:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
accountIds: ImmutablePropTypes.list,
|
|
|
|
hasMore: PropTypes.bool,
|
2020-05-07 06:55:24 +01:00
|
|
|
}
|
2019-07-16 20:57:35 +01:00
|
|
|
|
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-05-07 06:55:24 +01:00
|
|
|
this.props.dispatch(fetchRemovedAccounts(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) {
|
|
|
|
this.props.dispatch(fetchRemovedAccounts(nextProps.groupId))
|
2020-02-24 23:25:55 +00:00
|
|
|
}
|
2019-07-16 20:57:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleLoadMore = debounce(() => {
|
2020-05-07 06:55:24 +01:00
|
|
|
this.props.dispatch(expandRemovedAccounts(this.props.groupId))
|
|
|
|
}, 300, { leading: true })
|
2019-07-16 20:57:35 +01:00
|
|
|
|
2020-02-24 23:25:55 +00:00
|
|
|
render() {
|
2020-05-07 06:55:24 +01:00
|
|
|
const { accountIds, hasMore, group, intl } = this.props
|
2019-07-16 20:57:35 +01:00
|
|
|
|
2020-02-24 23:25:55 +00:00
|
|
|
return (
|
|
|
|
<ScrollableList
|
|
|
|
scrollKey='removed_accounts'
|
|
|
|
hasMore={hasMore}
|
2020-05-07 06:55:24 +01:00
|
|
|
showLoading={(!group || !accountIds)}
|
2020-02-24 23:25:55 +00:00
|
|
|
onLoadMore={this.handleLoadMore}
|
|
|
|
emptyMessage={<FormattedMessage id='group.removed_accounts.empty' defaultMessage='This group does not has any removed accounts.' />}
|
|
|
|
>
|
2020-05-07 06:55:24 +01:00
|
|
|
{
|
|
|
|
accountIds && accountIds.map((id) => (
|
|
|
|
<Account
|
|
|
|
key={id}
|
|
|
|
id={id}
|
|
|
|
actionIcon='subtract'
|
|
|
|
onActionClick={() => this.props.dispatch(removeRemovedAccount(group.get('id'), id))}
|
|
|
|
actionTitle={intl.formatMessage(messages.remove)}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
2020-02-24 23:25:55 +00:00
|
|
|
</ScrollableList>
|
|
|
|
)
|
2019-07-16 20:57:35 +01:00
|
|
|
}
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2019-07-16 20:57:35 +01:00
|
|
|
}
|