import { faAngleLeft, faAngleRight, faArrowLeft, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-native-fontawesome"; import AsyncStorage from "@react-native-async-storage/async-storage"; import { useIsFocused, useNavigation } from "@react-navigation/native"; import React, { useEffect, useState } from "react"; import { Image, StyleSheet, Text, TouchableOpacity, View } from "react-native"; import { get_customer } from "../../services/api/controllers/customers"; const AccountSettings = ({ route }) => { const navigation = useNavigation(); const [user, setuser] = useState([]); const { isrefresh } = route.params ?? ""; const [refresh, setrefresh] = useState(false); const [error, seterror] = useState(false); const isFocused = useIsFocused(); useEffect(() => { /* ---------------Check for the user saved email--------------- */ AsyncStorage.getItem("userData") .then((pass) => { const userDataArray = JSON.parse(pass); setuser(userDataArray); console.log(pass); }) .catch((error) => { console.log(error + "weeewwww"); }); }, []); useEffect(() => { setrefresh(!isrefresh); if (isrefresh) { AsyncStorage.getItem("userData") .then((pass) => { // console.log("mm "+pass._id); const userDataArray = JSON.parse(pass); // setuser(userDataArray); get_customer({ id: userDataArray[0]?._id }) .then((result) => { // console.log(result.data); if (result.error) { seterror(result.error); } else { console.log([result.data]); let userr = [result.data]; AsyncStorage.setItem("userData", JSON.stringify(userr)); setuser([result.data]); } }) .catch((error) => { // setError(error.message); console.log(error.message); }) .finally(() => { // setprodIsLoading(false); // Set loading to false when done loading }); }) .catch((error) => { console.log(error + "weeewwww"); }); } // console.log("get cutomer add :" + user[0]?.login_id); }, [isrefresh]); useEffect(() => { AsyncStorage.getItem("userData") .then((pass) => { // console.log("mm "+pass._id); const userDataArray = JSON.parse(pass); // setuser(userDataArray); get_customer({ id: userDataArray[0]?._id }) .then((result) => { // console.log(result.data); if (result.error) { seterror(result.error); } else { console.log([result.data]); let userr = [result.data]; AsyncStorage.setItem("userData", JSON.stringify(userr)); setuser([result.data]); } }) .catch((error) => { // setError(error.message); console.log(error.message); }) .finally(() => { // setprodIsLoading(false); // Set loading to false when done loading }); }) .catch((error) => { console.log(error + "weeewwww"); }); }, [isFocused]) return ( navigation.navigate("Home")} style={styles.backIcon} > Account Settings My Account {user[0]?.first_name} {user[0]?.last_name} Username {user[0]?.user_login ?? ""} Phone Number { // "+63" + user[0]?.phone_number ?? ""} Email Address {user[0]?.user_email} navigation.navigate("AccountAndSecurity", { isrefresh: false, userData: user[0], }) } > Edit profile navigation.navigate("Address", { isrefresh: !refresh }) } > My Addresses {/* navigation.navigate("Home")} > Bank Accounts */} { AsyncStorage.removeItem("something") .then(() => { console.log("pass removed from AsyncStorage"); }) .catch((error) => { console.error("Error removing item from AsyncStorage: ", error); }); AsyncStorage.removeItem("AccessToken") .then(() => { console.log("token removed from AsyncStorage"); }) .catch((error) => { console.error("Error removing item from AsyncStorage: ", error); }); AsyncStorage.removeItem("email") .then(() => { console.log("email removed from AsyncStorage"); }) .catch((error) => { console.error("Error removing item from AsyncStorage: ", error); }); AsyncStorage.removeItem("userData") .then(() => { console.log("user data removed from AsyncStorage"); }) .catch((error) => { console.error("Error removing item from AsyncStorage: ", error); }); navigation.navigate("Home", { userLoggedin: false }); }} style={styles.subContent} > Log Out ); }; const styles = StyleSheet.create({ container: { backgroundColor: "#ffff", width: "100%", height: "100%", }, wrapper: { height: "100%", width: "100%", backgroundColor: "#fdfdfd", }, header: { alignItems: "center", width: "100%", top: 0, paddingLeft: 15, flexDirection: "row", borderColor: "#ddd", paddingBottom: 15, borderBottomWidth: 1, }, headerText: { fontSize: 16, fontWeight: "600", marginLeft: 25, }, subHeaderWrap: { width: "100%", top: 0, borderColor: "#ddd", paddingBottom: 15, justifyContent: "center", }, subHeader: { width: "100%", paddingLeft: 15, borderColor: "#ddd", justifyContent: "center", }, subHeaderText: { fontSize: 14, fontWeight: "600", padding: 10, }, accountPrev: { width: "100%", // paddingLeft: 15, borderColor: "#ddd", // backgroundColor:"#f5f5f5", justifyContent: "center", alignContent: "center", }, accountPrevWrap: { // width: 150, // top: 0, borderColor: "#ddd", paddingBottom: 15, justifyContent: "center", alignItems: "center", }, accountPrevText: { fontSize: 14, fontWeight: "600", padding: 10, textTransform: "capitalize", }, subContentsWrap: { width: "100%", borderColor: "#ddd", justifyContent: "center", marginTop: 10, }, subContent: { width: "100%", borderColor: "#ececec", backgroundColor: "#fcfcfc", justifyContent: "space-between", alignItems: "center", flexDirection: "row", borderWidth: 1, padding: 15, paddingLeft: 20, }, subContentText: { fontSize: 14, fontWeight: "400", }, subContent1: { width: "100%", borderColor: "#f7f7f7", backgroundColor: "#fff", justifyContent: "space-between", alignItems: "center", flexDirection: "row", borderWidth: 1, padding: 15, paddingLeft: 20, }, subContentText1: { fontSize: 14, fontWeight: "400", }, }); export default AccountSettings;