import React, { useState, useEffect } from "react"; import { View, Text, StyleSheet, TextInput, TouchableOpacity, Alert, ScrollView, } from "react-native"; import { Ionicons } from "@expo/vector-icons"; import { useNavigation, useRoute } from "@react-navigation/native"; import MapView, { Marker } from "react-native-maps"; import { Picker } from "@react-native-picker/picker"; const EditTPS = () => { const navigation = useNavigation(); const route = useRoute(); const { tps } = route.params || {}; // Handle missing tps object gracefully useEffect(() => { if (tps) { console.log("Received tps data:", tps); } else { console.log("No tps data received"); } }, [tps]); const [nama, setNama] = useState(tps?.nama || ""); const [kecamatan, setKecamatan] = useState(tps?.kecamatan || ""); const [alamat, setAlamat] = useState(tps?.alamat || ""); const [jenis, setJenis] = useState(tps?.jenis || ""); const [luas, setLuas] = useState(tps?.luas || ""); const [volume, setVolume] = useState(tps?.volume || ""); const [latitude, setLatitude] = useState(tps?.latitude?.toString() || ""); const [longitude, setLongitude] = useState(tps?.longitude?.toString() || ""); const handleSave = () => { if ( !nama || !kecamatan || !alamat || !jenis || !luas || !volume || !latitude || !longitude ) { Alert.alert("Error", "Semua field harus diisi!"); return; } const updatedTPS = { ...tps, nama, kecamatan, alamat, jenis, luas, volume, latitude: parseFloat(latitude), longitude: parseFloat(longitude), }; // Here you can update your database or state with the updated data. navigation.goBack(); Alert.alert("Sukses", "TPS berhasil diperbarui!"); }; return ( navigation.goBack()} > EDIT LOKASI TPS Pilih Jenis TPS setJenis(itemValue)} > Pilih Kecamatan setKecamatan(itemValue)} > {/* MapView to show location */} {latitude && longitude ? ( ) : null} SIMPAN ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", padding: 16, marginTop: 30, }, header: { flexDirection: "row", alignItems: "center", marginBottom: 20, }, backButton: { marginRight: 20, }, title: { fontSize: 20, fontWeight: "bold", color: "#000", }, formContainer: { marginTop: -15, padding: 15, }, input: { borderWidth: 1, borderColor: "#ccc", borderRadius: 8, padding: 15, marginBottom: 12, fontSize: 14, }, label: { fontSize: 14, fontWeight: "bold", marginBottom: 5, }, picker: { height: 50, borderWidth: 1, borderColor: "#ccc", borderRadius: 8, marginBottom: 12, }, map: { height: 200, marginBottom: 20, }, saveButton: { width: "100%", padding: 15, backgroundColor: "#2D572C", alignItems: "center", borderRadius: 15, }, saveButtonText: { color: "#fff", fontSize: 16, fontWeight: "bold", }, }); export default EditTPS;