Skip to content

Commit fb85e4b

Browse files
authored
feat:refactor teams table with tanstackTable (#167)
1 parent c9fde4e commit fb85e4b

22 files changed

+806
-791
lines changed

amplify/data/resource.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const schema = a
9797
teamRooms: a.hasMany("TeamRoom", "teamId"),
9898
})
9999
.authorization((allow) => [
100-
allow.group("Admin").to(["read", "update", "create"]),
100+
allow.group("Admin").to(["read", "update", "create", "delete"]),
101101
allow.authenticated().to(["read"]),
102102
]),
103103
Score: a

package-lock.json

+57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
"@emotion/styled": "^11.13.0",
2626
"@react-email/components": "^0.0.19",
2727
"@react-email/render": "^0.0.15",
28+
"@tanstack/match-sorter-utils": "^8.19.4",
2829
"@tanstack/query-async-storage-persister": "^5.36.0",
2930
"@tanstack/react-query": "^5.32.1",
3031
"@tanstack/react-query-devtools": "^5.32.0",
3132
"@tanstack/react-query-persist-client": "^5.36.0",
33+
"@tanstack/react-table": "^8.20.5",
3234
"@typescript-eslint/parser": "^7.11.0",
3335
"@yudiel/react-qr-scanner": "^2.0.4",
3436
"aws-amplify": "^6.0.18",
@@ -82,5 +84,6 @@
8284
"hooks": {
8385
"pre-commit": "lint-staged"
8486
}
85-
}
87+
},
88+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
8689
}

src/app/admin/layout.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export const metadata: Metadata = {
1818

1919
function AdminLayout({ children }: { children: React.ReactNode }) {
2020
return (
21-
<div className="flex min-h-screen w-full flex-1">
21+
<div className="flex w-full flex-1 ">
2222
<SideNavBar />
23-
<div className="flex size-full flex-1 flex-col">
23+
<div className="flex w-full flex-1 flex-col ">
2424
<TopNavBar />
25-
<main className="grow">{children}</main>
25+
{children}
2626
</div>
2727
</div>
2828
);

src/app/admin/teams/TeamsTablePage.tsx

-170
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { useState } from "react";
2+
3+
import type { Row, TableMeta } from "@tanstack/react-table";
4+
5+
import type { Team } from "../tanstackTableSetup";
6+
import Modal from "./Modal";
7+
8+
export default function DeleteButton({
9+
row,
10+
meta,
11+
}: {
12+
row: Row<Team>;
13+
meta?: TableMeta<Team>;
14+
}) {
15+
const [showPopup, setShowPopup] = useState(false);
16+
17+
return (
18+
<>
19+
<button className=" text-dark-pink" onClick={() => setShowPopup(true)}>
20+
Delete
21+
</button>
22+
{showPopup && (
23+
<Modal onClose={() => setShowPopup(false)}>
24+
<h1 className="text-3xl font-semibold">
25+
{row.original.teamName}
26+
{"'s"} Team - #{row.original.teamID}
27+
</h1>
28+
<div className="flex flex-col gap-2 bg-light-grey p-2">
29+
<h1 className="text-xl font-bold">
30+
Are you sure you want to delete this record?
31+
</h1>
32+
<h2 className="mb-2">
33+
This record will be deleted{" "}
34+
<i>
35+
<b>permanently</b>
36+
</i>
37+
. You cannot undo this action.
38+
</h2>
39+
<div className="flex justify-end gap-2">
40+
<button
41+
className=" rounded-md border border-black p-2 px-6 hover:opacity-40"
42+
onClick={() => setShowPopup(false)}
43+
>
44+
Cancel
45+
</button>
46+
<button
47+
className="rounded-md border bg-dark-pink p-2 px-6 text-white transition-all hover:bg-pastel-pink"
48+
onClick={() => {
49+
meta?.deleteTeam(row.original, row.index);
50+
setShowPopup(false);
51+
}}
52+
>
53+
Delete
54+
</button>
55+
</div>
56+
</div>
57+
</Modal>
58+
)}
59+
</>
60+
);
61+
}

0 commit comments

Comments
 (0)