import {Text, TextField, TextFieldRef, View} from "react-native-ui-lib"; import React, {useEffect, useRef} from "react"; import {GroceryCategory, useGroceryContext} from "@/contexts/GroceryContext"; import {Dropdown} from "react-native-element-dropdown"; import CloseXIcon from "@/assets/svgs/CloseXIcon"; import {StyleSheet} from "react-native"; import DropdownIcon from "@/assets/svgs/DropdownIcon"; import {AntDesign} from "@expo/vector-icons"; interface IEditGrocery { id?: string; title: string; category: GroceryCategory; setTitle: (value: string) => void; setCategory?: (category: GroceryCategory) => void; setSubmit?: (value: boolean) => void; closeEdit?: () => void; handleEditSubmit?: Function; } const EditGroceryItem = ({editGrocery}: { editGrocery: IEditGrocery }) => { const {fuzzyMatchGroceryCategory} = useGroceryContext(); const inputRef = useRef(null); const groceryCategoryOptions = Object.values(GroceryCategory).map( (category) => ({ label: category, value: category, }) ); const handleSubmit = () => { inputRef?.current?.blur() console.log("CALLLLLL") if (editGrocery.setSubmit) { editGrocery.setSubmit(true); } if (editGrocery.handleEditSubmit) { editGrocery.handleEditSubmit({ id: editGrocery.id, title: editGrocery.title, category: editGrocery.category, }); } if (editGrocery.closeEdit) { editGrocery.closeEdit(); } } useEffect(() => { if (inputRef.current) { inputRef.current.focus(); } console.log(editGrocery.category); }, []); return ( { editGrocery.setTitle(value); let groceryCategory = fuzzyMatchGroceryCategory(value); if (editGrocery.setCategory) { editGrocery.setCategory(groceryCategory); } }} maxLength={25} /> { if (editGrocery.closeEdit) { editGrocery.closeEdit(); } }} /> ( )} renderItem={(item) => { return ( {item.label} ); }} onChange={(item) => { if (editGrocery.handleEditSubmit) { editGrocery.handleEditSubmit({ id: editGrocery.id, category: item.value, }); if (editGrocery.closeEdit) editGrocery.closeEdit(); } else { if (editGrocery.setCategory) { editGrocery.setCategory(item.value); } } }} /> ); }; const styles = StyleSheet.create({ itemText: { fontFamily: "Manrope_400Regular", fontSize: 15.42, paddingLeft: 15, }, selectedText: { fontFamily: "Manrope_500Medium", fontSize: 13.2, color: "#fd1775", }, dropdownStyle: {borderRadius: 6.61, height: 115.34, width: 187}, itemStyle: {padding: 0, margin: 0}, }); export default EditGroceryItem;