fix logical and api integration issues

This commit is contained in:
Jaanu423
2025-10-01 16:40:51 +05:30
parent 017c470fd3
commit 2aebed4386
6 changed files with 67 additions and 23 deletions
+2 -1
View File
@@ -13,6 +13,7 @@ import { RootStackParamList } from '../navigation/AppNavigator'; // Adjust path
import { apiCall } from '../utils/ApiHelper'; // Adjust path
import AppView from '../components/AppView'; // Adjust path
import colors from '../components/colors'; // Adjust path
import { BASE_URL } from '../utils/ApiUrls';
// --- Type Definitions ---
interface Participant {
@@ -52,7 +53,7 @@ const InviteScreen: FC<InviteScreenProps> = ({ route }) => {
setLoading(true);
setError(null);
try {
const response = await apiCall(`http://192.168.1.9:9060/api/fund/group/details?groupId=${groupId}`, 'GET') as { status: string; data?: GroupDetails; message?: string };
const response = await apiCall(`${BASE_URL}fund/group/details?groupId=${groupId}`, 'GET') as { status: string; data?: GroupDetails; message?: string };
if (response.status === 'success' && response.data) {
setGroupDetails(response.data);
} else {
+2 -1
View File
@@ -14,6 +14,7 @@ import { Ionicons } from '@react-native-vector-icons/ionicons';
import colors from '../../components/colors';
import DeclineModal from './DeclineModal';
import * as keychain from 'react-native-keychain'
import { BASE_URL } from '../../utils/ApiUrls';
// Define TypeScript interfaces
interface GroupRequest {
@@ -58,7 +59,7 @@ const RequestList: React.FC = () => {
setError(null);
const response = await fetch(
"http://192.168.1.9:9060/api/fund/group/pending/request",
`${BASE_URL}`,
{
method: "GET",
headers: {
+2 -2
View File
@@ -605,7 +605,7 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
</TouchableOpacity>
</View>
)}
{selectedUser?.cycleStatus !== "PENDING_PAYMENTS" && groupDetails.status === 'ACTIVE' &&(
{selectedUser?.cycleStatus !== "PENDING_PAYMENTS" && groupDetails.status === 'ACTIVE' && selectedUser?.cycleStatus === "PENDING_SELECTION" &&(
<View style={styles.floatingButtonContainer}>
<TouchableOpacity
style={styles.activateButton}
@@ -623,7 +623,7 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
}
{
selectedUser?.selectedUser !== null && selectedUser?.cycleStatus === "READY_FOR_WITHDRAWAL" && selectedUser?.canProceedToWithdrawal &&
selectedUser?.selectedUser !== null && selectedUser?.cycleStatus === "READY_FOR_WITHDRAWAL" &&
<View style={styles.floatingButtonContainer}>
<CustomButton
buttonBackground={colors?.pastelBlue}
+2 -1
View File
@@ -15,6 +15,7 @@ import { apiCall } from '../../utils/ApiHelper'; // Adjust path to your apiCall
import AppView from '../../components/AppView';
import colors from '../../components/colors';
import { useRoute } from '@react-navigation/native';
import { BASE_URL } from '../../utils/ApiUrls';
// --- Type Definitions ---
interface Member {
@@ -56,7 +57,7 @@ const MemberScreen = ({ route }) => {
setLoading(true);
try {
const response = await apiCall<ApiResponse>(
`http://192.168.1.9:9060/api/fund/group/all/member?groupId=${groupId}`,
`${BASE_URL}fund/group/all/member?groupId=${groupId}`,
'GET'
);
@@ -11,10 +11,10 @@ const NUM_COLUMNS = 3;
const ITEM_SIZE = width / NUM_COLUMNS - 20;
const RandomSelectUserScreen: React.FC<{ route: any }> = ({ route }) => {
const navigation = useNavigation()
const navigation = useNavigation()
const { groupId, cycleNumber } = route.params;
const [users, setUsers] = useState<{ id: string; name: string }[]>([]);
const [highlightedIndex, setHighlightedIndex] = useState<number | null>(null);
const [winner, setWinner] = useState<{ id: string; name: string } | null>(null);
@@ -28,11 +28,15 @@ const RandomSelectUserScreen: React.FC<{ route: any }> = ({ route }) => {
const fetchParticipants = async () => {
try {
const response = await apiCall(`${BASE_URL}fund/group/all/member?groupId=${groupId}`, "GET") as any;
if (response.status === 'success' && response.data) {
const formattedUsers = response.data.map((u: any) => ({
id: u.id,
name: `${u.firstName} ${u.lastName}`,
selected: u?.selected
}));
console.log("all mem : ", formattedUsers)
setUsers(formattedUsers);
} else {
Alert.alert('Error', 'Failed to fetch participants.');
@@ -56,18 +60,53 @@ const RandomSelectUserScreen: React.FC<{ route: any }> = ({ route }) => {
}
}, [highlightedIndex]);
// const handleStartSelection = () => {
// if (users.length === 0 || isAnimating) return;
// setWinner(null);
// setIsAnimating(true);
// let highlightCount = 0;
// const maxHighlights = 30 + Math.floor(Math.random() * 10); // Add some randomness
// const highlightInterval = setInterval(() => {
// const randomIndex = Math.floor(Math.random() * users.length);
// setHighlightedIndex(randomIndex);
// highlightCount++;
// if (highlightCount >= maxHighlights) {
// clearInterval(highlightInterval);
// fetchWinner();
// }
// }, 120);
// };
const handleStartSelection = () => {
if (users.length === 0 || isAnimating) return;
// Exclude already selected users
const availableUsers = users.filter(u => !u.selected);
if (availableUsers.length === 0 || isAnimating) {
Alert.alert('Info', 'All users are already selected.');
return;
}
setWinner(null);
setIsAnimating(true);
let highlightCount = 0;
const maxHighlights = 30 + Math.floor(Math.random() * 10); // Add some randomness
const maxHighlights = 30 + Math.floor(Math.random() * 10);
const highlightInterval = setInterval(() => {
const randomIndex = Math.floor(Math.random() * users.length);
setHighlightedIndex(randomIndex);
const randomIndex = Math.floor(Math.random() * availableUsers.length);
const selectedUser = availableUsers[randomIndex];
// Get original index in `users` for highlighting
const originalIndex = users.findIndex(u => u.id === selectedUser.id);
setHighlightedIndex(originalIndex);
highlightCount++;
if (highlightCount >= maxHighlights) {
@@ -81,7 +120,7 @@ const RandomSelectUserScreen: React.FC<{ route: any }> = ({ route }) => {
const payload = { groupId: groupId };
try {
const response = await apiCall(`${BASE_URL}fund/method/based/userSelect`, 'POST', payload) as any;
console.log("random select user response : ", response)
console.log("random select user response : ", response)
if (response.status === 'success' && response.data?.selectedUser?.id) {
const winnerData = { id: response?.data?.selectedUser?.id, name: `${response.data.selectedUser.firstName} ${response.data.selectedUser.lastName}` };
const winnerIndex = users.findIndex(u => u.id === winnerData.id);
@@ -95,7 +134,7 @@ const RandomSelectUserScreen: React.FC<{ route: any }> = ({ route }) => {
} else {
Alert.alert('Error', 'Failed to determine a winner from the API.');
}
navigation.navigate('EditGroup',{groupId})
navigation.replace('EditGroup', { groupId })
} catch (error) {
// Alert.alert('Error', 'Could not connect to the server to fetch the winner.');
} finally {
@@ -103,7 +142,7 @@ const RandomSelectUserScreen: React.FC<{ route: any }> = ({ route }) => {
}
};
const renderItem = ({ item, index }: { item: { id: string; name: string }, index: number }) => {
const renderItem = ({ item, index }: { item: { id: string; name: string, selected: boolean }, index: number }) => {
const isHighlighted = index === highlightedIndex;
const isWinner = winner?.id === item.id && !isAnimating;
@@ -119,6 +158,7 @@ const RandomSelectUserScreen: React.FC<{ route: any }> = ({ route }) => {
isHighlighted && styles.highlightedItem,
isWinner && styles.winnerItem,
animatedStyle,
{ backgroundColor: item?.selected && 'green' }
]}
>
<Ionicons name="person" size={40} color={isHighlighted || isWinner ? '#000000ff' : '#4b5563'} />
@@ -223,14 +263,14 @@ const styles = StyleSheet.create({
borderWidth: 1,
borderColor: '#e5e7eb',
padding: 8,
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.1,
shadowRadius: 3.84,
elevation: 5,
// shadowColor: "#000",
// shadowOffset: {
// width: 0,
// height: 2,
// },
// shadowOpacity: 0.1,
// shadowRadius: 3.84,
// elevation: 5,
},
highlightedItem: {
borderWidth: 5,
+2 -1
View File
@@ -16,6 +16,7 @@ import colors from "../../components/colors";
import { useNavigation } from "@react-navigation/native";
import AppView from "../../components/AppView";
import { Ionicons } from "@react-native-vector-icons/ionicons";
import { BASE_URL } from "../../utils/ApiUrls";
const BecomeOrg = () => {
const navigation = useNavigation<any>();
@@ -43,7 +44,7 @@ const BecomeOrg = () => {
const token = credentials.password;
const response = await fetch(
"http://192.168.1.9:9060/api/organizer/registration/apply",
`${BASE_URL}organizer/registration/apply`,
{
method: "POST",
headers: {