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
+3 -2
View File
@@ -190,7 +190,8 @@ export default function GroupScreen() {
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;
@@ -233,7 +234,7 @@ export default function GroupScreen() {
const handleViewGroup = (group: Group) => {
// navigation.navigate('GroupDetails', { group });
Alert.alert("View Group", `Viewing details for ${group.groupName}`);
ToastAndroid.show(`Viewing details for ${group.groupName}`, ToastAndroid.SHORT);
};
const onRefresh = () => {
+4 -2
View File
@@ -8,6 +8,7 @@ import {
TouchableOpacity,
Alert,
ActivityIndicator,
ToastAndroid,
} from 'react-native';
import { RootStackParamList } from '../navigation/AppNavigator'; // Adjust path
import { apiCall } from '../utils/ApiHelper'; // Adjust path
@@ -78,9 +79,10 @@ const InviteScreen: FC<InviteScreenProps> = ({ route }) => {
// Replace with your actual API call to join the group
// For now, it just shows an alert.
await apiCall(`http://192.168.1.5:9060/api/fund/groups/join/invite/${code}`, 'POST');
Alert.alert('Success!', `You have requested to join "${groupDetails.groupName}".`);
ToastAndroid.show(`You have requested to join "${groupDetails.groupName}".`, ToastAndroid.SHORT);
fetchGroupDetails(); // Refresh details after joining
} catch (e: any) {
Alert.alert('Join Error', e.message || 'An unexpected error occurred.');
ToastAndroid.show(e.message || 'An unexpected error occurred.', ToastAndroid.SHORT);
} finally {
setJoining(false);
}
+8 -4
View File
@@ -9,6 +9,7 @@ import {
KeyboardAvoidingView,
Platform,
ScrollView,
ToastAndroid,
} from "react-native";
import axios from "axios";
import { ORGRAGISTRATION } from "../utils/ApiUrls";
@@ -30,7 +31,7 @@ export default function OrganizerRegisterScreen() {
const [loading, setLoading] = useState(false);
const handleSubmit = async () => {
if (!bankAccountNumber || !bankName || !branchCode) {
Alert.alert("Error", "All fields are required.");
ToastAndroid.show('All fields are required.', ToastAndroid.SHORT);
return;
}
@@ -42,7 +43,7 @@ const handleSubmit = async () => {
const token = creds ? creds.password : null;
if (!token) {
Alert.alert("Error", "No token found. Please log in again.");
ToastAndroid.show('No token found. Please log in again.', ToastAndroid.SHORT);
setLoading(false);
return;
}
@@ -65,10 +66,13 @@ const handleSubmit = async () => {
);
console.log("✅ Organizer Registered:", res.data);
Alert.alert("Success", "Organizer registered successfully!");
ToastAndroid.show('Organizer registered successfully!', ToastAndroid.SHORT);
// Optionally, reset form fields
setBankAccountNumber("");
setBankName("");
setBranchCode("");
} catch (err: any) {
console.error("❌ Register Error:", err?.response?.data || err.message);
// Alert.alert("Error", "Failed to register. Please try again.");
} finally {
setLoading(false);
}
+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({})
+12 -25
View File
@@ -202,18 +202,18 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
if (editableData.maxParticipants < groupDetails.totalParticipants) {
Alert.alert('Invalid Input', `Max participants cannot be less than the current count (${groupDetails.totalParticipants}).`);
ToastAndroid.show(`Max participants cannot be less than the current count (${groupDetails.totalParticipants}).`, ToastAndroid.SHORT);
return;
}
setSaving(true);
try {
await apiCall(`${BASE_URL}fund/groups/${groupDetails.id}/edit`, 'PUT', editableData);
Alert.alert('Success', 'Group has been updated.');
ToastAndroid.show('Group has been updated.', ToastAndroid.SHORT);
setEditingCard(null);
await fetchGroupDetails();
} catch (e: any) {
Alert.alert('Save Error', e.message || 'An unexpected error occurred.');
ToastAndroid.show(e.message || 'An unexpected error occurred.', ToastAndroid.SHORT);
} finally {
setSaving(false);
}
@@ -241,11 +241,11 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
setStarting(true);
try {
await apiCall(`${BASE_URL}fund/group/start?groupId=${groupDetails.id}`, 'GET');
Alert.alert('Success', 'Group has been started successfully.');
ToastAndroid.show('Group has been started successfully.', ToastAndroid.SHORT);
await fetchGroupDetails();
navigation.goBack()
} catch (e: any) {
Alert.alert('Start Error', e.message || 'An unexpected error occurred.');
ToastAndroid.show(e.message || 'An unexpected error occurred.', ToastAndroid.SHORT);
} finally {
setStarting(false);
}
@@ -267,7 +267,7 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
if (inviteLink) {
Clipboard.setString(inviteLink);
Alert.alert('Copied!', 'Invitation link copied to clipboard.');
ToastAndroid.show('Invitation link copied to clipboard.', ToastAndroid.SHORT);
await Share.share({
message: `Join my group on CircleCollect! ${inviteLink}`,
url: inviteLink,
@@ -277,7 +277,7 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
throw new Error('Could not generate invitation link.');
}
} catch (error: any) {
Alert.alert('Error', error.message || 'Failed to generate invitation.');
ToastAndroid.show(error.message || 'Failed to generate invitation.', ToastAndroid.SHORT);
} finally {
setInviting(false);
}
@@ -380,30 +380,18 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
const canStartGroup = groupDetails.status === 'APPROVED' && groupDetails.totalParticipants >= groupDetails.minParticipants;
console.log(" myu status : ", groupDetails.status)
// const pickImage = () => {
// launchImageLibrary({ mediaType: "photo", quality: 0.5 }, (response) => {
// if (response.didCancel) return;
// if (response.errorCode) {
// Alert.alert("Error", response.errorMessage || "Something went wrong");
// } else if (response.assets && response.assets.length > 0) {
// const selectedImage = response.assets[0];
// console.log(selectedImage?.uri)
// setSelectedImage(selectedImage?.uri)
// }
// });
// };
const pickImage = () => {
launchImageLibrary({ mediaType: "photo", quality: 0.5 }, (response) => {
if (response.didCancel) return;
if (response.errorCode) {
Alert.alert("Error", response.errorMessage || "Something went wrong");
ToastAndroid.show(response.errorMessage || "Something went wrong", ToastAndroid.SHORT);
return;
}
if (!response.assets || response.assets.length === 0) {
Alert.alert("Error", "No image selected");
ToastAndroid.show("No image selected", ToastAndroid.SHORT);
return;
}
@@ -423,7 +411,7 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
// Additional validation for required fields
if (!selectedImage.uri) {
Alert.alert("Error", "Invalid image file");
ToastAndroid.show("Invalid image file", ToastAndroid.SHORT);
return;
}
@@ -442,13 +430,13 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
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;
if (!selectedImage) {
Alert.alert("Error", "Please select an image first");
ToastAndroid.show("Please select an image first", ToastAndroid.SHORT);
return;
}
@@ -487,7 +475,6 @@ const EditGroupScreen: React.FC<EditGroupScreenProps> = ({ route }) => {
} catch (error: any) {
console.error("❌ Error updating group image:", error);
// Alert.alert("Error", error.message || "Could not update group image");
} finally {
setImageUpdating(false);
}
+4 -2
View File
@@ -8,6 +8,7 @@ import {
TouchableOpacity,
ActivityIndicator,
Alert,
ToastAndroid,
} from "react-native";
import { useNavigation, useFocusEffect, useRoute, RouteProp } from "@react-navigation/native";
import { StackNavigationProp } from "@react-navigation/stack";
@@ -102,13 +103,14 @@ const ManagementScreen: FC = () => {
// No need to set loading here if the whole screen is already loading
const res = await apiCall(url, "PUT", {}) as ApiResponse<null> | null;
if (res && res.statusCode === 200) {
Alert.alert("Success", res.message || successMessage);
ToastAndroid.show("Success", ToastAndroid.SHORT);
fetchData(); // Refresh data after action
} else {
throw new Error(res?.message || failureMessage);
}
} catch (err: any) {
// Alert.alert("Error", err.message || "An unexpected error occurred.");
console.error("Action Error:", err);
ToastAndroid.show(err.message || failureMessage, ToastAndroid.SHORT);
}
};
+6 -5
View File
@@ -1,5 +1,5 @@
import React, { useEffect, useState, useCallback } from 'react';
import { View, Text, StyleSheet, ActivityIndicator, ScrollView, RefreshControl, Alert, TouchableOpacity, Modal, TextInput } from 'react-native';
import { View, Text, StyleSheet, ActivityIndicator, ScrollView, RefreshControl, Alert, TouchableOpacity, Modal, TextInput, ToastAndroid } from 'react-native';
import { useRoute, RouteProp } from '@react-navigation/native';
import { Ionicons } from "@react-native-vector-icons/ionicons";
import colors from '../../components/colors';
@@ -121,12 +121,12 @@ const Payments: React.FC = () => {
const amountToWaive = parseFloat(waiverAmount);
if (isNaN(amountToWaive) || amountToWaive < 0) {
Alert.alert("Invalid Input", "Please enter a valid waiver amount.");
ToastAndroid.show("Please enter a valid waiver amount.", ToastAndroid.SHORT);
return;
}
if (amountToWaive > currentParticipant.lateFee) {
Alert.alert("Invalid Amount", `Waiver cannot exceed the current late fee of ₹${currentParticipant.lateFee}.`);
ToastAndroid.show(`Waiver cannot exceed the current late fee of ₹${currentParticipant.lateFee}.`, ToastAndroid.SHORT);
return;
}
@@ -135,14 +135,15 @@ const Payments: React.FC = () => {
const response = await apiCall(url, 'PUT', {}) as any;
if (response && response.statusCode === 200) {
Alert.alert("Success", `₹${amountToWaive} has been waived successfully.`);
ToastAndroid.show(`₹${amountToWaive} has been waived successfully.`, ToastAndroid.SHORT);
setModalVisible(false);
onRefresh();
} else {
throw new Error(response?.message || "Failed to apply waiver.");
}
} catch (error: any) {
Alert.alert("API Error", error.message);
ToastAndroid.show(error.message || "Failed to apply waiver.", ToastAndroid.SHORT);
console.error("Waive Fee Error:", error);
}
};
@@ -1,5 +1,5 @@
import React, { useState, useEffect, useRef } from 'react';
import { View, Text, StyleSheet, TouchableOpacity, FlatList, Dimensions, Alert, ActivityIndicator, Animated, Button } from 'react-native';
import { View, Text, StyleSheet, TouchableOpacity, FlatList, Dimensions, Alert, ActivityIndicator, Animated, Button, ToastAndroid } from 'react-native';
import { apiCall } from '../../utils/ApiHelper';
import { Ionicons } from "@react-native-vector-icons/ionicons";
import { useNavigation } from '@react-navigation/native';
@@ -44,10 +44,10 @@ const RandomSelectUserScreen: React.FC<{ route: any }> = ({ route }) => {
setUsers(formattedUsers);
} else {
Alert.alert('Error', 'Failed to fetch participants.');
ToastAndroid.show('Failed to fetch participants.', ToastAndroid.SHORT);
}
} catch (error) {
Alert.alert('Error', 'Could not connect to the server to fetch participants.');
ToastAndroid.show('Could not connect to the server to fetch participants.', ToastAndroid.SHORT);
} finally {
setIsLoading(false);
}
@@ -94,7 +94,7 @@ const RandomSelectUserScreen: React.FC<{ route: any }> = ({ route }) => {
const availableUsers = users.filter(u => !u.selected);
if (availableUsers.length === 0 || isAnimating) {
Alert.alert('Info', 'All users are already selected.');
ToastAndroid.show('All users are already selected.', ToastAndroid.SHORT);
return;
}
@@ -134,14 +134,14 @@ const RandomSelectUserScreen: React.FC<{ route: any }> = ({ route }) => {
setWinner(winnerData);
setHighlightedIndex(winnerIndex);
} else {
Alert.alert('Error', 'Winner not found among participants.');
ToastAndroid.show('Winner not found among participants.', ToastAndroid.SHORT);
}
} else {
Alert.alert('Error', 'Failed to determine a winner from the API.');
ToastAndroid.show('Failed to determine a winner from the API.', ToastAndroid.SHORT);
}
navigation.replace('EditGroup', { groupId })
} catch (error) {
// Alert.alert('Error', 'Could not connect to the server to fetch the winner.');
ToastAndroid.show('Could not connect to the server to fetch the winner.', ToastAndroid.SHORT);
} finally {
setIsAnimating(false);
}
+2 -1
View File
@@ -13,6 +13,7 @@ import {
NativeModules,
Linking,
Alert,
ToastAndroid,
} from "react-native";
import AppView from "../../components/AppView";
import colors from "../../components/colors";
@@ -83,7 +84,7 @@ const YourContacts = () => {
}
} catch (err) {
console.error("Error sending to WhatsApp:", err);
Alert.alert("Error", "Something went wrong while trying to open WhatsApp");
ToastAndroid.show("Something went wrong while trying to open WhatsApp", ToastAndroid.SHORT);
}
setModalVisible(false);
+6 -5
View File
@@ -9,6 +9,7 @@ import {
KeyboardAvoidingView,
Platform,
TouchableOpacity,
ToastAndroid,
} from "react-native";
import * as Keychain from "react-native-keychain";
import { CustomInput, CustomButton } from "../../components/common/Custom";
@@ -27,7 +28,7 @@ const BecomeOrg = () => {
const handleSubmit = async () => {
if (!idName || !idNumber || !issueDate) {
Alert.alert("Error", "Please fill all fields");
ToastAndroid.show("Please fill all fields", ToastAndroid.SHORT);
return;
}
@@ -35,7 +36,7 @@ const BecomeOrg = () => {
setLoading(true);
const credentials = await Keychain.getGenericPassword();
if (!credentials) {
Alert.alert("Error", "You are not logged in. Please log in to continue.");
ToastAndroid.show("You are not logged in. Please log in to continue.", ToastAndroid.SHORT);
setLoading(false);
// Optionally navigate to login screen
// navigation.navigate("Login");
@@ -62,17 +63,17 @@ const BecomeOrg = () => {
const result = await response.json();
if (response.ok && result.status === "success") {
Alert.alert("Success", "Organizer registration application submitted successfully!");
ToastAndroid.show("Organizer registration application submitted successfully!", ToastAndroid.SHORT);
setIdName("");
setIdNumber("");
setIssueDate("");
navigation.navigate("Home" as never);
} else {
Alert.alert("Error", result.message || "Failed to submit application");
ToastAndroid.show(result.message || "Failed to submit application", ToastAndroid.SHORT);
}
} catch (error) {
console.error("❌ Registration error:", error);
// Alert.alert("Error", "An unexpected error occurred. Please try again.");
ToastAndroid.show("An unexpected error occurred. Please try again.", ToastAndroid.SHORT);
} finally {
setLoading(false);
}
+5 -4
View File
@@ -6,6 +6,7 @@ import {
Alert,
ActivityIndicator,
TouchableOpacity,
ToastAndroid,
} from "react-native";
import { useNavigation, useRoute } from "@react-navigation/native";
import { CustomButton, CustomInput } from "../../components/common/Custom";
@@ -39,7 +40,7 @@ const EditBankDetails = () => {
// The update function remains the same, using the local state
const handleUpdateBankDetails = async () => {
if (!bankName || !bankAccountNumber || !branchCode) {
Alert.alert("Validation Error", "Please fill in all bank details.");
ToastAndroid.show("Please fill in all bank details.", ToastAndroid.SHORT);
return;
}
@@ -52,14 +53,14 @@ const EditBankDetails = () => {
}) as { status: string; message?: string };
console.log("Update Bank Response:", response);
if (response.status === "success") {
Alert.alert("Success", response.message || "Bank details updated successfully!");
ToastAndroid.show(response.message || "Bank details updated successfully!", ToastAndroid.SHORT);
navigation.goBack();
} else {
Alert.alert("Update Failed", response.message || "Could not update bank details.");
ToastAndroid.show(response.message || "Could not update bank details.", ToastAndroid.SHORT);
}
} catch (error: any) {
console.error("Error updating bank details:", error);
// Alert.alert("Error", error.message || "An unexpected error occurred. Please try again.");
ToastAndroid.show(error.message || "An unexpected error occurred. Please try again.", ToastAndroid.SHORT);
} finally {
setLoading(false);
}
+16 -22
View File
@@ -13,6 +13,7 @@ import {
KeyboardAvoidingView,
Platform,
RefreshControl,
ToastAndroid,
} from "react-native";
import * as Keychain from "react-native-keychain";
import { Ionicons } from "@react-native-vector-icons/ionicons";
@@ -69,7 +70,7 @@ const Profile = () => {
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;
@@ -114,11 +115,10 @@ const Profile = () => {
profileStatus: true, // set true once profile is fetched
}));
} else {
Alert.alert("Error", "Failed to fetch user profile");
ToastAndroid.show("Failed to fetch user profile", ToastAndroid.SHORT);
}
} catch (error) {
console.error("❌ Error fetching profile:", error);
// Alert.alert("Error", "Could not connect to server");
} finally {
setFetching(false);
}
@@ -129,7 +129,7 @@ const Profile = () => {
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;
@@ -157,20 +157,16 @@ const Profile = () => {
const result = await response.json();
console.log("result for profile update :", result);
// Alert.alert("Success", "Profile updated successfully");
// setEditing(false);
// fetchUserProfile();
if (result.status === "success") {
Alert.alert("Success", "Profile updated successfully");
ToastAndroid.show("Profile updated successfully", ToastAndroid.SHORT);
setEditing(false);
fetchUserProfile(); // reload updated data
} else {
Alert.alert("Error", "Failed to update profile");
ToastAndroid.show("Failed to update profile", ToastAndroid.SHORT);
}
} catch (error) {
console.error("❌ Error updating profile:", error);
// Alert.alert("Error", "Could not update profile");
ToastAndroid.show("Could not update profile", ToastAndroid.SHORT);
}
};
@@ -179,7 +175,7 @@ const Profile = () => {
launchImageLibrary({ mediaType: "photo", quality: 0.5 }, (response) => {
if (response.didCancel) return;
if (response.errorCode) {
Alert.alert("Error", response.errorMessage || "Something went wrong");
ToastAndroid.show(response.errorMessage || "Something went wrong", ToastAndroid.SHORT);
} else if (response.assets && response.assets.length > 0) {
const selectedImage = response.assets[0];
setUser((prev: any) =>
@@ -194,14 +190,14 @@ const Profile = () => {
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;
if (!user?.filePath) {
Alert.alert("Error", "Please select an image first");
ToastAndroid.show("Please select an image first", ToastAndroid.SHORT);
return;
}
@@ -232,8 +228,7 @@ const Profile = () => {
const result = await response.json();
if (result.status === "success") {
Alert.alert("Success", "Profile image updated successfully");
ToastAndroid.show("Profile image updated successfully", ToastAndroid.SHORT);
// If API returns updated image, set it
if (result.data?.imageBlob) {
@@ -247,11 +242,11 @@ const Profile = () => {
// Refresh profile from API as well
fetchUserProfile();
} else {
Alert.alert("Error", result.message || "Failed to update profile image");
ToastAndroid.show(result.message || "Failed to update profile image", ToastAndroid.SHORT);
}
} catch (error) {
console.error("❌ Error updating profile image:", error);
// Alert.alert("Error", "Could not update profile image");
ToastAndroid.show("Could not update profile image", ToastAndroid.SHORT);
} finally {
setImageUpdating(false);
}
@@ -262,7 +257,7 @@ const Profile = () => {
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;
@@ -305,7 +300,7 @@ const Profile = () => {
if (!credentials) {
Alert.alert("Info", "No user is currently logged in");
ToastAndroid.show('No user is currently logged in', ToastAndroid.SHORT);
return;
}
@@ -314,11 +309,10 @@ const Profile = () => {
// Clear stored credentials
await Keychain.resetGenericPassword();
dispatch(clearUser())
Alert.alert("Success", "You have been logged out");
ToastAndroid.show("You have been logged out", ToastAndroid.SHORT);
navigation.replace("Login");
} catch (error) {
console.error("Logout error:", error);
// Alert.alert("Error", "Failed to log out. Please try again.");
}
};
+4 -4
View File
@@ -2,14 +2,14 @@ import { useDispatch } from "react-redux";
import { BASE_URL } from "./ApiUrls";
import * as Keychain from "react-native-keychain";
import { setUserData } from "../redux/userSlice";
import { Alert } from "react-native";
import { Alert, ToastAndroid } from "react-native";
export const fetchUserProfile = async () => {
const dispatch = useDispatch();
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;
@@ -52,11 +52,11 @@ export const fetchUserProfile = async () => {
console.log("splash user data:", result.data);
} else {
Alert.alert("Error", "Failed to fetch user profile");
ToastAndroid.show(result.message || "Failed to fetch user profile", ToastAndroid.SHORT);
}
} catch (error) {
console.error("❌ Error fetching profile:", error);
// Alert.alert("Error", "Could not connect to server");
ToastAndroid.show("Could not connect to server", ToastAndroid.SHORT);
}
};