manage user credancial
This commit is contained in:
+35
-11
@@ -7,21 +7,27 @@ import {
|
||||
UIManager,
|
||||
Platform,
|
||||
Image,
|
||||
Alert,
|
||||
} 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 { useDispatch, useSelector } from "react-redux";
|
||||
import { RouteProp, 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"
|
||||
import { setUserData } from "../../redux/userSlice";
|
||||
// Enable animation for Android
|
||||
if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) {
|
||||
UIManager.setLayoutAnimationEnabledExperimental(true);
|
||||
}
|
||||
|
||||
type RootStackParamList = {
|
||||
Home: { refreshProfile: boolean; role: string };
|
||||
};
|
||||
|
||||
type UserProfile = {
|
||||
id: string;
|
||||
userId: number;
|
||||
@@ -33,9 +39,8 @@ type UserProfile = {
|
||||
const Home = () => {
|
||||
const user = useSelector((state: any) => state.user);
|
||||
const navigation = useNavigation();
|
||||
const route = useRoute();
|
||||
const dispatch = useDispatch()
|
||||
|
||||
console.log("route asf : ", route?.params)
|
||||
const [apiUser, setApiUser] = useState<UserProfile | null | any>(null)
|
||||
|
||||
const fetchUserProfile = async () => {
|
||||
@@ -60,7 +65,29 @@ const Home = () => {
|
||||
console.log("👤 Profile Response:", result);
|
||||
if (result.status === "success") {
|
||||
setApiUser(result.data);
|
||||
|
||||
dispatch(
|
||||
setUserData({
|
||||
id: result.data.id,
|
||||
userId: result.data.userId,
|
||||
username: result.data.username,
|
||||
firstName: result.data.firstName,
|
||||
lastName: result.data.lastName,
|
||||
gender: result.data.gender,
|
||||
mobile: result.data.mobile,
|
||||
email: result.data.email,
|
||||
address: result.data.address,
|
||||
bankAccountNumber: result.data.bankAccountNumber,
|
||||
bankName: result.data.bankName,
|
||||
branchCode: result.data.branchCode,
|
||||
profilePicture: result.data.filePath,
|
||||
filePath: result.data.filePath,
|
||||
imageBlob: result.data.imageBlob,
|
||||
role: result.data.role,
|
||||
organizerId: result.data.organizerId,
|
||||
organizerStatus: result.data.organizerStatus,
|
||||
profileStatus: true,
|
||||
})
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("❌ Error fetching profile:", error);
|
||||
@@ -68,10 +95,8 @@ const Home = () => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (route.params) {
|
||||
fetchUserProfile();
|
||||
}
|
||||
}, [route.params]);
|
||||
fetchUserProfile();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AppView barStyle="dark-content" style={styles.container}>
|
||||
@@ -91,6 +116,7 @@ const Home = () => {
|
||||
</View>
|
||||
{/* Status */}
|
||||
<UserProfileStatus />
|
||||
{/* <UserHome /> */}
|
||||
{user?.role === "USER" || apiUser?.role === "USER" ? <UserHome /> :
|
||||
<GroupsTabs />}
|
||||
</AppView>
|
||||
@@ -110,6 +136,4 @@ const styles = StyleSheet.create({
|
||||
marginBottom: 12,
|
||||
},
|
||||
greeting: { fontSize: 22, fontWeight: "600", color: colors.Home },
|
||||
|
||||
|
||||
});
|
||||
@@ -54,7 +54,7 @@ const UserProfileStatus: React.FC = () => {
|
||||
|
||||
const json: ApiResponse = await response.json();
|
||||
|
||||
console.log("👤 Profile Status Response:", json);
|
||||
console.log("Profile Status :", json);
|
||||
if (json.status === "success") {
|
||||
setStatusData(json.data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user