From 848032768cfee999a419e6b5e7350f0f2abcd0ac Mon Sep 17 00:00:00 2001 From: Jaanu423 Date: Mon, 13 Oct 2025 14:00:13 +0530 Subject: [PATCH] correct issues --- src/navigation/AppNavigator.tsx | 14 +- src/navigation/types.ts | 1 + src/screens/GroupCreation.tsx | 5 +- src/screens/GroupScreen.tsx | 6 +- src/screens/NotificationRedirection.tsx | 6 +- src/screens/home/user-home/GroupDetails.tsx | 21 +-- src/screens/notification/Notification.tsx | 135 ++++++++++---------- src/screens/profile/Profile.tsx | 21 ++- src/utils/firebase/firebaseServices.ts | 1 + 9 files changed, 105 insertions(+), 105 deletions(-) diff --git a/src/navigation/AppNavigator.tsx b/src/navigation/AppNavigator.tsx index 58cfcfe..01ab69c 100644 --- a/src/navigation/AppNavigator.tsx +++ b/src/navigation/AppNavigator.tsx @@ -46,12 +46,14 @@ export type RootStackParamList = { TransactionList: undefined RandomSelectUserScreen: { groupId: string | number, cycleNumber: number }; Notification: undefined; - NotificationRedirection:{ data: any }; - Management: - | { actionTab: "My Groups" } - | { actionTab1: "Joined Groups" } - | { actionTab2: "Requests" } - | { actionTab3: "Your Requests" }; + NotificationRedirection: { data: any }; + Management: + | { actionTab: "My Groups" } + | { actionTab1: "Joined Groups" } + | { actionTab2: "Requests" } + | { actionTab3: "Your Requests" } + | { groupId: string | number; } + }; const Stack = createNativeStackNavigator(); diff --git a/src/navigation/types.ts b/src/navigation/types.ts index 26debb7..5517adb 100644 --- a/src/navigation/types.ts +++ b/src/navigation/types.ts @@ -32,6 +32,7 @@ export type RootStackParamList = { ManageJoinedGroup: { groupId: string | number }; Invite: { groupId: string | number; code: string | number }; ManagementTabs:any + NotificationRedirection: { data: any }; }; diff --git a/src/screens/GroupCreation.tsx b/src/screens/GroupCreation.tsx index e51bd18..8461b49 100644 --- a/src/screens/GroupCreation.tsx +++ b/src/screens/GroupCreation.tsx @@ -9,6 +9,7 @@ import { TouchableOpacity, Alert, Image, + ToastAndroid, } from "react-native"; import { useNavigation } from "@react-navigation/native"; import { CustomInput } from "../components/common/Custom"; @@ -75,8 +76,8 @@ export default function GroupCreationForm() { console.log("Reviewing Payload:", payload); navigation.navigate("GroupReview", { form: payload }); } else { - Alert.alert("Incomplete Form", "Please fill out all required fields correctly."); - setErrors('') + ToastAndroid.show('Please fill out all required fields correctly.', ToastAndroid.SHORT); + setErrors(''); } }; diff --git a/src/screens/GroupScreen.tsx b/src/screens/GroupScreen.tsx index 9aee568..e97539c 100644 --- a/src/screens/GroupScreen.tsx +++ b/src/screens/GroupScreen.tsx @@ -12,6 +12,7 @@ import { ScrollView, Alert, RefreshControl, + ToastAndroid, } from "react-native"; import { FAB } from "react-native-paper"; import { Ionicons } from "@react-native-vector-icons/ionicons"; @@ -176,13 +177,12 @@ export default function GroupScreen() { console.log("JOIN_GROUP_URL response:", res); if (res.statusCode === 200) { - Alert.alert("Success", "You requested to join the group."); + ToastAndroid.show('You requested to join the group.', ToastAndroid.SHORT); } else { - // Alert.alert("Error", res.message || "Failed to join group."); + ToastAndroid.show(res.message || "Failed to join group.", ToastAndroid.SHORT); } } catch (error) { console.error("Join Group Error:", error); - // Alert.alert("Error", "An unexpected error occurred."); } }; diff --git a/src/screens/NotificationRedirection.tsx b/src/screens/NotificationRedirection.tsx index b6f3781..8449698 100644 --- a/src/screens/NotificationRedirection.tsx +++ b/src/screens/NotificationRedirection.tsx @@ -18,14 +18,11 @@ const NotificationRedirection: React.FC = () => { // This effect runs once when the component mounts if (data) { console.log('🔄 Processing notification data:', data); - // --- Your Redirection Logic Goes Here --- // Use the 'data' object to decide where to go. // For this example, we'll navigate based on 'msgType'. - let destination: keyof RootStackParamList = 'Home'; // Default destination let params: object | undefined = undefined; - switch (data.msgType) { case 'JOIN_REQUEST': destination = 'Home'; @@ -62,10 +59,9 @@ const NotificationRedirection: React.FC = () => { // Keep the default destination as 'Home' break; } - + console.log(`➡ Redirecting to ${destination} with params:`, params); // Use replace to prevent the user from navigating back to this loading screen navigation.replace(destination, params); - } else { // If no data is passed for some reason, just go to the home screen console.warn('⚠ No data found in notification, redirecting to Home.'); diff --git a/src/screens/home/user-home/GroupDetails.tsx b/src/screens/home/user-home/GroupDetails.tsx index f93a12c..f21de4a 100644 --- a/src/screens/home/user-home/GroupDetails.tsx +++ b/src/screens/home/user-home/GroupDetails.tsx @@ -23,6 +23,7 @@ const CustomDropdown = ({ items, selectedValue, onValueChange, placeholder = "Se const [open, setOpen] = useState(false); const selectedLabel = items.find((item:any) => item.value === selectedValue)?.label || placeholder; + return ( setOpen(true)} style={styles.dropdownHeader}> @@ -64,6 +65,8 @@ const CustomDropdown = ({ items, selectedValue, onValueChange, placeholder = "Se const GroupDetails = () => { const route = useRoute(); + + console.log(" route id : ", route) const [memberData, setMemberData] = useState([]); const [loading, setLoading] = useState(false); const [openModal, setOpenModal] = useState(false); @@ -85,7 +88,7 @@ const GroupDetails = () => { const getCycleDashboard = async () => { try { - const response = await apiCall(`${BASE_URL}payments/groups/${group.id}/cycle-dashboard`, "GET") as any; + const response = await apiCall(`${BASE_URL}payments/groups/${group.id || route?.params?.groupId}/cycle-dashboard`, "GET") as any; const responseData = response.data; setCycleDashboardData(responseData); @@ -106,7 +109,7 @@ const GroupDetails = () => { const fetchGroupDetails = async () => { try { - const res = await apiCall(`${GROUP_ALL_MEMBER}?groupId=${group.id}`, "GET") as any; + const res = await apiCall(`${GROUP_ALL_MEMBER}?groupId=${group.id || route?.params?.groupId}`, "GET") as any; console.log("Group Members Response: ", res); setMemberData(res.data); } catch (error: any) { @@ -116,7 +119,7 @@ const GroupDetails = () => { const handleContribution = async () => { try { - const res = await apiCall(`${CONTRIBUTE}${group.id}/calculate-contribution`, 'GET') as any; + const res = await apiCall(`${CONTRIBUTE}${group.id || route?.params?.groupId}/calculate-contribution`, 'GET') as any; setPayable(res.data); } catch (error) { console.log("Error in handleContribution: ", error); @@ -131,13 +134,13 @@ const GroupDetails = () => { getCycleDashboard() ]); setLoading(false); - }, [group.id]); + }, [group.id || route?.params?.groupId]); useEffect(() => { - if (group.id) { + if (group.id || route?.params?.groupId) { fetchAllData(); } - }, [group.id, fetchAllData]); + }, [group.id || route?.params?.groupId, fetchAllData]); const onRefresh = useCallback(async () => { setRefreshing(true); @@ -169,8 +172,8 @@ const GroupDetails = () => { } contentContainerStyle={styles.scrollContent} > -
- {group.description} +
+ {group.description || route.name} @@ -180,7 +183,7 @@ const GroupDetails = () => { ₹{group.collected} Contribution - + ₹{group.goal} Total Amount diff --git a/src/screens/notification/Notification.tsx b/src/screens/notification/Notification.tsx index 6adcaff..a9aaa4b 100644 --- a/src/screens/notification/Notification.tsx +++ b/src/screens/notification/Notification.tsx @@ -44,22 +44,20 @@ const Notification = () => { dispatch(clearAllNotifications()); }; - const handleMarkAsRead = (messageId: string, screen: string) => { + const handleMarkAsRead = (messageId: string, screen: string, groupId: string, cycleNumber: string, contributionId: string) => { console.log("screen type : ", screen); handleMarkAsReadAndNavigate( messageId, screen, { - // Pass additional parameters based on notification type - groupId: 'ebc27862-acde-4129-b12c-fd4c2966e858', - cycleNumber: '1', - contributionId: '12345', - actionTab3: 'Your Requests' , + groupId: groupId, + cycleNumber, + contributionId, + actionTab3: 'Your Requests', actionTab1: 'Joined Groups', GroupDetails: { item: {} }, - // etc. } ); }; @@ -240,74 +238,77 @@ const Notification = () => { keyExtractor={(item) => item.messageId} showsVerticalScrollIndicator={false} contentContainerStyle={styles.listContainer} - renderItem={({ item }) => ( - handleMarkAsRead(item.messageId, item?.data?.msgType)} - activeOpacity={0.7} - > - - - {/* Icon */} - - - - - {/* Content */} - - - - {item.data.title} - - - {formatTime(item.sentTime)} - + renderItem={({ item }) => { + console.log("noti items : ", item) + return ( + handleMarkAsRead(item.messageId, item?.data?.msgType, item?.data?.groupId, item?.data?.cycleNumber, item?.data?.contributionId)} + activeOpacity={0.7} + > + + + {/* Icon */} + + - - {item.data.body} - - - {item.data.msgType && ( - + {/* Content */} + + - {/* {item.data.msgType} */} - {getFilterDisplayName(item.data.msgType as FilterType)} + {item.data.title} + + + {formatTime(item.sentTime)} - )} - - {/* Actions */} - - {!item.read && ( - - )} - handleDelete(item.messageId)} - style={styles.deleteButton} - > - - + + {item.data.body} + + + {item.data.msgType && ( + + + {/* {item.data.msgType} */} + {getFilterDisplayName(item.data.msgType as FilterType)} + + + )} + + + {/* Actions */} + + {!item.read && ( + + )} + handleDelete(item.messageId)} + style={styles.deleteButton} + > + + + - - - - )} + + + ) + }} ListEmptyComponent={ diff --git a/src/screens/profile/Profile.tsx b/src/screens/profile/Profile.tsx index cd8f078..2791f3c 100644 --- a/src/screens/profile/Profile.tsx +++ b/src/screens/profile/Profile.tsx @@ -161,13 +161,13 @@ const Profile = () => { // Alert.alert("Success", "Profile updated successfully"); // setEditing(false); // fetchUserProfile(); - // if (result.status === "success") { - // Alert.alert("Success", "Profile updated successfully"); - // setEditing(false); - // fetchUserProfile(); // reload updated data - // } else { - // Alert.alert("Error", "Failed to update profile"); - // } + if (result.status === "success") { + Alert.alert("Success", "Profile updated successfully"); + setEditing(false); + fetchUserProfile(); // reload updated data + } else { + Alert.alert("Error", "Failed to update profile"); + } } catch (error) { console.error("❌ Error updating profile:", error); // Alert.alert("Error", "Could not update profile"); @@ -309,7 +309,7 @@ const Profile = () => { return; } - await deleteFcmToken(); + await deleteFcmToken(user?.userId?.toString()); // Clear stored credentials await Keychain.resetGenericPassword(); @@ -463,11 +463,6 @@ const Profile = () => { Personal Information Become Organizer - {/* - - - - */} navigation.navigate('Transaction')}> diff --git a/src/utils/firebase/firebaseServices.ts b/src/utils/firebase/firebaseServices.ts index eefe30d..2619b05 100644 --- a/src/utils/firebase/firebaseServices.ts +++ b/src/utils/firebase/firebaseServices.ts @@ -239,6 +239,7 @@ const processAndAddNotification = (remoteMessage: any) => { title: title, additionalProp1: data?.additionalProp1 || '', additionalProp2: data?.additionalProp2 || '', + groupId: data?.groupId || '', ...data // Spread any additional data }, from: from || 'unknown',