|
|
@ -1,23 +1,30 @@
|
|
|
|
import { useState } from 'react';
|
|
|
|
import { useState } from 'react';
|
|
|
|
import type { TypeaheadOption } from '@tih/ui';
|
|
|
|
|
|
|
|
import { Typeahead } from '@tih/ui';
|
|
|
|
import { Typeahead } from '@tih/ui';
|
|
|
|
|
|
|
|
import type { Props as TypeaheadProps } from '@tih/ui/src/Typeahead/Typeahead';
|
|
|
|
|
|
|
|
|
|
|
|
import { trpc } from '~/utils/trpc';
|
|
|
|
import { trpc } from '~/utils/trpc';
|
|
|
|
|
|
|
|
|
|
|
|
type Props = Readonly<{
|
|
|
|
type Props = Omit<
|
|
|
|
disabled?: boolean;
|
|
|
|
TypeaheadProps,
|
|
|
|
isLabelHidden?: boolean;
|
|
|
|
'noResultsMessage' | 'onQueryChange' | 'options' | 'query'
|
|
|
|
onSelect: (option: TypeaheadOption) => void;
|
|
|
|
> &
|
|
|
|
placeHolder?: string;
|
|
|
|
Partial<Pick<TypeaheadProps, 'noResultsMessage'>> &
|
|
|
|
}>;
|
|
|
|
(
|
|
|
|
|
|
|
|
| Required<Pick<TypeaheadProps, 'onQueryChange' | 'query'>>
|
|
|
|
|
|
|
|
| {
|
|
|
|
|
|
|
|
onQueryChange?: never;
|
|
|
|
|
|
|
|
query?: never;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
export default function CompaniesTypeahead({
|
|
|
|
export default function CompaniesTypeahead({
|
|
|
|
disabled,
|
|
|
|
query: queryProp,
|
|
|
|
onSelect,
|
|
|
|
onQueryChange,
|
|
|
|
isLabelHidden,
|
|
|
|
nullable = true,
|
|
|
|
placeHolder,
|
|
|
|
...typeaheadProps
|
|
|
|
}: Props) {
|
|
|
|
}: Props) {
|
|
|
|
const [query, setQuery] = useState('');
|
|
|
|
const [queryState, setQuery] = useState('');
|
|
|
|
|
|
|
|
const query = queryProp ?? queryState;
|
|
|
|
const companies = trpc.useQuery([
|
|
|
|
const companies = trpc.useQuery([
|
|
|
|
'companies.list',
|
|
|
|
'companies.list',
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -29,11 +36,9 @@ export default function CompaniesTypeahead({
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Typeahead
|
|
|
|
<Typeahead
|
|
|
|
disabled={disabled}
|
|
|
|
{...typeaheadProps}
|
|
|
|
isLabelHidden={isLabelHidden}
|
|
|
|
|
|
|
|
label="Company"
|
|
|
|
|
|
|
|
noResultsMessage="No companies found"
|
|
|
|
noResultsMessage="No companies found"
|
|
|
|
nullable={true}
|
|
|
|
nullable={nullable}
|
|
|
|
options={
|
|
|
|
options={
|
|
|
|
data?.map(({ id, name }) => ({
|
|
|
|
data?.map(({ id, name }) => ({
|
|
|
|
id,
|
|
|
|
id,
|
|
|
@ -41,9 +46,8 @@ export default function CompaniesTypeahead({
|
|
|
|
value: id,
|
|
|
|
value: id,
|
|
|
|
})) ?? []
|
|
|
|
})) ?? []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
placeholder={placeHolder}
|
|
|
|
query={query}
|
|
|
|
onQueryChange={setQuery}
|
|
|
|
onQueryChange={onQueryChange ?? setQuery}
|
|
|
|
onSelect={onSelect}
|
|
|
|
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|