|
|
@ -1,26 +1,30 @@
|
|
|
|
|
|
|
|
import type { ComponentProps } from 'react';
|
|
|
|
import { useState } from 'react';
|
|
|
|
import { useState } from 'react';
|
|
|
|
import type { TypeaheadOption } from '@tih/ui';
|
|
|
|
import type { TypeaheadOption } from '@tih/ui';
|
|
|
|
import { Typeahead } from '@tih/ui';
|
|
|
|
import { Typeahead } from '@tih/ui';
|
|
|
|
|
|
|
|
|
|
|
|
import { trpc } from '~/utils/trpc';
|
|
|
|
import { trpc } from '~/utils/trpc';
|
|
|
|
|
|
|
|
|
|
|
|
type Props = Readonly<{
|
|
|
|
type BaseProps = Pick<
|
|
|
|
disabled?: boolean;
|
|
|
|
ComponentProps<typeof Typeahead>,
|
|
|
|
errorMessage?: string;
|
|
|
|
| 'disabled'
|
|
|
|
isLabelHidden?: boolean;
|
|
|
|
| 'errorMessage'
|
|
|
|
onSelect: (option: TypeaheadOption | null) => void;
|
|
|
|
| 'isLabelHidden'
|
|
|
|
placeholder?: string;
|
|
|
|
| 'placeholder'
|
|
|
|
required?: boolean;
|
|
|
|
| 'required'
|
|
|
|
value?: TypeaheadOption | null;
|
|
|
|
| 'textSize'
|
|
|
|
}>;
|
|
|
|
>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Props = BaseProps &
|
|
|
|
|
|
|
|
Readonly<{
|
|
|
|
|
|
|
|
onSelect: (option: TypeaheadOption | null) => void;
|
|
|
|
|
|
|
|
value?: TypeaheadOption | null;
|
|
|
|
|
|
|
|
}>;
|
|
|
|
|
|
|
|
|
|
|
|
export default function CompaniesTypeahead({
|
|
|
|
export default function CompaniesTypeahead({
|
|
|
|
disabled,
|
|
|
|
|
|
|
|
onSelect,
|
|
|
|
onSelect,
|
|
|
|
isLabelHidden,
|
|
|
|
|
|
|
|
placeholder,
|
|
|
|
|
|
|
|
required,
|
|
|
|
|
|
|
|
value,
|
|
|
|
value,
|
|
|
|
|
|
|
|
...props
|
|
|
|
}: Props) {
|
|
|
|
}: Props) {
|
|
|
|
const [query, setQuery] = useState('');
|
|
|
|
const [query, setQuery] = useState('');
|
|
|
|
const companies = trpc.useQuery([
|
|
|
|
const companies = trpc.useQuery([
|
|
|
@ -34,8 +38,6 @@ export default function CompaniesTypeahead({
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Typeahead
|
|
|
|
<Typeahead
|
|
|
|
disabled={disabled}
|
|
|
|
|
|
|
|
isLabelHidden={isLabelHidden}
|
|
|
|
|
|
|
|
label="Company"
|
|
|
|
label="Company"
|
|
|
|
noResultsMessage="No companies found"
|
|
|
|
noResultsMessage="No companies found"
|
|
|
|
nullable={true}
|
|
|
|
nullable={true}
|
|
|
@ -46,12 +48,10 @@ export default function CompaniesTypeahead({
|
|
|
|
value: id,
|
|
|
|
value: id,
|
|
|
|
})) ?? []
|
|
|
|
})) ?? []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
placeholder={placeholder}
|
|
|
|
|
|
|
|
required={required}
|
|
|
|
|
|
|
|
textSize="inherit"
|
|
|
|
|
|
|
|
value={value}
|
|
|
|
value={value}
|
|
|
|
onQueryChange={setQuery}
|
|
|
|
onQueryChange={setQuery}
|
|
|
|
onSelect={onSelect}
|
|
|
|
onSelect={onSelect}
|
|
|
|
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|