parent
8880e29b2d
commit
634a41a48a
@ -0,0 +1,41 @@
|
|||||||
|
import { useMemo, useState } from 'react';
|
||||||
|
|
||||||
|
import { trpc } from '~/utils/trpc';
|
||||||
|
|
||||||
|
import type { ExpandedTypeaheadProps } from './ExpandedTypeahead';
|
||||||
|
import ExpandedTypeahead from './ExpandedTypeahead';
|
||||||
|
|
||||||
|
export type CompanyTypeaheadProps = Omit<
|
||||||
|
ExpandedTypeaheadProps,
|
||||||
|
'label' | 'onQueryChange' | 'options'
|
||||||
|
>;
|
||||||
|
|
||||||
|
export default function CompanyTypeahead(props: CompanyTypeaheadProps) {
|
||||||
|
const [query, setQuery] = useState('');
|
||||||
|
|
||||||
|
const { data: companies } = trpc.useQuery([
|
||||||
|
'companies.list',
|
||||||
|
{
|
||||||
|
name: query,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const companyOptions = useMemo(() => {
|
||||||
|
return (
|
||||||
|
companies?.map(({ id, name }) => ({
|
||||||
|
id,
|
||||||
|
label: name,
|
||||||
|
value: id,
|
||||||
|
})) ?? []
|
||||||
|
);
|
||||||
|
}, [companies]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ExpandedTypeahead
|
||||||
|
{...(props as ExpandedTypeaheadProps)}
|
||||||
|
label="Company"
|
||||||
|
options={companyOptions}
|
||||||
|
onQueryChange={setQuery}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
import type { ComponentProps } from 'react';
|
||||||
|
import { Button, Typeahead } from '@tih/ui';
|
||||||
|
|
||||||
|
type RequireAllOrNone<T> = T | { [K in keyof T]?: never };
|
||||||
|
|
||||||
|
type TypeaheadProps = ComponentProps<typeof Typeahead>;
|
||||||
|
type TypeaheadOption = TypeaheadProps['options'][number];
|
||||||
|
|
||||||
|
export type ExpandedTypeaheadProps = RequireAllOrNone<{
|
||||||
|
onSuggestionClick: (option: TypeaheadOption) => void;
|
||||||
|
suggestedCount: number;
|
||||||
|
}> &
|
||||||
|
TypeaheadProps;
|
||||||
|
|
||||||
|
export default function ExpandedTypeahead({
|
||||||
|
suggestedCount = 0,
|
||||||
|
onSuggestionClick,
|
||||||
|
...typeaheadProps
|
||||||
|
}: ExpandedTypeaheadProps) {
|
||||||
|
const suggestions = typeaheadProps.options.slice(0, suggestedCount);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-wrap gap-x-2">
|
||||||
|
{suggestions.map((suggestion) => (
|
||||||
|
<Button
|
||||||
|
key={suggestion.id}
|
||||||
|
label={suggestion.label}
|
||||||
|
variant="tertiary"
|
||||||
|
onClick={() => {
|
||||||
|
onSuggestionClick?.(suggestion);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
<Typeahead {...typeaheadProps} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
@ -1,12 +1,19 @@
|
|||||||
import type { ComponentProps } from 'react';
|
|
||||||
import { Typeahead } from '@tih/ui';
|
|
||||||
|
|
||||||
import { LOCATIONS } from '~/utils/questions/constants';
|
import { LOCATIONS } from '~/utils/questions/constants';
|
||||||
|
|
||||||
type TypeaheadProps = ComponentProps<typeof Typeahead>;
|
import type { ExpandedTypeaheadProps } from './ExpandedTypeahead';
|
||||||
|
import ExpandedTypeahead from './ExpandedTypeahead';
|
||||||
|
|
||||||
export type LocationTypeaheadProps = Omit<TypeaheadProps, 'label' | 'options'>;
|
export type LocationTypeaheadProps = Omit<
|
||||||
|
ExpandedTypeaheadProps,
|
||||||
|
'label' | 'options'
|
||||||
|
>;
|
||||||
|
|
||||||
export default function LocationTypeahead(props: LocationTypeaheadProps) {
|
export default function LocationTypeahead(props: LocationTypeaheadProps) {
|
||||||
return <Typeahead label="Location" options={LOCATIONS} {...props} />;
|
return (
|
||||||
|
<ExpandedTypeahead
|
||||||
|
{...(props as ExpandedTypeaheadProps)}
|
||||||
|
label="Location"
|
||||||
|
options={LOCATIONS}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,19 @@
|
|||||||
import type { ComponentProps } from 'react';
|
|
||||||
import { Typeahead } from '@tih/ui';
|
|
||||||
|
|
||||||
import { ROLES } from '~/utils/questions/constants';
|
import { ROLES } from '~/utils/questions/constants';
|
||||||
|
|
||||||
type TypeaheadProps = ComponentProps<typeof Typeahead>;
|
import type { ExpandedTypeaheadProps } from './ExpandedTypeahead';
|
||||||
|
import ExpandedTypeahead from './ExpandedTypeahead';
|
||||||
|
|
||||||
export type RoleTypeaheadProps = Omit<TypeaheadProps, 'label' | 'options'>;
|
export type RoleTypeaheadProps = Omit<
|
||||||
|
ExpandedTypeaheadProps,
|
||||||
|
'label' | 'options'
|
||||||
|
>;
|
||||||
|
|
||||||
export default function RoleTypeahead(props: RoleTypeaheadProps) {
|
export default function RoleTypeahead(props: RoleTypeaheadProps) {
|
||||||
return <Typeahead label="Role" options={ROLES} {...props} />;
|
return (
|
||||||
|
<ExpandedTypeahead
|
||||||
|
{...(props as ExpandedTypeaheadProps)}
|
||||||
|
label="Role"
|
||||||
|
options={ROLES}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue