Skip to content

Commit c4bd790

Browse files
committed
meri marzi
1 parent 0374b8b commit c4bd790

10 files changed

Lines changed: 207 additions & 694 deletions

File tree

src/app/layout.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ export default function RootLayout({
4444
disableTransitionOnChange
4545
>
4646
<Toaster position="top-right" toastOptions={{ id: "_toast" }} />
47-
<NavigationWrapper>
48-
{children}
49-
</NavigationWrapper>
47+
<NavigationWrapper>{children}</NavigationWrapper>
5048
</ThemeProvider>
5149
</Providers>
5250
</body>
5351
</html>
5452
);
55-
}
53+
}

src/app/users/page.tsx

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
"use client";
2-
import { DataTable } from "@/components/table/data-table";
32
import userCol from "@/components/columns/UserCol";
3+
import { DataTable } from "@/components/table/data-table";
44
// import { useEffect, useMemo, useState } from "react";
55
// import { user } from "@/store/interfaces";
66
// import useToast from "@/lib/toast";
7-
import { useQuery } from "@tanstack/react-query";
7+
import { downloadCSV } from "@/api/downloadCSV";
88
import { fetchUsers } from "@/api/fetchUsers";
9-
import {type User } from "@/data/schema";
10-
import { useState } from "react";
11-
import { useDebounce } from "use-debounce";
12-
import Image from "next/image";
139
import loading from "@/assets/images/loading.gif";
14-
import { UserModal } from "@/components/table/user-modal";
1510
import { Button } from "@/components/ui/button";
16-
import { downloadCSV } from "@/api/downloadCSV";
11+
import { type User } from "@/data/schema";
12+
import { useQuery } from "@tanstack/react-query";
13+
import Image from "next/image";
14+
import { useState } from "react";
15+
import { useDebounce } from "use-debounce";
1716

1817
export default function Users() {
1918
const [cursorHistory, setCursorHistory] = useState<string[]>([]);
2019
const [currentCursor, setCurrentCursor] = useState<string | undefined>(
2120
undefined,
2221
);
23-
const [pageLimit, setPageLimit] =useState<number>(10);
22+
const [pageLimit, setPageLimit] = useState<number>(10);
2423
const [theName, setTheName] = useState<string>("");
2524
// const queryClient = useQueryClient();
2625
const [nameDebounce] = useDebounce(theName, 1000);
@@ -31,7 +30,11 @@ export default function Users() {
3130
} = useQuery({
3231
queryKey: ["users", currentCursor, nameDebounce, pageLimit],
3332
queryFn: () =>
34-
fetchUsers({ limit: pageLimit, cursorId: currentCursor, name: nameDebounce }),
33+
fetchUsers({
34+
limit: pageLimit,
35+
cursorId: currentCursor,
36+
name: nameDebounce,
37+
}),
3538
placeholderData: (previousData) => previousData,
3639
// enabled: !!debouncedSearch,
3740
});
@@ -52,33 +55,28 @@ export default function Users() {
5255
}
5356
};
5457

58+
const onClick = async () => {
59+
try {
60+
const blob = await downloadCSV();
5561

62+
const url = window.URL.createObjectURL(blob.data as Blob);
63+
const a = document.createElement("a");
64+
a.href = url;
65+
a.download = "users.csv"; // Set the filename for the downloaded file
66+
document.body.appendChild(a);
5667

68+
a.click();
5769

58-
const onClick = async () => {
59-
try {
60-
const blob = await downloadCSV();
61-
62-
const url = window.URL.createObjectURL(blob.data as Blob);
63-
const a = document.createElement('a');
64-
a.href = url;
65-
a.download = 'users.csv'; // Set the filename for the downloaded file
66-
document.body.appendChild(a);
67-
68-
a.click();
69-
70-
window.URL.revokeObjectURL(url);
71-
document.body.removeChild(a);
72-
} catch (err) {
73-
console.error('Error downloading CSV:', err);
74-
alert('Failed to download CSV. Please try again.');
75-
}
76-
};
70+
window.URL.revokeObjectURL(url);
71+
document.body.removeChild(a);
72+
} catch (err) {
73+
console.error("Error downloading CSV:", err);
74+
alert("Failed to download CSV. Please try again.");
75+
}
76+
};
7777
return (
7878
<div className="p-4">
79-
<div className="mb-4"></div>
80-
{/* <DataTableUsers users={oosers} columns={userCol} /> */}
81-
<div className="mb-4 flex flex items-start">
79+
<div className="mb-4 flex items-start">
8280
<input
8381
className="bg-gray w-[50%] rounded-md border p-2 text-white"
8482
placeholder="Search"
@@ -88,9 +86,9 @@ export default function Users() {
8886
/>
8987
<Button onClick={onClick}>Download CSV </Button>
9088
</div>
91-
89+
9290
{isError && <div className="text-red-500">Error fetching team data</div>}
93-
91+
9492
{isLoading && (
9593
<div className="flex justify-center">
9694
<Image
@@ -102,17 +100,18 @@ export default function Users() {
102100
/>
103101
</div>
104102
)}
105-
106-
107-
<DataTable<User, string>
108-
setPageLimit={setPageLimit}
109-
pageLimit={pageLimit}
110-
columns={userCol}
111-
data={userList?.users ?? []}
112-
// data={oosers}
113-
handleNextPage={handleNextPage}
114-
handlePrevPage={handlePrevPage}
115-
/>
103+
104+
<div className="w-full overflow-hidden">
105+
<DataTable<User, string>
106+
setPageLimit={setPageLimit}
107+
pageLimit={pageLimit}
108+
columns={userCol}
109+
data={userList?.users ?? []}
110+
// data={oosers}
111+
handleNextPage={handleNextPage}
112+
handlePrevPage={handlePrevPage}
113+
/>
114+
</div>
116115
</div>
117116
);
118117
}

src/components/columns.tsx

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)