import React, { useState } from 'react'; import { useFormikContext } from 'formik'; import SearchableSelect, { Option } from '@/components/elements/SearchableSelect'; import { User } from '@definitions/admin'; import { searchUserAccounts } from '@/api/admin/user'; export default ({ selected }: { selected?: User }) => { const { setFieldValue } = useFormikContext(); const [ user, setUser ] = useState(selected || null); const [ users, setUsers ] = useState(null); const onSearch = async (query: string) => { setUsers( await searchUserAccounts({ filters: { username: query, email: query } }) ); }; const onSelect = (user: User | null) => { setUser(user); setFieldValue('ownerId', user?.id || null); }; const getSelectedText = (user: User | null): string => user?.email || ''; return ( {users?.map(d => ( ))} ); };