[questions][fix] use useJobTitleOptions in RoleTypeahead

pull/516/head
Jeff Sieu 3 years ago
parent 4e16a6d6b5
commit 07249067c0

@ -1,33 +1,25 @@
import { useState } from 'react'; import { useState } from 'react';
import { JobTitleLabels } from '~/components/shared/JobTitles'; import { useJobTitleOptions } from '~/components/shared/JobTitlesTypeahead';
import type { ExpandedTypeaheadProps } from './ExpandedTypeahead'; import type { ExpandedTypeaheadProps } from './ExpandedTypeahead';
import ExpandedTypeahead from './ExpandedTypeahead'; import ExpandedTypeahead from './ExpandedTypeahead';
import type { FilterChoices } from '../filter/FilterSection';
export type RoleTypeaheadProps = Omit< export type RoleTypeaheadProps = Omit<
ExpandedTypeaheadProps, ExpandedTypeaheadProps,
'label' | 'onQueryChange' | 'options' 'label' | 'onQueryChange' | 'options'
>; >;
const ROLES: FilterChoices = Object.entries(JobTitleLabels)
.map(([slug, { label, ranking }]) => ({
id: slug,
label,
ranking,
value: slug,
}))
.sort((a, b) => b.ranking - a.ranking);
export default function RoleTypeahead(props: RoleTypeaheadProps) { export default function RoleTypeahead(props: RoleTypeaheadProps) {
const [query, setQuery] = useState(''); const [query, setQuery] = useState('');
const roleOptions = useJobTitleOptions(query);
return ( return (
<ExpandedTypeahead <ExpandedTypeahead
{...(props as ExpandedTypeaheadProps)} {...(props as ExpandedTypeaheadProps)}
label="Role" label="Role"
options={ROLES.filter((option) => options={roleOptions.filter((option) =>
option.label option.label
.toLocaleLowerCase() .toLocaleLowerCase()
.includes(query.trim().toLocaleLowerCase()), .includes(query.trim().toLocaleLowerCase()),

Loading…
Cancel
Save