46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import type { Control, FieldPath, FieldValues } from "react-hook-form";
|
|
import { FormField, FormItem, FormLabel } from "~/components/ui/form";
|
|
import { DatasetCombobox } from "~/components/dataset/DatasetCombobox";
|
|
|
|
interface DatasetFormFieldProps<T extends FieldValues> {
|
|
control: Control<T>;
|
|
name: FieldPath<T>;
|
|
label?: string;
|
|
onSelect?: (value: string, isNew: boolean) => void;
|
|
allowCreation?: boolean;
|
|
}
|
|
|
|
/**
|
|
* This component should be used with react-hook-form only.
|
|
* For standard RR7 forms we can just use DatasetCombobox or DatasetSelect directly.
|
|
*/
|
|
export function DatasetFormField<T extends FieldValues>({
|
|
control,
|
|
name,
|
|
label = "Dataset",
|
|
onSelect,
|
|
allowCreation,
|
|
}: DatasetFormFieldProps<T>) {
|
|
return (
|
|
<FormField
|
|
control={control}
|
|
name={name}
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>{label}</FormLabel>
|
|
<div className="grid gap-x-8 md:grid-cols-2">
|
|
<DatasetCombobox
|
|
selected={field.value}
|
|
onSelect={(value, isNew) => {
|
|
field.onChange(value);
|
|
onSelect?.(value, isNew);
|
|
}}
|
|
allowCreation={allowCreation}
|
|
/>
|
|
</div>
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
);
|
|
}
|