Skip to content

Commit 3b7890c

Browse files
committed
Add pagination in InApp wallet users table and update tabs (#4325)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview The focus of this PR is to implement pagination functionality for displaying a specific number of items per page in the Users component of the embedded wallets feature. ### Detailed summary - Added pagination logic to display a subset of wallets per page based on active page - Implemented pagination buttons for navigating through multiple pages - Updated the Users component to show items based on pagination - Added state management for active page selection - Updated URL search parameters based on selected tab in the EmbeddedWallets component > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 3d60da3 commit 3b7890c

File tree

2 files changed

+73
-21
lines changed

2 files changed

+73
-21
lines changed

apps/dashboard/src/components/embedded-wallets/Users/index.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PaginationButtons } from "@/components/pagination-buttons";
12
import type { EmbeddedWalletUser } from "@3rdweb-sdk/react/hooks/useEmbeddedWallets";
23
import { Flex, Switch } from "@chakra-ui/react";
34
import { createColumnHelper } from "@tanstack/react-table";
@@ -104,6 +105,19 @@ export const Users: React.FC<UsersProps> = ({
104105
tempLink.click();
105106
}, [theWalletsWeWant]);
106107

108+
const [activePage, setActivePage] = useState(1);
109+
const itemsPerPage = 20;
110+
const totalPages =
111+
theWalletsWeWant.length <= itemsPerPage
112+
? 1
113+
: Math.ceil(theWalletsWeWant.length / itemsPerPage);
114+
115+
const itemsToShow = useMemo(() => {
116+
const startIndex = (activePage - 1) * itemsPerPage;
117+
const endIndex = startIndex + itemsPerPage;
118+
return theWalletsWeWant.slice(startIndex, endIndex);
119+
}, [activePage, theWalletsWeWant]);
120+
107121
return (
108122
<Flex flexDir="column" gap={10}>
109123
<Flex flexDir="column" gap={6}>
@@ -129,11 +143,19 @@ export const Users: React.FC<UsersProps> = ({
129143

130144
<TWTable
131145
title="active in-app wallets"
132-
data={theWalletsWeWant}
146+
data={itemsToShow}
133147
columns={columns}
134148
isLoading={isLoading}
135149
isFetched={isFetched}
136150
/>
151+
152+
{totalPages > 1 && (
153+
<PaginationButtons
154+
activePage={activePage}
155+
onPageClick={setActivePage}
156+
totalPages={totalPages}
157+
/>
158+
)}
137159
</Flex>
138160

139161
<Analytics trackingCategory={trackingCategory} />
Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { TabButtons } from "@/components/ui/tabs";
12
import type { ApiKey } from "@3rdweb-sdk/react/hooks/useApi";
23
import type { EmbeddedWalletUser } from "@3rdweb-sdk/react/hooks/useEmbeddedWallets";
3-
import { Tab, TabList, TabPanel, TabPanels, Tabs } from "@chakra-ui/react";
4+
import { useState } from "react";
45
import { Configure } from "./Configure";
56
import { Users } from "./Users";
67

@@ -21,26 +22,55 @@ export const EmbeddedWallets: React.FC<EmbeddedWalletsProps> = ({
2122
trackingCategory,
2223
defaultTabIndex,
2324
}) => {
25+
const [selectedTab, setSelectedTab] = useState<"users" | "config">(
26+
defaultTabIndex === 0 ? "users" : "config",
27+
);
28+
29+
function updateSearchParams(value: string) {
30+
const url = new URL(window.location.href);
31+
url.searchParams.set("tab", value);
32+
window.history.pushState(null, "", url.toString());
33+
}
34+
2435
return (
25-
<Tabs defaultIndex={defaultTabIndex || 0}>
26-
<TabList px={0} borderBottomColor="borderColor" borderBottomWidth="1px">
27-
<Tab>Users</Tab>
28-
<Tab>Configuration</Tab>
29-
</TabList>
36+
<div>
37+
<TabButtons
38+
tabs={[
39+
{
40+
name: "Users",
41+
onClick: () => {
42+
setSelectedTab("users");
43+
updateSearchParams("0");
44+
},
45+
isActive: selectedTab === "users",
46+
isEnabled: true,
47+
},
48+
{
49+
name: "Configuration",
50+
onClick: () => {
51+
setSelectedTab("config");
52+
updateSearchParams("1");
53+
},
54+
isActive: selectedTab === "config",
55+
isEnabled: true,
56+
},
57+
]}
58+
/>
59+
60+
<div className="h-6" />
61+
62+
{selectedTab === "users" && (
63+
<Users
64+
wallets={wallets}
65+
isLoading={isLoading}
66+
isFetched={isFetched}
67+
trackingCategory={trackingCategory}
68+
/>
69+
)}
3070

31-
<TabPanels pt={6}>
32-
<TabPanel px={0}>
33-
<Users
34-
wallets={wallets}
35-
isLoading={isLoading}
36-
isFetched={isFetched}
37-
trackingCategory={trackingCategory}
38-
/>
39-
</TabPanel>
40-
<TabPanel px={0}>
41-
<Configure apiKey={apiKey} trackingCategory={trackingCategory} />
42-
</TabPanel>
43-
</TabPanels>
44-
</Tabs>
71+
{selectedTab === "config" && (
72+
<Configure apiKey={apiKey} trackingCategory={trackingCategory} />
73+
)}
74+
</div>
4575
);
4676
};

0 commit comments

Comments
 (0)