import React from 'react'; import PropTypes from 'prop-types'; import AsyncSelect from 'react-select/lib/Async'; import { seafileAPI } from '../utils/seafile-api.js'; import { gettext } from '../utils/constants'; const propTypes = { placeholder: PropTypes.string.isRequired, onSelectChange: PropTypes.func.isRequired, isMulti: PropTypes.bool.isRequired, className: PropTypes.string, }; const NoOptionsMessage = (props) => { return (
{gettext('User not found')}
); }; class UserSelect extends React.Component { constructor(props) { super(props); this.options = []; } handleSelectChange = (option) => { this.options = []; this.props.onSelectChange(option); } loadOptions = (input, callback) => { const value = input.trim(); if (value.length > 0) { seafileAPI.searchUsers(value).then((res) => { this.options = []; for (let i = 0 ; i < res.data.users.length; i++) { const item = res.data.users[i]; let obj = {}; obj.value = item.name; obj.email = item.email; obj.label = {item.name} ; this.options.push(obj); } callback(this.options); }); } } clearSelect = () => { this.refs.userSelect.select.onChange([], { action: 'clear' }); } render() { return ( ); } } UserSelect.propTypes = propTypes; export default UserSelect;