forked from adrianhajdin/banking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecentTransactions.tsx
76 lines (66 loc) · 2.21 KB
/
RecentTransactions.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import Link from 'next/link'
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { BankTabItem } from './BankTabItem'
import BankInfo from './BankInfo'
import TransactionsTable from './TransactionsTable'
import { Pagination } from './Pagination'
const RecentTransactions = ({
accounts,
transactions = [],
appwriteItemId,
page = 1,
}: RecentTransactionsProps) => {
const rowsPerPage = 10;
const totalPages = Math.ceil(transactions.length / rowsPerPage);
const indexOfLastTransaction = page * rowsPerPage;
const indexOfFirstTransaction = indexOfLastTransaction - rowsPerPage;
const currentTransactions = transactions.slice(
indexOfFirstTransaction, indexOfLastTransaction
)
return (
<section className="recent-transactions">
<header className="flex items-center justify-between">
<h2 className="recent-transactions-label">Recent transactions</h2>
<Link
href={`/transaction-history/?id=${appwriteItemId}`}
className="view-all-btn"
>
View all
</Link>
</header>
<Tabs defaultValue={appwriteItemId} className="w-full">
<TabsList className="recent-transactions-tablist">
{accounts.map((account: Account) => (
<TabsTrigger key={account.id} value={account.appwriteItemId}>
<BankTabItem
key={account.id}
account={account}
appwriteItemId={appwriteItemId}
/>
</TabsTrigger>
))}
</TabsList>
{accounts.map((account: Account) => (
<TabsContent
value={account.appwriteItemId}
key={account.id}
className="space-y-4"
>
<BankInfo
account={account}
appwriteItemId={appwriteItemId}
type="full"
/>
<TransactionsTable transactions={currentTransactions} />
{totalPages > 1 && (
<div className="my-4 w-full">
<Pagination totalPages={totalPages} page={page} />
</div>
)}
</TabsContent>
))}
</Tabs>
</section>
)
}
export default RecentTransactions