Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dashboard
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
red-giant
dashboard
Commits
ab7d7b94
"Scripts/preprocess_CORDEX.sh" did not exist on "cc1b630f34a5733f796e98306cb601bb69d57f2f"
Verified
Commit
ab7d7b94
authored
3 years ago
by
Defendi Alberto
Browse files
Options
Downloads
Patches
Plain Diff
Install controller.
parent
3b9d3003
No related branches found
No related tags found
2 merge requests
!60
New component to search senior (see #12). Enhance responsiveness and solve #10 and #11
,
!58
Camelize data and insert react-hook-form in autocomplete.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/Dashboard/ReservationPage/Reservation/SeniorSearch.tsx
+51
-33
51 additions, 33 deletions
...ts/Dashboard/ReservationPage/Reservation/SeniorSearch.tsx
with
51 additions
and
33 deletions
src/components/Dashboard/ReservationPage/Reservation/SeniorSearch.tsx
+
51
−
33
View file @
ab7d7b94
...
@@ -4,50 +4,68 @@ import TextField from '@material-ui/core/TextField';
...
@@ -4,50 +4,68 @@ import TextField from '@material-ui/core/TextField';
import
Autocomplete
from
'
@material-ui/lab/Autocomplete
'
;
import
Autocomplete
from
'
@material-ui/lab/Autocomplete
'
;
import
{
getSeniorList
}
from
'
api/getSeniorList
'
;
import
{
getSeniorList
}
from
'
api/getSeniorList
'
;
import
{
ResponseProps
}
from
'
api/ResponseProps
'
;
import
{
ResponseProps
}
from
'
api/ResponseProps
'
;
import
{
Control
,
Controller
}
from
'
react-hook-form
'
;
import
{
ReservationProps
}
from
'
./ReservationProps
'
;
export
const
SeniorSearch
:
FC
=
()
=>
{
type
SeniorSearchProps
=
{
control
:
Control
<
ReservationProps
>
;
};
export
const
SeniorSearch
:
FC
<
SeniorSearchProps
>
=
({
control
,
}:
SeniorSearchProps
)
=>
{
const
[
value
,
setValue
]
=
useState
<
ResponseProps
|
null
>
(
null
);
const
[
value
,
setValue
]
=
useState
<
ResponseProps
|
null
>
(
null
);
const
[
seniors
,
setSeniors
]
=
useState
<
ResponseProps
[]
>
([]);
const
[
seniors
,
setSeniors
]
=
useState
<
ResponseProps
[]
>
([]);
const
[
query
,
setQuery
]
=
useState
<
string
>
(
''
);
// FIX: Input closing when the data is changed.
// The issue is caused by the stopped re-rendering of react hook form. Consider
// attaching the value manually or to isolate this component.
const
handleChange
=
(
newValue
:
string
):
void
=>
{
const
handleChange
=
(
newValue
:
string
):
void
=>
{
if
(
newValue
!==
undefined
)
{
const
MIN_SEARCH_LENGTH
=
4
;
const
MIN_SEARCH_LENGTH
=
3
;
if
(
newValue
.
length
>=
MIN_SEARCH_LENGTH
&&
value
==
null
)
{
if
(
newValue
.
length
>=
MIN_SEARCH_LENGTH
)
getSeniorList
(
newValue
).
then
((
list
)
=>
{
getSeniorList
(
newValue
).
then
((
list
)
=>
{
if
(
list
.
length
!==
0
)
{
setSeniors
(
list
);
setSeniors
(
list
);
});
}
else
{
setSeniors
([]);
}
});
}
}
};
};
return
(
return
(
<
Autocomplete
<
Controller
value
=
{
value
}
control
=
{
control
}
id
=
"senior-searcher"
name
=
"senior"
onInputChange
=
{
(
event
,
newValue
)
=>
handleChange
(
newValue
)
}
as
=
{
({
onChange
})
=>
(
onChange
=
{
(
event
,
newValue
)
=>
{
<
Autocomplete
setValue
(
newValue
);
value
=
{
value
}
}
}
id
=
"senior-searcher"
options
=
{
seniors
}
onInputChange
=
{
(
_
,
newValue
)
=>
handleChange
(
newValue
)
}
getOptionSelected
=
{
(
option
,
val
)
=>
option
.
id
===
val
.
id
}
onChange
=
{
(
_
,
val
)
=>
{
getOptionLabel
=
{
(
option
)
=>
{
onChange
(
val
?.
id
);
if
(
Object
.
prototype
.
hasOwnProperty
.
call
({
user
:
true
},
'
user
'
))
{
setValue
(
val
);
return
option
.
user
.
lastName
;
}
return
''
;
}
}
renderOption
=
{
(
option
)
=>
(
<>
{
option
.
user
.
firstName
}
{
option
.
user
.
lastName
}
{
option
.
user
.
username
}
</>
)
}
renderInput
=
{
(
params
)
=>
(
<
TextField
{
...
params
}
label
=
"Search a senior"
variant
=
"outlined"
InputProps
=
{
{
...
params
.
InputProps
,
}
}
}
}
options
=
{
seniors
}
getOptionSelected
=
{
(
option
,
val
)
=>
option
.
id
===
val
.
id
}
getOptionLabel
=
{
(
option
)
=>
option
.
user
.
lastName
}
renderOption
=
{
(
option
)
=>
(
<>
{
option
.
user
.
firstName
}
{
option
.
user
.
lastName
}{
'
'
}
{
option
.
user
.
username
}
{
option
.
memberCardNumber
}
</>
)
}
renderInput
=
{
(
params
)
=>
(
<
TextField
{
...
params
}
label
=
"Search a senior"
variant
=
"outlined"
InputProps
=
{
{
...
params
.
InputProps
,
}
}
/>
)
}
/>
/>
)
}
)
}
/>
/>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment