import React, { useState } from "react"; import { StyleSheet, View, Text, Alert, ActivityIndicator, TouchableOpacity, } from "react-native"; import { useNavigation, useRoute } from "@react-navigation/native"; import { CustomButton, CustomInput } from "../../components/common/Custom"; import colors from "../../components/colors"; import AppView from "../../components/AppView"; import { Ionicons } from "@react-native-vector-icons/ionicons"; import { UPDATE_BANK_URL } from "../../utils/ApiUrls"; import { apiCall } from "../../utils/ApiHelper"; const EditBankDetails = () => { const navigation = useNavigation(); const route = useRoute(); // Get initial data from route parameters passed from the Profile screen const { currentBankName, currentAccountNumber, currentBranchCode } = route.params as { currentBankName?: string; currentAccountNumber?: string; currentBranchCode?: string; }; // Initialize state with the passed-in details const [bankName, setBankName] = useState(currentBankName || ""); const [bankAccountNumber, setBankAccountNumber] = useState(currentAccountNumber || ""); const [branchCode, setBranchCode] = useState(currentBranchCode || ""); const [loading, setLoading] = useState(false); // The update function remains the same, using the local state const handleUpdateBankDetails = async () => { if (!bankName || !bankAccountNumber || !branchCode) { Alert.alert("Validation Error", "Please fill in all bank details."); return; } try { setLoading(true); const response = await apiCall(UPDATE_BANK_URL, 'PUT', { bankName, bankAccountNumber, branchCode, }) as { status: string; message?: string }; console.log("Update Bank Response:", response); if (response.status === "success") { Alert.alert("Success", response.message || "Bank details updated successfully!"); navigation.goBack(); } else { Alert.alert("Update Failed", response.message || "Could not update bank details."); } } catch (error: any) { console.error("Error updating bank details:", error); Alert.alert("Error", error.message || "An unexpected error occurred. Please try again."); } finally { setLoading(false); } }; return ( navigation.goBack()} style={styles.backButton}> Edit Bank Details Update Your Bank Information navigation.goBack()} style={styles.cancelButton} buttonBackground={colors.pastelBlue} /> ); }; const styles = StyleSheet.create({ header: { flexDirection: "row", alignItems: "center", padding: 16, }, backButton: { marginRight: 16, }, headerTitle: { fontSize: 22, fontWeight: "600", color: colors.Profile, }, container: { flex: 1, padding: 16, }, sectionTitle: { fontSize: 18, fontWeight: "700", color: "#1e293b", marginBottom: 20, }, buttonContainer: { marginTop: 24, }, cancelButton: { marginTop: 12, borderWidth: 1, borderColor: "#cbd5e1", }, }); export default EditBankDetails;