Merge branch 'feature_redux' of https://git.zeptic.in/abintoppo_lincpay/CircleCollect into feature_profile

This commit is contained in:
Abin Toppo
2025-09-18 13:46:31 +05:30
2 changed files with 66 additions and 2 deletions
+34
View File
@@ -8,6 +8,7 @@ import { BASE_URL } from "../utils/ApiUrls";
import { useDispatch, useSelector } from "react-redux";
import { setUserData } from "../redux/userSlice";
import colors from "../components/colors";
import { ApiResponse } from "./home/UserProfileStatus";
const SplashScreen = () => {
const dispatch = useDispatch();
@@ -15,6 +16,7 @@ const SplashScreen = () => {
const navigation = useNavigation<StackNavigationProp<RootStackParamList>>();
const fadeAnim = useRef(new Animated.Value(1)).current;
const fetchUserProfile = async () => {
try {
const credentials = await Keychain.getGenericPassword();
@@ -69,6 +71,38 @@ const SplashScreen = () => {
}
};
const userStatus = async () => {
try {
const credentials = await Keychain.getGenericPassword();
if (!credentials) {
Alert.alert("Error", "You are not logged in");
return;
}
const token = credentials.password;
const response = await fetch(`${BASE_URL}user/profile/status`, {
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${token}`,
},
});
const json: ApiResponse = await response.json();
console.log("👤 Profile Status Response:", json);
if (json.status === "success") {
} else {
// setError(json.message || "Failed to fetch status");
}
} catch (err) {
// setError("Something went wrong. Please try again.");
}
};
console.log("redux user", user);
useEffect(() => {
+32 -2
View File
@@ -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>