Handle search user (frontend)

This commit is contained in:
cyril lopez 2017-11-27 14:26:54 +01:00
parent baee801941
commit 5cf7c45202
3 changed files with 4 additions and 28 deletions

View File

@ -91,7 +91,7 @@ class InputSearch extends React.Component { // eslint-disable-line react/prefer-
<ul>
{map(this.state.filteredUsers, (user) => (
<InputSearchLi
key={user.name}
key={user.id || user._id}
item={user}
isAdding={this.state.isAdding}
onClick={this.handleClick}

View File

@ -15,7 +15,7 @@ function InputSearchLi({ onClick, isAdding, item }) {
<li className={styles.li}>
<div>
<div>
{item.name}
{item.username}
</div>
<div onClick={() => onClick(item)}>
<i className={`fa ${icon}`} />

View File

@ -1,5 +1,4 @@
import { LOCATION_CHANGE } from 'react-router-redux';
import { includes, toLower } from 'lodash';
import {
call,
cancel,
@ -33,32 +32,9 @@ import {
export function* fetchUser(action) {
try {
const fakeUser = [
{
id: '11',
name: 'John Lennon',
},
{
id: '12',
name: 'Paul McCartney',
},
{
id: '13',
name: 'George Harrison',
},
{
id: '14',
name: 'Ringo Starr',
},
];
// Temporary waiting for backend dynamic
const filteredUsers = fakeUser.filter((user) => {
if (includes(toLower(user.name), toLower(action.user))) {
return user;
}
});
const data = yield call(request, `/users-permissions/search/${action.user}`, { method: 'GET' });
yield put(getUserSucceeded(filteredUsers));
yield put(getUserSucceeded(data));
} catch(error) {
strapi.notification.error('users-permissions.notification.error.fetchUser');
}