/** * DropdownField Component * * 드롭다운/선택 필드 (dropdown, searchable-dropdown) */ 'use client'; import { useState, useEffect } from 'react'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { Label } from '@/components/ui/label'; import type { DynamicFieldProps, DropdownOption } from '../types'; import { cn } from '@/lib/utils'; export function DropdownField({ field, value, error, onChange, onBlur, disabled, }: DynamicFieldProps) { const [options, setOptions] = useState( field.dropdown_config?.options || [] ); const [isLoading, setIsLoading] = useState(false); // API에서 옵션 로드 (options_endpoint가 있는 경우) useEffect(() => { if (field.dropdown_config?.options_endpoint) { setIsLoading(true); fetch(field.dropdown_config.options_endpoint) .then((res) => res.json()) .then((data) => { if (data.success && Array.isArray(data.data)) { setOptions(data.data); } }) .catch((err) => { console.error('[DropdownField] Failed to load options:', err); }) .finally(() => { setIsLoading(false); }); } }, [field.dropdown_config?.options_endpoint]); const displayValue = value === null || value === undefined ? '' : String(value); const handleValueChange = (newValue: string) => { onChange(newValue); onBlur(); }; return (
{field.help_text && !error && (

{field.help_text}

)} {error &&

{error}

}
); } export default DropdownField;