1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 08:53:14 +00:00

replace code to user-select component (#3033)

This commit is contained in:
杨顺强
2019-03-04 15:53:12 +08:00
committed by Daniel Pan
parent 6ca920db64
commit 9498551ca2
6 changed files with 39 additions and 141 deletions

View File

@@ -1,10 +1,10 @@
import React, { Fragment } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import AsyncSelect from 'react-select/lib/Async';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import toaster from '../toast';
import { gettext } from '../../utils/constants';
import { Button, Modal, ModalHeader, ModalBody } from 'reactstrap';
import { seafileAPI } from '../../utils/seafile-api.js';
import UserSelect from '../user-select';
const propTypes = {
itemName: PropTypes.string.isRequired,
@@ -29,26 +29,6 @@ class TransferDialog extends React.Component {
this.options = [];
}
loadOptions = (value, callback) => {
if (value.trim().length > 0) {
seafileAPI.searchUsers(value.trim()).then((res) => {
this.options = [];
for (let i = 0 ; i < res.data.users.length; i++) {
let obj = {};
obj.value = res.data.users[i].name;
obj.email = res.data.users[i].email;
obj.label =
<Fragment>
<img src={res.data.users[i].avatar_url} className="avatar reviewer-select-avatar" alt=""/>
<span className='reviewer-select-name'>{res.data.users[i].name}</span>
</Fragment>;
this.options.push(obj);
}
callback(this.options);
});
}
}
submit = () => {
let repoID = this.props.repoID;
let user = this.state.selectedOption.email;
@@ -74,16 +54,17 @@ class TransferDialog extends React.Component {
<div dangerouslySetInnerHTML={{__html:message}} />
</ModalHeader>
<ModalBody>
<AsyncSelect
className='reviewer-select' isFocused
loadOptions={this.loadOptions}
<UserSelect
ref="userSelect"
isMulti={false}
className="reviewer-select"
placeholder={gettext('Please enter 1 or more character')}
onChange={this.handleSelectChange}
isClearable classNamePrefix
inputId={'react-select-transfer-input'}
/><br />
<Button color="primary" onClick={this.submit}>{gettext('Submit')}</Button>
onSelectChange={this.handleSelectChange}
/>
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.submit}>{gettext('Submit')}</Button>
</ModalFooter>
</Modal>
);
}