diff --git a/app/features/screens/bankDetailsScreen/bankDetailsScreen.tsx b/app/features/screens/bankDetailsScreen/bankDetailsScreen.tsx index 0008c15..c7909c6 100644 --- a/app/features/screens/bankDetailsScreen/bankDetailsScreen.tsx +++ b/app/features/screens/bankDetailsScreen/bankDetailsScreen.tsx @@ -36,23 +36,33 @@ import { useAppDispatch, useAppSelector } from '@store'; // updatedAt: '2026-07-21T07:29:42.582Z', // }, // ]; -export const BankDetailsScreen: React.FC = () => { +export const BankDetailsScreen = () => { const { colors } = useAppTheme(); const styles = getStyles(colors); const navigation = useNavigation>(); const dispatch = useAppDispatch(); - const { bankAccounts, isLoading, error } = useAppSelector( - state => state.addBankDetails, - ); + // Replace this state with Redux selector when wiring real API // const [accounts] = useState(bankAccounts); const [refreshing, setRefreshing] = useState(false); + // console.log('-------'); useEffect(() => { dispatch(fetchBankAccounts()); - }, []); + // console.log('object') + }, [dispatch]); + + const { bankAccounts, isLoading, error } = useAppSelector( + state => state.addBankDetails, + ); + + const accountsList = Array.isArray(bankAccounts) + ? bankAccounts + : (bankAccounts as any)?.data || (bankAccounts as any)?.bankAccounts || []; + + // console.log(accountsList); const handleRefresh = () => { setRefreshing(true); @@ -100,7 +110,7 @@ export const BankDetailsScreen: React.FC = () => { {/* Empty State */} - {bankAccounts?.length === 0 ? ( + {!accountsList || accountsList.length === 0 ? ( @@ -118,22 +128,22 @@ export const BankDetailsScreen: React.FC = () => { Your Accounts - {bankAccounts?.length} + {accountsList.length} {/* Account Cards */} - {bankAccounts?.map(account => ( + {accountsList.map((account: any) => ( {/* Top color strip for default account */} - {account.isDefault && } + {account?.isDefault && } {/* Card Header Row */} @@ -144,36 +154,36 @@ export const BankDetailsScreen: React.FC = () => { - {account.bankName} + {account?.bankName} - {account.accountHolderName} + {account?.accountHolderName} {/* Status Badges */} - {account.isDefault && ( + {account?.isDefault && ( DEFAULT )} - {account.isVerified ? 'VERIFIED' : 'PENDING'} + {account?.isVerified ? 'VERIFIED' : 'PENDING'} @@ -186,22 +196,22 @@ export const BankDetailsScreen: React.FC = () => { Account Number - {maskAccountNumber(account.accountNumber)} + {maskAccountNumber(account?.accountNumber)} IFSC Code - {account.ifscCode || '—'} + {account?.ifscCode || '—'} - {account.branchName ? ( + {account?.branchName ? ( Branch - {account.branchName} + {account?.branchName} ) : null} @@ -209,7 +219,7 @@ export const BankDetailsScreen: React.FC = () => { Owner Type - {account.ownerType || '—'} + {account?.ownerType || '—'} @@ -219,9 +229,9 @@ export const BankDetailsScreen: React.FC = () => { {/* Card Footer */} - Added {formatDate(account.createdAt)} + Added {formatDate(account?.createdAt)} - {account.isVerified && ( + {account?.isVerified && ( )} diff --git a/app/features/screens/earningsScreen/earningsScreen.tsx b/app/features/screens/earningsScreen/earningsScreen.tsx index bff5deb..05445d0 100644 --- a/app/features/screens/earningsScreen/earningsScreen.tsx +++ b/app/features/screens/earningsScreen/earningsScreen.tsx @@ -1,77 +1,95 @@ -import React from 'react'; +import React, { useCallback } from 'react'; import { View, Text, ScrollView } from 'react-native'; import { useAppTheme } from '@theme'; import { WalletIcon } from '@icons'; -import { useAppSelector } from '@store'; -import { formatCurrency } from '@utils/formatters'; +import { useAppDispatch, useAppSelector } from '@store'; +import { formatCurrency, formatDate } from '@utils'; import { getStyles } from './earningsScreen.styles'; +import { getCompletedDeliveries } from '../jobsScreen'; +import { useFocusEffect } from '@react-navigation/native'; export const EarningsScreen: React.FC = () => { const { colors } = useAppTheme(); const styles = getStyles(colors); - const { todayEarnings, completedCount, onlineMinutes } = useAppSelector( - state => state.earnings, - ); - const { jobHistory } = useAppSelector(state => state.job); + // const { todayEarnings, completedCount, onlineMinutes } = useAppSelector( + // state => state.earnings, + // ); + + const dispatch = useAppDispatch(); + // const { jobHistory } = useAppSelector(state => state.job); + const { completedDeliveries } = useAppSelector(state => state.deliveries) + // console.log('completedDeliveries', completedDeliveries) // Default mock jobs history if none completed yet - const defaultHistory: { - orderId: string; - time: string; - amount: string; - paymentType: 'online' | 'cod'; - }[] = [ - { - orderId: '#ORD125487', - time: '12:35 PM', - amount: '78.0', - paymentType: 'online', - }, - { - orderId: '#ORD125422', - time: '11:15 AM', - amount: '65.0', - paymentType: 'cod', - }, - { - orderId: '#ORD125389', - time: '09:40 AM', - amount: '120.0', - paymentType: 'online', - }, - { - orderId: '#ORD125310', - time: 'Yesterday', - amount: '85.0', - paymentType: 'online', - }, - ]; + // const defaultHistory: { + // orderId: string; + // time: string; + // amount: string; + // paymentType: 'online' | 'cod'; + // }[] = [ + // { + // orderId: '#ORD125487', + // time: '12:35 PM', + // amount: '78.0', + // paymentType: 'online', + // }, + // { + // orderId: '#ORD125422', + // time: '11:15 AM', + // amount: '65.0', + // paymentType: 'cod', + // }, + // { + // orderId: '#ORD125389', + // time: '09:40 AM', + // amount: '120.0', + // paymentType: 'online', + // }, + // { + // orderId: '#ORD125310', + // time: 'Yesterday', + // amount: '85.0', + // paymentType: 'online', + // }, + // ]; - const displayHistory = - jobHistory.length > 0 - ? jobHistory - .map(job => ({ - orderId: job.orderId, - time: job.deliveredAt - ? new Date(job.deliveredAt).toLocaleTimeString([], { - hour: '2-digit', - minute: '2-digit', - }) - : 'Delivered', - amount: job.amount, - paymentType: job.paymentType, - })) - .concat(defaultHistory) - : defaultHistory; + const totalAmount = completedDeliveries?.reduce((acc, item) => { + return acc + Number(item?.order?.deliveryFee); + }, 0); - const formatOnlineTime = (mins: number) => { - const hours = Math.floor(mins / 60); - const remainingMins = mins % 60; - return `${hours}h ${ - remainingMins < 10 ? `0${remainingMins}` : remainingMins - }m`; - }; + // console.log('totalAmount', totalAmount) + + useFocusEffect(useCallback(() => { + dispatch(getCompletedDeliveries()); + }, [dispatch])) + // const deliveryList = Array.isArray(completedDeliveries) + // ? completedDeliveries + // : (completedDeliveries as any)?.data || (completedDeliveries as any)?.bankAccounts || []; + + // const displayHistory = + // deliveryList?.length > 0 + // ? deliveryList + // .map((delivery: any) => ({ + // orderId: delivery.orderId, + // time: delivery.deliveredAt + // ? new Date(delivery.deliveredAt).toLocaleTimeString([], { + // hour: '2-digit', + // minute: '2-digit', + // }) + // : 'Delivered', + // amount: delivery?.totalAmount, + // paymentType: delivery?.paymentMethod, + // })) + // .concat(defaultHistory) + // : defaultHistory; + + // const formatOnlineTime = (mins: number) => { + // const hours = Math.floor(mins / 60); + // const remainingMins = mins % 60; + // return `${hours}h ${remainingMins < 10 ? `0${remainingMins}` : remainingMins + // }m`; + // }; return ( @@ -85,18 +103,18 @@ export const EarningsScreen: React.FC = () => { {/* Total Earnings Card */} - Today's Earnings + Total Earnings - {formatCurrency(todayEarnings)} + {formatCurrency(totalAmount || 0)} - + {/* - {completedCount} + {completedDeliveries?.length} Deliveries - + */} - + {/* @@ -110,15 +128,15 @@ export const EarningsScreen: React.FC = () => { ₹78.50 Avg / Order - - + */} + {/* */} {/* Recent Deliveries List */} Recent Deliveries - {displayHistory.map((item, index) => ( + {completedDeliveries?.map((item, index) => ( @@ -126,17 +144,17 @@ export const EarningsScreen: React.FC = () => { {item.orderId} - {item.time} + {formatDate(item?.deliveredAt || '')} - +{formatCurrency(Number(item.amount))} + +{formatCurrency(Number(item?.order?.deliveryFee))} - {item.paymentType.toUpperCase()} + {/* {item?.order?.pa.toUpperCase()} */}