@@ -10,6 +10,7 @@ import {
1010 ListIcon ,
1111 Link ,
1212 Code ,
13+ Text ,
1314} from '@chakra-ui/react'
1415import { AtSignIcon , AddIcon } from '@chakra-ui/icons'
1516import join from 'url-join'
@@ -84,14 +85,14 @@ export function AddMemberByUsernameForm({ onSubmit }) {
8485 if ( res . status === 200 ) {
8586 const data = await res . json ( )
8687 if ( data ?. users . length ) {
87- setSearchResult ( data . users [ 0 ] )
88+ setSearchResult ( data . users )
8889 setStatus ( 'successSearch' )
8990 } else {
90- setSearchResult ( { } )
91+ setSearchResult ( [ ] )
9192 setStatus ( 'noResults' )
9293 }
9394 } else {
94- setSearchResult ( { } )
95+ setSearchResult ( [ ] )
9596 setStatus ( 'noResults' )
9697 }
9798 }
@@ -102,7 +103,7 @@ export function AddMemberByUsernameForm({ onSubmit }) {
102103 await onSubmit ( { osmId : uid , username } )
103104 actions . setSubmitting ( false )
104105 actions . resetForm ( { username : '' } )
105- setSearchResult ( { } )
106+ setSearchResult ( [ ] )
106107 } catch ( e ) {
107108 logger . error ( e )
108109 actions . setSubmitting ( false )
@@ -153,45 +154,50 @@ export function AddMemberByUsernameForm({ onSubmit }) {
153154 </ Button >
154155 </ Flex >
155156 < Box display = 'flex' justifyContent = 'stretch' py = { 3 } px = { 1 } >
156- { searchResult ?. id && (
157- < List spacing = { 5 } fontSize = 'sm' width = { '100%' } >
158- < ListItem
159- display = 'flex'
160- alignItems = 'center'
161- justifyContent = 'space-between'
162- >
163- < ListIcon as = { AtSignIcon } color = 'brand.600' />
164- < Link
165- href = { join ( OSM_DOMAIN , '/user' , searchResult . name ) }
166- isExternal
157+ < List spacing = { 5 } fontSize = 'sm' width = { '100%' } >
158+ { searchResult ?. length &&
159+ searchResult . map ( ( result ) => (
160+ < ListItem
161+ key = { result . id }
162+ display = 'flex'
163+ alignItems = 'center'
164+ justifyContent = 'space-between'
165+ marginTop = '1rem'
167166 >
168- { searchResult . name }
169- </ Link >
170- < Code ml = { 2 } > { searchResult . id } </ Code >
171- < Button
172- ml = 'auto'
173- textTransform = 'lowercase'
174- onClick = { async ( ) =>
175- submit ( searchResult . id , searchResult . name , {
176- setStatus,
177- setSubmitting,
178- resetForm,
179- } )
180- }
181- size = 'sm'
182- isLoading = { isSubmitting }
183- loadingText = 'Adding'
184- isDisabled = { isSubmitting }
185- leftIcon = { < AddIcon /> }
186- >
187- Add
188- </ Button >
189- </ ListItem >
190- </ List >
191- ) }
192- { status === 'noResults' && (
193- < Box fontSize = 'md' > No results found.</ Box >
194- ) }
167+ < ListIcon as = { AtSignIcon } color = 'brand.600' />
168+ < Link
169+ href = { join ( OSM_DOMAIN , '/user' , result . name ) }
170+ isExternal
171+ >
172+ { result . name }
173+ </ Link >
174+ < Code ml = { 2 } > { result . id } </ Code >
175+ < Button
176+ ml = 'auto'
177+ textTransform = 'lowercase'
178+ onClick = { async ( ) =>
179+ submit ( result . id , result . name , {
180+ setStatus,
181+ setSubmitting,
182+ resetForm,
183+ } )
184+ }
185+ size = 'sm'
186+ isLoading = { isSubmitting }
187+ loadingText = 'Adding'
188+ isDisabled = { isSubmitting }
189+ leftIcon = { < AddIcon /> }
190+ >
191+ Add
192+ </ Button >
193+ </ ListItem >
194+ ) ) }
195+ { status === 'noResults' && (
196+ < Text as = 'b' >
197+ No results found. Try typing the exact OSM username.
198+ </ Text >
199+ ) }
200+ </ List >
195201 </ Box >
196202 </ >
197203 )
0 commit comments