diff --git a/src/components/JoinedGroupCard.tsx b/src/components/JoinedGroupCard.tsx index b1048f7..a9f7fc6 100644 --- a/src/components/JoinedGroupCard.tsx +++ b/src/components/JoinedGroupCard.tsx @@ -2,7 +2,7 @@ import React, { FC } from 'react'; import { View, Text, StyleSheet, TouchableOpacity, ToastAndroid } from 'react-native'; import colors from './colors'; import { useNavigation } from '@react-navigation/native'; -import { BASE_URL } from '../utils/ApiUrls'; +import { BASE_URL, CONTRIBUTE } from '../utils/ApiUrls'; import { apiCall } from '../utils/ApiHelper'; interface JoinedGroup { @@ -65,13 +65,14 @@ export const JoinedGroupCard: FC = ({ item, onViewPress, h const statusStyle = getStatusStyle(item.status); const navigation = useNavigation(); const [loading, setLoading] = React.useState(false); + const [payable, setPayable] = React.useState(); const onPayPress = async () => { // Navigate to payment screen or handle payment logic // navigation.navigate('PaymentScreen', { groupId: item.id, amount: item.contributionAmount }); setLoading(true); try { - const res = await apiCall(`${BASE_URL}payments/contribute/${item?.id}?amount=${item?.contributionAmount}`, 'POST') as any; + const res = await apiCall(`${BASE_URL}payments/contribute/${item?.id}?amount=${payable?.totalPayable}`, 'POST') as any; console.log('payment res ', res) if (res.status === 200 || res.status === 201 || res.statusCode === 200) { ToastAndroid.show('Payment done!', ToastAndroid.SHORT); @@ -83,6 +84,18 @@ export const JoinedGroupCard: FC = ({ item, onViewPress, h setLoading(false); } }; + + const handleContribution = async () => { + try { + const res = await apiCall(`${CONTRIBUTE}${item.id}/calculate-contribution`, 'GET') as any; + setPayable(res.data); + } catch (error) { + console.log("Error in handleContribution: ", error); + } + }; + React.useEffect(() => { + handleContribution(); + }, []); return ( navigation.navigate("GroupDetails", { item, color: colors.black })}> {/* Header */} @@ -104,6 +117,12 @@ export const JoinedGroupCard: FC = ({ item, onViewPress, h {item.cycleType} + {payable?.effectiveLateFee && ( + <> + Total Payable: ₹{payable?.totalPayable.toLocaleString('en-IN')} + Effective Late Fee : ₹{payable?.effectiveLateFee.toLocaleString('en-IN')} + + )} {/* Footer with Dates & Buttons */} diff --git a/src/screens/home/UserProfileStatus.tsx b/src/screens/home/UserProfileStatus.tsx index 6b8b342..3efacc5 100644 --- a/src/screens/home/UserProfileStatus.tsx +++ b/src/screens/home/UserProfileStatus.tsx @@ -127,7 +127,8 @@ const UserProfileStatus: React.FC = ({ } setSubmitting(true); try { - const response = await apiCall(PAY_ALL_URL, 'POST',{ groupIds: selectedGroupIds, payAllDue: true }, undefined, "Payment failed. Try again.") as any; + const response = await apiCall(PAY_ALL_URL, 'POST',{ groupIds: selectedGroupIds }, undefined, "Payment failed. Try again.") as any; + console.log("-=-=-=-=-=-=-=-=-=-=-=",response) // const response = await fetch( diff --git a/src/screens/home/user-home/GroupDetails.tsx b/src/screens/home/user-home/GroupDetails.tsx index 11bf3da..e74d4bf 100644 --- a/src/screens/home/user-home/GroupDetails.tsx +++ b/src/screens/home/user-home/GroupDetails.tsx @@ -80,7 +80,7 @@ const GroupDetails = () => { const [cycleDashboardData, setCycleDashboardData] = useState(); const [selectedCycleNumber, setSelectedCycleNumber] = useState(null); const [cycleItems, setCycleItems] = useState([]); - const [selectedUser, setSelectedUser] = useState() as any + const [selectedUser, setSelectedUser] = useState() as string | any; const group = { @@ -96,10 +96,10 @@ const GroupDetails = () => { const getPaymentStatus = async () => { - const response = await apiCall(`${BASE_URL}payments/group/${group.id || route?.params?.groupId}/payment/paid`, 'GET') as { status: string; data?: { currentCycle: number, allPaid: boolean, selectedUser: any }; message?: string }; - console.log("paymentStatus", response.data?.selectedUser) + const response = await apiCall(`${BASE_URL}payments/group/${group.id || route?.params?.groupId}/payment/paid`, 'GET') as { status: string; data?: { currentCycle: number, allPaid: boolean, selectedUser: string }; message?: string }; + console.log("paymentStatus", response.data) if (response.status === 'success') { - setSelectedUser(response.data?.selectedUser); + setSelectedUser(response.data); } } @@ -237,7 +237,7 @@ const GroupDetails = () => { placeholder="Select a Cycle" /> )} - + {selectedCycleData && cycleDashboardData && ( )} @@ -263,7 +263,7 @@ const GroupDetails = () => { ))} - {cycleDashboardData?.status === 'ACTIVE' && !payable?.hasPaid && ( + {cycleDashboardData?.status === 'ACTIVE' || cycleDashboardData?.status === 'DELAY' && !payable?.hasPaid && ( setOpenModal(true)} style={styles.button}> Contribute @@ -423,7 +423,7 @@ const styles = StyleSheet.create({ }, floatingWinnerContainer: { position: 'absolute', - bottom: 80, + bottom: 80, alignSelf: 'center', backgroundColor: colors.pastelBlue, paddingHorizontal: 15,