import { BoxButtonOnFooter, ButtonCustom, SelectCustom, Spacing, StackCustom, TextAreaCustom, TextCustom, TextInputCustom, ViewWrapper, } from "@/components"; import { MainColor } from "@/constants/color-palet"; import { apiMasterBidangBisnis } from "@/service/api-client/api-master"; import { apiGetOnePortofolio, apiUpdatePortofolio, } from "@/service/api-client/api-portofolio"; import { IMasterBidangBisnis } from "@/types/Type-Master"; import { router, useLocalSearchParams } from "expo-router"; import { useEffect, useState } from "react"; import { Text, View } from "react-native"; import PhoneInput, { ICountry } from "react-native-international-phone-number"; import Toast from "react-native-toast-message"; interface IFormData { id_Portofolio: string; namaBisnis: string; alamatKantor: string; tlpn: string; deskripsi: string; masterBidangBisnisId: string; } export default function PortofolioEdit() { const { id } = useLocalSearchParams(); const [isLoading, setIsLoading] = useState(false); const [selectedCountry, setSelectedCountry] = useState(null); const [bidangBisnis, setBidangBisnis] = useState([]); const [data, setData] = useState({}); function handleInputValue(phoneNumber: string) { setData({ ...data, tlpn: phoneNumber }); } function handleSelectedCountry(country: ICountry) { setSelectedCountry(country); } useEffect(() => { onLoadData(id as string); onLoadMaster(); }, [id]); const onLoadData = async (id: string) => { const response = await apiGetOnePortofolio({ id: id }); if (response.data.tlpn && response.data.tlpn.includes("62")) { const fixNumber = response.data.tlpn.replace("62", ""); console.log("Fix Number >>", fixNumber); setData({ ...response.data, tlpn: fixNumber }); } }; const onLoadMaster = async () => { try { const response = await apiMasterBidangBisnis(); setBidangBisnis(response.data); } catch (error) { setBidangBisnis([]); console.log("Error onLoadMasterBidangBisnis", error); } }; const handleSubmitUpdate = async () => { try { setIsLoading(true); const callingCode = selectedCountry?.callingCode.replace(/^\+/, "") || ""; const fixNumber = data.tlpn.replace(/\s+/g, ""); const realNumber = callingCode + fixNumber; const newData: IFormData = { id_Portofolio: data.id_Portofolio, namaBisnis: data.namaBisnis, alamatKantor: data.alamatKantor, tlpn: realNumber, deskripsi: data.deskripsi, masterBidangBisnisId: data.masterBidangBisnisId, }; const response = await apiUpdatePortofolio({ id: id as string, data: newData, category: "detail", }); if (!response.success) { Toast.show({ type: "info", text1: "Info", text2: response.message, }); return } Toast.show({ type: "success", text1: "Sukses", text2: "Data terupdate", }); router.back(); } catch (error) { console.log("Error handleSubmitUpdate", error); } finally { setIsLoading(false); } }; const buttonUpdate = ( Update ); return ( <> setData({ ...data, namaBisnis: value }) } /> ({ label: item.name, value: item.id, }))} value={data.masterBidangBisnisId} onChange={(value) => { setData({ ...(data as any), masterBidangBisnisId: value }); }} /> {/* ({ label: item.name, value: item.id, }))} value={data.masterSubBidangBisnisId} onChange={(value) => { setData({ ...(data as any), masterSubBidangBisnisId: value }); }} /> console.log("delete")}> */} {/* console.log("add")}> Tambah Pilihan */} Nomor Telepon * setData({ ...data, alamatKantor: value }) } /> setData({ ...data, deskripsi: value }) } autosize minRows={2} maxRows={5} required showCount maxLength={1000} /> ); }