correct issues

This commit is contained in:
Jaanu423
2025-10-13 15:07:31 +05:30
parent 848032768c
commit afe43b56a5
17 changed files with 350 additions and 336 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ const GroupList = () => {
const fetchGroups = async () => {
const credentials = await keychain.getGenericPassword();
if (!credentials) {
Alert.alert("Error", "You are not logged in");
ToastAndroid.show('You are not logged in', ToastAndroid.SHORT);
return;
}
const token = credentials.password;
+2 -1
View File
@@ -10,6 +10,7 @@ import {
Alert,
FlatList,
ListRenderItem,
ToastAndroid,
} from "react-native";
import AppView from "../../components/AppView";
import colors from "../../components/colors";
@@ -97,7 +98,7 @@ const Home: React.FC = () => {
} else if (item.action === "NAVIGATE_CREATE_GROUP") {
navigation.navigate("GroupCreation" as never);
} else {
Alert.alert("Unknown action", item.title);
ToastAndroid.show(`Unknown action: ${item.title}`, ToastAndroid.SHORT);
}
};
+7 -6
View File
@@ -8,7 +8,8 @@ import {
RefreshControl,
Alert,
ActivityIndicator,
TextInput
TextInput,
ToastAndroid
} from 'react-native';
import { Ionicons } from '@react-native-vector-icons/ionicons';
import colors from '../../components/colors';
@@ -50,7 +51,7 @@ const RequestList: React.FC = () => {
const credentials = await keychain.getGenericPassword();
if (!credentials) {
Alert.alert("Error", "You are not logged in");
ToastAndroid.show('You are not logged in', ToastAndroid.SHORT);
return;
}
const token = credentials.password;
@@ -146,14 +147,13 @@ const RequestList: React.FC = () => {
// Remove the accepted request from the list
const updatedRequests = requests.filter(req => req.requestId !== requestId);
setRequests(updatedRequests);
Alert.alert("Success", data.message || "Request accepted successfully");
ToastAndroid.show(data.message || "Request accepted successfully", ToastAndroid.SHORT);
fetchRequests();
} else {
throw new Error(data.message || "Failed to accept request");
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
// Alert.alert("Error", `Failed to accept request: ${errorMessage}`);
console.error("Accept Error:", error);
} finally {
setProcessingRequest(null);
@@ -192,14 +192,15 @@ const RequestList: React.FC = () => {
// Remove the declined request from the list
const updatedRequests = requests.filter(req => req.requestId !== selectedRequestId);
setRequests(updatedRequests);
Alert.alert("Success", data.message || "Request declined successfully");
ToastAndroid.show(data.message || "Request declined successfully", ToastAndroid.SHORT);
fetchRequests();
} else {
throw new Error(data.message || "Failed to decline request");
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
// Alert.alert("Error", `Failed to decline request: ${errorMessage}`);
console.error("Decline Error:", error);
} finally {
setProcessingRequest(null);
+1 -1
View File
@@ -39,7 +39,7 @@ const UserProfileStatus: React.FC = () => {
try {
const credentials = await Keychain.getGenericPassword();
if (!credentials) {
Alert.alert("Error", "You are not logged in");
ToastAndroid.show('You are not logged in', ToastAndroid.SHORT);
return;
}
const token = credentials.password;
+261 -243
View File
@@ -1,249 +1,267 @@
import React, { useEffect, useState } from "react";
import {
StyleSheet,
Text,
View,
FlatList,
TouchableOpacity,
Alert,
RefreshControl,
ScrollView,
Button,
} from "react-native";
import { useNavigation } from "@react-navigation/native";
import type { NativeStackNavigationProp } from "@react-navigation/native-stack";
import type { RootStackParamList } from "../../../navigation/AppNavigator";
import colors from "../../../components/colors";
import { Ionicons } from "@react-native-vector-icons/ionicons";
import { GET_JOINED_GROUP_URL } from "../../../utils/ApiUrls";
import * as Keychain from "react-native-keychain";
import AnimatedCard from "../../../components/common/AnimatedCard";
// import React, { useEffect, useState } from "react";
// import {
// StyleSheet,
// Text,
// View,
// FlatList,
// TouchableOpacity,
// Alert,
// RefreshControl,
// ScrollView,
// Button,
// ToastAndroid,
// } from "react-native";
// import { useNavigation } from "@react-navigation/native";
// import type { NativeStackNavigationProp } from "@react-navigation/native-stack";
// import type { RootStackParamList } from "../../../navigation/AppNavigator";
// import colors from "../../../components/colors";
// import { Ionicons } from "@react-native-vector-icons/ionicons";
// import { GET_JOINED_GROUP_URL } from "../../../utils/ApiUrls";
// import * as Keychain from "react-native-keychain";
// import AnimatedCard from "../../../components/common/AnimatedCard";
type NavigationProp = NativeStackNavigationProp<
RootStackParamList,
"GroupDetails"
>;
// type NavigationProp = NativeStackNavigationProp<
// RootStackParamList,
// "GroupDetails"
// >;
type Group = {
id: string;
groupName: string;
description: string;
currentParticipants: number;
maxParticipants: number;
contributionAmount: number;
status: string;
};
// type Group = {
// id: string;
// groupName: string;
// description: string;
// currentParticipants: number;
// maxParticipants: number;
// contributionAmount: number;
// status: string;
// };
// const UserHome = () => {
// const navigation = useNavigation<NavigationProp>();
// const [groups, setGroups] = useState<Group[]>([]);
// const [loading, setLoading] = useState<boolean>(false)
// const [refreshing, setRefreshing] = useState<boolean>(false)
// const activeGroups = groups.filter((g) => g.status === "ACTIVE");
// const totalGroups = activeGroups.length;
// const totalContribution = activeGroups.reduce(
// (sum, g) => sum + g.contributionAmount,
// 0
// );
// const onRefresh = async () => {
// setRefreshing(true)
// await handleGroup()
// setRefreshing(false)
// }
// const handleGroup = async () => {
// try {
// setLoading(true)
// const credentials = await Keychain.getGenericPassword();
// if (!credentials) {
// ToastAndroid.show('You are not logged in', ToastAndroid.SHORT);
// return;
// }
// const token = credentials.password;
// const response = await fetch(GET_JOINED_GROUP_URL, {
// method: "GET",
// headers: {
// Accept: "*/*",
// Authorization: `Bearer ${token}`,
// },
// });
// const result = await response.json();
// if (result.status === "success") {
// console.log("GET_JOINED_GROUP_URL res : ", result);
// setGroups(result.data); // save API data
// setLoading(false)
// } else {
// ToastAndroid.show("Failed to fetch groups", ToastAndroid.SHORT);
// setLoading(false)
// }
// } catch (error) {
// console.error("❌ Error fetching groups:", error);
// } finally {
// setLoading(false)
// }
// };
// useEffect(() => {
// handleGroup();
// }, []);
// const renderItem = ({ item }: { item: Group }) => {
// return (
// <TouchableOpacity
// style={styles.card}
// onPress={() => navigation.navigate("GroupDetails", { item })}
// >
// <Text style={styles.groupName}>{item.groupName}</Text>
// <Text style={styles.description} numberOfLines={1}>{item.description}</Text>
// <View style={styles.statsRow}>
// <Ionicons
// name="person-circle-outline"
// size={20}
// color={colors.primary}
// />
// <Text style={styles.detail}>
// {item.currentParticipants}/{item.maxParticipants} members
// </Text>
// </View>
// <Text style={styles.amount}>
// Contribution: ₹{item.contributionAmount}
// </Text>
// <Text style={styles.status}>Status: {item.status}</Text>
// </TouchableOpacity>
// );
// };
// return (
// <ScrollView>
// {/* Stats */}
// {/* <Button title="Transaction List" onPress={()=>navigation.navigate('TransactionList')}/> */}
// <AnimatedCard
// onPress={() => navigation.navigate("TransactionList")}
// title={"transaction list"} iconName="calculator-outline"
// subtitle="View your transaction history"
// backOne={colors.Home}
// backTwo={colors.pastelPink}
// />
// <AnimatedCard
// onPress={() => navigation.navigate("Management" as never)}
// title={"Group Management"}
// iconName="person-outline"
// subtitle="Manage your joined & requested groups"
// backOne={colors.Settings}
// backTwo={colors.pastelOrange}
// />
// <View style={[styles.statsRow, { marginTop: 12 }]}>
// <View style={styles.statBox}>
// <Text style={styles.statValue}>{totalGroups}</Text>
// <Text style={styles.statLabel}>Groups Joined</Text>
// </View>
// <View style={styles.statBox}>
// <Text style={styles.statValue}>₹{totalContribution}</Text>
// <Text style={styles.statLabel}>Cycle Contribution</Text>
// </View>
// </View>
// {/* Groups List */}
// <Text style={styles.sectionTitle}>Your Groups</Text>
// <FlatList
// data={groups.filter((status) => status.status === "ACTIVE")}
// keyExtractor={(item) => item.id}
// renderItem={renderItem}
// contentContainerStyle={{ paddingBottom: 20 }}
// onRefresh={onRefresh}
// refreshing={refreshing}
// />
// </ScrollView>
// );
// };
// export default UserHome;
// const styles = StyleSheet.create({
// statsRow: {
// flexDirection: "row",
// gap: 10,
// },
// statBox: {
// flex: 1,
// backgroundColor: "#fff",
// padding: 16,
// borderRadius: 12,
// alignItems: "center",
// shadowColor: "#000",
// shadowOpacity: 0.05,
// shadowOffset: { width: 0, height: 2 },
// shadowRadius: 6,
// elevation: 2,
// borderWidth:1,
// borderColor:colors.Home
// },
// statValue: {
// fontSize: 18,
// fontWeight: "700",
// color: colors.Home,
// },
// statLabel: {
// fontSize: 12,
// color: "#64748b",
// marginTop: 4,
// },
// sectionTitle: {
// fontSize: 18,
// fontWeight: "600",
// color: colors.Home,
// marginBottom: 12,
// marginTop:15
// },
// card: {
// backgroundColor: "#ffffff",
// padding: 16,
// marginBottom: 12,
// borderRadius: 12,
// shadowColor: "#000",
// shadowOpacity: 0.05,
// shadowOffset: { width: 0, height: 2 },
// shadowRadius: 6,
// elevation: 2,
// borderLeftWidth: 5,
// borderColor: colors.Home
// },
// groupName: {
// fontSize: 16,
// fontWeight: "600",
// color: colors.Home,
// marginBottom: 4,
// },
// description: {
// fontSize: 13,
// color: "#475569",
// marginBottom: 8,
// },
// detail: {
// fontSize: 13,
// color: "#475569",
// marginBottom: 8,
// },
// amount: {
// fontSize: 13,
// color: "#64748b",
// marginTop: 4,
// },
// status: {
// fontSize: 12,
// fontWeight: "500",
// color: colors.primary,
// marginTop: 2,
// },
// });
import { StyleSheet, Text, View } from 'react-native'
import React from 'react'
const UserHome = () => {
const navigation = useNavigation<NavigationProp>();
const [groups, setGroups] = useState<Group[]>([]);
const [loading, setLoading] = useState<boolean>(false)
const [refreshing, setRefreshing] = useState<boolean>(false)
return (
<View>
<Text>UserHome</Text>
</View>
)
}
export default UserHome
const activeGroups = groups.filter((g) => g.status === "ACTIVE");
const totalGroups = activeGroups.length;
const totalContribution = activeGroups.reduce(
(sum, g) => sum + g.contributionAmount,
0
);
const onRefresh = async () => {
setRefreshing(true)
await handleGroup()
setRefreshing(false)
}
const handleGroup = async () => {
try {
setLoading(true)
const credentials = await Keychain.getGenericPassword();
if (!credentials) {
Alert.alert("Error", "You are not logged in");
return;
}
const token = credentials.password;
const response = await fetch(GET_JOINED_GROUP_URL, {
method: "GET",
headers: {
Accept: "*/*",
Authorization: `Bearer ${token}`,
},
});
const result = await response.json();
if (result.status === "success") {
console.log("GET_JOINED_GROUP_URL res : ", result);
setGroups(result.data); // save API data
setLoading(false)
} else {
Alert.alert("Error", "Failed to fetch groups");
}
} catch (error) {
console.error("❌ Error fetching groups:", error);
// Alert.alert("Error", "Could not connect to server");
} finally {
setLoading(false)
}
};
useEffect(() => {
handleGroup();
}, []);
const renderItem = ({ item }: { item: Group }) => {
return (
<TouchableOpacity
style={styles.card}
onPress={() => navigation.navigate("GroupDetails", { item })}
>
<Text style={styles.groupName}>{item.groupName}</Text>
<Text style={styles.description} numberOfLines={1}>{item.description}</Text>
<View style={styles.statsRow}>
<Ionicons
name="person-circle-outline"
size={20}
color={colors.primary}
/>
<Text style={styles.detail}>
{item.currentParticipants}/{item.maxParticipants} members
</Text>
</View>
<Text style={styles.amount}>
Contribution: ₹{item.contributionAmount}
</Text>
<Text style={styles.status}>Status: {item.status}</Text>
</TouchableOpacity>
);
};
return (
<ScrollView>
{/* Stats */}
{/* <Button title="Transaction List" onPress={()=>navigation.navigate('TransactionList')}/> */}
<AnimatedCard
onPress={() => navigation.navigate("TransactionList")}
title={"transaction list"} iconName="calculator-outline"
subtitle="View your transaction history"
backOne={colors.Home}
backTwo={colors.pastelPink}
/>
<AnimatedCard
onPress={() => navigation.navigate("Management" as never)}
title={"Group Management"}
iconName="person-outline"
subtitle="Manage your joined & requested groups"
backOne={colors.Settings}
backTwo={colors.pastelOrange}
/>
<View style={[styles.statsRow, { marginTop: 12 }]}>
<View style={styles.statBox}>
<Text style={styles.statValue}>{totalGroups}</Text>
<Text style={styles.statLabel}>Groups Joined</Text>
</View>
<View style={styles.statBox}>
<Text style={styles.statValue}>₹{totalContribution}</Text>
<Text style={styles.statLabel}>Cycle Contribution</Text>
</View>
</View>
{/* Groups List */}
<Text style={styles.sectionTitle}>Your Groups</Text>
<FlatList
data={groups.filter((status) => status.status === "ACTIVE")}
keyExtractor={(item) => item.id}
renderItem={renderItem}
contentContainerStyle={{ paddingBottom: 20 }}
onRefresh={onRefresh}
refreshing={refreshing}
/>
</ScrollView>
);
};
export default UserHome;
const styles = StyleSheet.create({
statsRow: {
flexDirection: "row",
gap: 10,
},
statBox: {
flex: 1,
backgroundColor: "#fff",
padding: 16,
borderRadius: 12,
alignItems: "center",
shadowColor: "#000",
shadowOpacity: 0.05,
shadowOffset: { width: 0, height: 2 },
shadowRadius: 6,
elevation: 2,
borderWidth:1,
borderColor:colors.Home
},
statValue: {
fontSize: 18,
fontWeight: "700",
color: colors.Home,
},
statLabel: {
fontSize: 12,
color: "#64748b",
marginTop: 4,
},
sectionTitle: {
fontSize: 18,
fontWeight: "600",
color: colors.Home,
marginBottom: 12,
marginTop:15
},
card: {
backgroundColor: "#ffffff",
padding: 16,
marginBottom: 12,
borderRadius: 12,
shadowColor: "#000",
shadowOpacity: 0.05,
shadowOffset: { width: 0, height: 2 },
shadowRadius: 6,
elevation: 2,
borderLeftWidth: 5,
borderColor: colors.Home
},
groupName: {
fontSize: 16,
fontWeight: "600",
color: colors.Home,
marginBottom: 4,
},
description: {
fontSize: 13,
color: "#475569",
marginBottom: 8,
},
detail: {
fontSize: 13,
color: "#475569",
marginBottom: 8,
},
amount: {
fontSize: 13,
color: "#64748b",
marginTop: 4,
},
status: {
fontSize: 12,
fontWeight: "500",
color: colors.primary,
marginTop: 2,
},
});
const styles = StyleSheet.create({})