import React, { useEffect, useRef, useState } from 'react'; import { ScrollView, View, Text, Image, TouchableOpacity, BackHandler, Dimensions, Keyboard } from 'react-native'; import { FontAwesome, Ionicons } from '@expo/vector-icons'; import config from '../../components/data/config.json' import { styles } from '@/components/style/style'; import { FAB } from 'react-native-elements'; import { useNavigation, NavigationProp, useFocusEffect } from '@react-navigation/native'; import { GestureHandlerRootView, TextInput } from 'react-native-gesture-handler'; import AsyncStorage from '@react-native-async-storage/async-storage'; import { addStorage, cfg, getStorage } from '@/components/lib/cfg'; import { DB } from '@/components/lib/db'; const CustDetail = ({ act, hidedata, search, show, data:dataRow, send }:any) => { const [bgHead, setBgHead] = useState(null) const [nama, setNama] = useState(''); const [Id, setId] = useState(''); const [formTitle, setFormTitle] = useState('Perusahaan'); const [formArea, setFormArea] = useState('none'); const [email, setEmail] = useState(''); const [inputVal, setInputVal] = useState(''); const [formName, setFormName] = useState(''); const [datatext, setDataText] = useState('example@mail.com'); const inputRef = useRef(null); // Create a ref for the TextInput let heightWIndow = Dimensions.get('window').height + 80; const [Act, setAct] = useState(send['contactActiveData']) const [contact, setContact] = useState<{ name: string , row: string , icon: string , value: string , type: string | null }[]>([]); const [produk, setProduk] = useState<{ name: string , value: string }[]>([]); const navigation = useNavigation>(); const Contact = (props: any) => { return ( <> {(props?.data || []).map((data: any, key: number) => { setFormArea('flex') setFormTitle(data?.name); setInputVal(data?.value) setFormName(data?.row) inputRef.current?.focus() }}> {data.type == 'ionic' ? : } {data.value ? data.value : data.name} )} ) } const Produk = function (props: any) { return ( <> Riwayat Pembelian {(props?.data || []).map((data: any, key: number) => {data?.name} )} ) } const callData = async (Active:any = null) => { let data: any = Active? Active : send['contactActiveData']; console.log(send) data = JSON.parse(atob(data)); setId(data?.id) setNama(data?.name) setEmail(data?.email) let country = 'Indonesia'; if (data?.country_id) { const negara: any = await getStorage('negara') const [{ name }] = negara.filter((s: any) => s?.id == data?.country_id); country = name; } setContact([ { name: "Name", row: "name", icon: "person", value: data?.name, type: "ionic" } , { name: "Email", row: "email", icon: "mail-outline", value: data?.email, type: "ionic" } , { name: "Company Name", row: "company_id", icon: "building", value: "PT VDS", type: "" } , { name: "Job Title", row: "function", icon: "star-outline", value: data?.function, type: "ionic" } , { name: "Phone", row: "phone", icon: "phone", value: data?.phone, type: "" } , { name: "Mobile Phone", row: "mobile", icon: "mobile", value: data?.mobile, type: "" } , { name: "Address", row: "street", icon: "location", value: data?.street, type: "ionic" } , { name: "Address 2", row: "street2", icon: "location", value: data?.street2, type: "ionic" } , { name: "City", row: "city", icon: "location", value: data?.city, type: "ionic" } , { name: "Country", row: "country_id", icon: "globe", value: country, type: "ionic" } ]); setProduk([ { name: 'A1-F12', value: '20' } , { name: 'A1-K12', value: '20' } , { name: 'A1-F16', value: '20' } , { name: 'A1-F16', value: '20' } ]); }; cfg.action['detailcontact'] = () => { callData() } useEffect(() => { (function () { callData() })(); }, []) const customerBack = function () { show(dataRow); hidedata(false) act(search) } const fabAction = function () { // console.log("action") } const onScroll = (event: any) => { const yOffset = event.nativeEvent.contentOffset.y; if (yOffset > 190) { setBgHead(config.color.primary) } else { setBgHead(null) } }; return ( <> {nama} {email} {/* */} {/* 20 Dos 20 Bal 20 Slop */} {formTitle} {formName != 'country_id' && formName != 'company_id' ? { let data: any = JSON.parse(atob(Act)); data[formName] = inputVal; let g = btoa(JSON.stringify(data)); setAct(g) callData(g) setFormArea('none') await DB(`UPDATE res_partner SET ${formName} = '${inputVal}' WHERE id = ${Id}`) await addStorage('contactActiveData', data); Keyboard.dismiss() act() }}> Simpan : <> } { Keyboard.dismiss() setFormArea('none') }}> Tutup ); }; export default CustDetail;