mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2026-04-01 10:01:43 +08:00
[portal][ui] add companies filter
This commit is contained in:
40
apps/portal/src/components/global/CompaniesTypeahead.tsx
Normal file
40
apps/portal/src/components/global/CompaniesTypeahead.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { useState } from 'react';
|
||||
import type { TypeaheadOption } from '@tih/ui';
|
||||
import { Typeahead } from '@tih/ui';
|
||||
|
||||
import { trpc } from '~/utils/trpc';
|
||||
|
||||
type Props = Readonly<{
|
||||
disabled?: boolean;
|
||||
onSelect: (option: TypeaheadOption) => void;
|
||||
}>;
|
||||
|
||||
export default function CompaniesTypeahead({ disabled, onSelect }: Props) {
|
||||
const [query, setQuery] = useState('');
|
||||
const companies = trpc.useQuery([
|
||||
'companies.list',
|
||||
{
|
||||
name: query,
|
||||
},
|
||||
]);
|
||||
|
||||
const { data } = companies;
|
||||
|
||||
return (
|
||||
<Typeahead
|
||||
disabled={disabled}
|
||||
label="Company"
|
||||
noResultsMessage="No companies found"
|
||||
nullable={true}
|
||||
options={
|
||||
data?.map(({ id, name }) => ({
|
||||
id,
|
||||
label: name,
|
||||
value: id,
|
||||
})) ?? []
|
||||
}
|
||||
onQueryChange={setQuery}
|
||||
onSelect={onSelect}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user