diff --git a/client/views/teams/modals/CreateTeamModal/UsersInput.tsx b/client/views/teams/modals/CreateTeamModal/UsersInput.tsx index 454d90f3dc3c..f93065254896 100644 --- a/client/views/teams/modals/CreateTeamModal/UsersInput.tsx +++ b/client/views/teams/modals/CreateTeamModal/UsersInput.tsx @@ -10,27 +10,33 @@ type UsersInputProps = { onChange: (value: unknown, action: 'remove' | undefined) => void; }; -const useUsersAutoComplete = (term: string): AutoCompleteProps['options'] => { +type AutocompleteData = [AutoCompleteProps['options'], { [key: string]: string | undefined }]; + +const useUsersAutoComplete = (term: string): AutocompleteData => { const params = useMemo(() => ({ selector: JSON.stringify({ term }), }), [term]); const { value: data } = useEndpointData('users.autocomplete', params); - return useMemo(() => { + return useMemo(() => { if (!data) { - return []; + return [[], {}]; } - return data.items.map((user) => ({ + const options = data.items.map((user) => ({ label: user.name ?? '', - value: user.username ?? '', + value: user._id ?? '', })) || []; + + const labelData = Object.fromEntries(data.items.map((user) => [user._id, user.username]) || []); + + return [options, labelData]; }, [data]); }; const UsersInput: FC = ({ onChange, ...props }) => { const [filter, setFilter] = useState(''); - const options = useUsersAutoComplete(useDebouncedValue(filter, 1000)); + const [options, labelData] = useUsersAutoComplete(useDebouncedValue(filter, 1000)); const onClickSelected = useCallback((e) => { e.stopPropagation(); @@ -41,17 +47,17 @@ const UsersInput: FC = ({ onChange, ...props }) => { const renderSelected = useCallback>( ({ value: selected }) => <> {selected?.map((value) => - - {value} + + {labelData[value]} )} , - [onClickSelected, props], + [onClickSelected, props, labelData], ); const renderItem = useCallback>( ({ value, ...props }) => -