import { useFormikContext } from 'formik'; import { useState } from 'react'; import type { Database } from '@/api/admin/databases/getDatabases'; import searchDatabases from '@/api/admin/databases/searchDatabases'; import SearchableSelect, { Option } from '@/components/elements/SearchableSelect'; export default ({ selected }: { selected: Database | null }) => { const context = useFormikContext(); const [database, setDatabase] = useState(selected); const [databases, setDatabases] = useState(null); const onSearch = (query: string): Promise => { return new Promise((resolve, reject) => { searchDatabases({ name: query }) .then(databases => { setDatabases(databases); return resolve(); }) .catch(reject); }); }; const onSelect = (database: Database | null) => { setDatabase(database); context.setFieldValue('databaseHostId', database?.id || null); }; const getSelectedText = (database: Database | null): string | undefined => { return database?.name; }; return ( {databases?.map(d => ( ))} ); };