import { useFormikContext } from 'formik'; import { useState } from 'react'; import { searchRoles } from '@/api/admin/roles'; import SearchableSelect, { Option } from '@/components/elements/SearchableSelect'; import type { UserRole } from '@definitions/admin'; export default ({ selected }: { selected: UserRole | null }) => { const context = useFormikContext(); const [role, setRole] = useState(selected); const [roles, setRoles] = useState(null); const onSearch = (query: string): Promise => { return new Promise((resolve, reject) => { searchRoles({ name: query }) .then(roles => { setRoles(roles); return resolve(); }) .catch(reject); }); }; const onSelect = (role: UserRole | null) => { setRole(role); context.setFieldValue('adminRoleId', role?.id || null); }; const getSelectedText = (role: UserRole | null): string | undefined => { return role?.name; }; return ( {roles?.map(d => ( ))} ); };