import { DatePicker, DatePickerView, InputItem, List, Text, TextareaItem, View } from "@ant-design/react-native"; import { V1AnswerSettings, AnswerTypes } from "@formstr/sdk/dist/interfaces"; import { useState } from "react"; import RNPickerSelect from "react-native-picker-select" interface InputFillerProps { answerType: AnswerTypes; answerSettings: V1AnswerSettings; onChange: (answer: string, message?: string) => void; defaultValue?: string | number | boolean; } export const InputFiller: React.FC = ({ answerType, answerSettings, onChange, defaultValue, }) => { const [inputValue, setInputValue] = useState(""); const handleInputChange = ( e: any ) => { setInputValue(e.target.value) }; const handleValueChange = (value: string | null) => { if (!value) return; onChange(value); }; const getInput = ( answerType: AnswerTypes, answerSettings: V1AnswerSettings ) => { const dropdownItems = (answerSettings.choices || []).map((choice) => { return { label: choice.label, value: choice.choiceId, key: choice.choiceId }}) const INPUT_TYPE_COMPONENT_MAP: { [key in AnswerTypes]?: JSX.Element } = { [AnswerTypes.label]: <>, [AnswerTypes.shortText]: ( ), [AnswerTypes.paragraph]: ( ), [AnswerTypes.number]: ( // ), [AnswerTypes.radioButton]: ( // ), [AnswerTypes.checkboxes]: ( // ), [AnswerTypes.dropdown]: ( { setInputValue(value), console.log("selected value is: ", value)}} items={dropdownItems} placeholder={{}} key="picker" value={inputValue} >{inputValue ? answerSettings.choices?.filter((choice) => { return choice.choiceId === inputValue})[0].label : "Select an option"} ), [AnswerTypes.date]: ( ), [AnswerTypes.time]: ( ), }; return INPUT_TYPE_COMPONENT_MAP[answerType]; }; return <>{getInput(answerType, answerSettings)}; };