import React, { useCallback, useEffect, useState } from "react"; import { StyleSheet, Text, View, TouchableOpacity, UIManager, Platform, Image, } from "react-native"; import AppView from "../../components/AppView"; import UserProfileStatus from "./UserProfileStatus"; import colors from "../../components/colors"; import GroupsTabs from "./GroupsTabs"; import { useSelector } from "react-redux"; import { useFocusEffect, useNavigation, useRoute } from "@react-navigation/native"; import UserHome from "./user-home/UserHome"; import { PROFILE_URL } from "../../utils/ApiUrls"; import *as Keychain from "react-native-keychain" // Enable animation for Android if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) { UIManager.setLayoutAnimationEnabledExperimental(true); } type UserProfile = { id: string; userId: number; firstName: string | null; lastName: string | null; imageBlob: string | null; role?: string; } const Home = () => { const user = useSelector((state: any) => state.user); const navigation = useNavigation(); const route = useRoute(); console.log("route asf : ", route?.params) const [apiUser, setApiUser] = useState(null) const fetchUserProfile = async () => { try { const credentials = await Keychain.getGenericPassword(); if (!credentials) { return; } const token = credentials.password; const response = await fetch( PROFILE_URL, { method: "GET", headers: { Accept: "*/*", Authorization: `Bearer ${token}`, }, } ); const result = await response.json(); console.log("👤 Profile Response:", result); if (result.status === "success") { setApiUser(result.data); } } catch (error) { console.error("❌ Error fetching profile:", error); } }; useEffect(() => { if (route.params) { fetchUserProfile(); } }, [route.params]); return ( {/* Header */} Hello, {user.firstName || apiUser?.firstName} {user.lastName || apiUser?.lastName}👋 navigation.navigate("Profile" as never)}> {/* Status */} {user?.role === "USER" || apiUser?.role === "USER" ? : } ); }; export default Home; const styles = StyleSheet.create({ container: { paddingBottom: '25%', }, header: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", marginBottom: 12, }, greeting: { fontSize: 22, fontWeight: "600", color: colors.Home }, });