import { useMemo } from "react" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import FieldErrorMessage from "@/components/common/FieldErrorMessage" import FormLabel from "@/components/common/FormLabel" import { cn } from "@/lib/utils" import type { FormSelectFieldProps } from "@/type/commonType" import { getFormSelectFieldState } from "@/utils/formFieldValidation" import { dedupeSelectOptions } from "@/utils/search" export function FormSelectField({ label, name, value, onChange, options, placeholder, error, touched, isRequired = false, className, disabled = false, isLoading = false, loadingText = "Loading...", noValueFoundText = "No options found", valueType = "string", }: FormSelectFieldProps) { const uniqueOptions = useMemo(() => dedupeSelectOptions(options), [options]) const selectValue = value == null ? "" : String(value) const handleValueChange = (val: string) => { if (valueType === "number") { ;(onChange as (value: number) => void)(Number(val)) return } ;(onChange as (value: string) => void)(val) } const fieldState = getFormSelectFieldState({ name, touched, error, disabled, isLoading, }) return (
) }