Skip to content
Snippets Groups Projects
Verified Commit 009a0be9 authored by Defendi Alberto's avatar Defendi Alberto
Browse files

Integrate api call.

parent 62964825
No related branches found
No related tags found
2 merge requests!60New component to search senior (see #12). Enhance responsiveness and solve #10 and #11,!58Camelize data and insert react-hook-form in autocomplete.
Pipeline #12645 passed
/* eslint-disable react/jsx-props-no-spreading */
import React, { FC, useEffect, useState } from 'react';
import React, { FC, useState } from 'react';
import TextField from '@material-ui/core/TextField';
import Autocomplete from '@material-ui/lab/Autocomplete';
import { getSeniorList } from 'api/getSeniorList';
import { CircularProgress } from '@material-ui/core';
import { ResponseProps } from 'api/ResponseProps';
type DataProps = {
lastName: string;
id: number;
};
export const SeniorSearch: FC = () => {
const [value, setValue] = useState<ResponseProps | null>(null);
const [lastNameInput, setLastNameInput] = useState<string>('');
const [seniors, setSeniors] = useState<ResponseProps[]>([
{
id: 0,
user: {
username: '',
firstName: '',
lastName: '',
email: '',
},
},
]);
const [seniors, setSeniors] = useState<ResponseProps[]>([]);
const handleChange = (newValue: string): void => {
if (newValue !== undefined) {
const MIN_SEARCH_LENGTH = 3;
if (newValue.length >= MIN_SEARCH_LENGTH)
getSeniorList(newValue).then((list) => {
setSeniors(list as ResponseProps[]);
console.log(seniors);
setSeniors(list);
});
}
};
......@@ -42,17 +24,26 @@ export const SeniorSearch: FC = () => {
value={value}
id="senior-searcher"
onInputChange={(event, newValue) => handleChange(newValue)}
options={seniors as ResponseProps[]}
onChange={(event, newValue) => {
setValue(newValue);
}}
options={seniors}
getOptionSelected={(option, val) => option.id === val.id}
getOptionLabel={(option) => {
if (Object.prototype.hasOwnProperty.call({ user: true }, 'user')) {
return option.user.email ? option.user.email : '';
return option.user.lastName;
}
return '';
}}
renderOption={(option) => (
<>
{option.user.firstName} {option.user.lastName} {option.user.username}
</>
)}
renderInput={(params) => (
<TextField
{...params}
label="Asynchronous"
label="Search a senior"
variant="outlined"
InputProps={{
...params.InputProps,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment