Merge branch 'feature_redux' of https://git.zeptic.in/abintoppo_lincpay/CircleCollect into feature_profile
This commit is contained in:
@@ -19,7 +19,7 @@ import { launchImageLibrary } from "react-native-image-picker";
|
||||
import { CustomButton, CustomInput } from "../../components/common/Custom";
|
||||
import colors from "../../components/colors";
|
||||
import SwitchNavigator from "./SwitchNavigator";
|
||||
import { useFocusEffect } from "@react-navigation/native";
|
||||
import { useFocusEffect, useNavigation } from "@react-navigation/native";
|
||||
import { ApiResponse } from "../home/UserProfileStatus";
|
||||
import { BASE_URL } from "../../utils/ApiUrls";
|
||||
import AppView from "../../components/AppView";
|
||||
@@ -46,6 +46,7 @@ type UserProfile = {
|
||||
};
|
||||
|
||||
const Profile = () => {
|
||||
const navigation = useNavigation<any>();
|
||||
const [user, setUser] = useState<UserProfile | null>(null);
|
||||
const [fetching, setFetching] = useState(true);
|
||||
const [editing, setEditing] = useState(false);
|
||||
@@ -242,6 +243,35 @@ const Profile = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const logout = async (navigation: any) => {
|
||||
try {
|
||||
const credentials = await Keychain.getGenericPassword();
|
||||
|
||||
if (!credentials) {
|
||||
Alert.alert("Info", "No user is currently logged in");
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear stored credentials
|
||||
await Keychain.resetGenericPassword();
|
||||
Alert.alert("Success", "You have been logged out");
|
||||
navigation.replace("Login");
|
||||
} catch (error) {
|
||||
console.error("Logout error:", error);
|
||||
Alert.alert("Error", "Failed to log out. Please try again.");
|
||||
}
|
||||
};
|
||||
|
||||
const confirmLogout = (navigation: any) => {
|
||||
Alert.alert(
|
||||
"Logout",
|
||||
"Are you sure you want to log out?",
|
||||
[
|
||||
{ text: "Cancel", style: "cancel" },
|
||||
{ text: "Yes, Logout", style: "destructive", onPress: () => logout(navigation) },
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
useFocusEffect(
|
||||
@@ -281,7 +311,7 @@ const Profile = () => {
|
||||
{/* Header */}
|
||||
<View style={styles.header}>
|
||||
<Text style={styles.headerTitle}>User Profile</Text>
|
||||
<TouchableOpacity onPress={fetchUserProfile} style={styles.refreshButton}>
|
||||
<TouchableOpacity onPress={() => confirmLogout(navigation)} style={styles.refreshButton}>
|
||||
<Ionicons name="refresh" size={24} color={'#000'} />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user