again push for merge code
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
// src/screens/NotificationRedirection.tsx
|
||||
|
||||
import React, { useEffect } from 'react';
|
||||
import { View, StyleSheet, ActivityIndicator, Text } from 'react-native';
|
||||
import { useRoute, RouteProp, useNavigation } from '@react-navigation/native';
|
||||
import { StackNavigationProp } from '@react-navigation/stack';
|
||||
import { RootStackParamList } from '../navigation/types';
|
||||
|
||||
// Define the specific route prop type for this screen
|
||||
type NotificationRedirectionRouteProp = RouteProp<RootStackParamList, 'NotificationRedirection'>;
|
||||
|
||||
const NotificationRedirection: React.FC = () => {
|
||||
const route = useRoute<NotificationRedirectionRouteProp>();
|
||||
const navigation = useNavigation<StackNavigationProp<RootStackParamList>>();
|
||||
const { data } = route.params;
|
||||
|
||||
useEffect(() => {
|
||||
// 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';
|
||||
params = {
|
||||
screen: 'Management',
|
||||
params: { actionTab: 'Requests' },
|
||||
};
|
||||
break;
|
||||
case 'JOIN_APPROVED':
|
||||
destination = 'Home';
|
||||
params = {
|
||||
screen: 'Management',
|
||||
params: { actionTab: 'Joined Groups' },
|
||||
};
|
||||
break;
|
||||
case 'GROUP_STARTED':
|
||||
destination = 'GroupDetails';
|
||||
params = {
|
||||
item: {id: data?.groupId,
|
||||
},
|
||||
};
|
||||
break;
|
||||
// 'ManagementTabs', { groupId: group.id }
|
||||
case 'CONTRIBUTION':
|
||||
destination = 'ManagementTabs';
|
||||
params = {
|
||||
screen:'Payments',
|
||||
groupId: data.groupId
|
||||
};
|
||||
break;
|
||||
// navigation.navigate('ManagementTabs', { groupId: group.id });
|
||||
|
||||
default:
|
||||
// Keep the default destination as 'Home'
|
||||
break;
|
||||
}
|
||||
|
||||
// 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.');
|
||||
navigation.replace('Home');
|
||||
}
|
||||
}, [data, navigation]); // Effect dependencies
|
||||
|
||||
// This is the only UI the user will see: a clean loading indicator
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<ActivityIndicator size="large" color="#007AFF" />
|
||||
<Text style={styles.loadingText}>Loading...</Text>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
backgroundColor: '#f5f5f5',
|
||||
},
|
||||
loadingText: {
|
||||
marginTop: 10,
|
||||
fontSize: 16,
|
||||
color: '#666',
|
||||
},
|
||||
});
|
||||
|
||||
export default NotificationRedirection;
|
||||
Reference in New Issue
Block a user