diff options
| author | Md Saban <45597394+mdsaban@users.noreply.github.com> | 2024-06-30 03:44:44 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-29 23:14:44 +0100 |
| commit | e107f8b6c250759ab0f884b2fdd0283fae15cfe5 (patch) | |
| tree | d1b9123c4bd4ec6cd8df5f18b026250ffdfdf608 /apps/web/components/dashboard/admin/UserList.tsx | |
| parent | a63713032ff6b15b80348f724246e7abea40c8a4 (diff) | |
| download | karakeep-e107f8b6c250759ab0f884b2fdd0283fae15cfe5.tar.zst | |
ui: refactor admin settings page (#249)
* ui: refactor admin ui
* fix: pr comments
* chore: lint fix
* chore: refactor
* minor tweaks
---------
Co-authored-by: MohamedBassem <me@mbassem.com>
Diffstat (limited to 'apps/web/components/dashboard/admin/UserList.tsx')
| -rw-r--r-- | apps/web/components/dashboard/admin/UserList.tsx | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/apps/web/components/dashboard/admin/UserList.tsx b/apps/web/components/dashboard/admin/UserList.tsx new file mode 100644 index 00000000..024325a3 --- /dev/null +++ b/apps/web/components/dashboard/admin/UserList.tsx @@ -0,0 +1,75 @@ +"use client"; + +import { ActionButton } from "@/components/ui/action-button"; +import LoadingSpinner from "@/components/ui/spinner"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; +import { toast } from "@/components/ui/use-toast"; +import { api } from "@/lib/trpc"; +import { Trash } from "lucide-react"; +import { useSession } from "next-auth/react"; + +export default function UsersSection() { + const { data: session } = useSession(); + const invalidateUserList = api.useUtils().users.list.invalidate; + const { data: users } = api.users.list.useQuery(); + const { mutate: deleteUser, isPending: isDeletionPending } = + api.users.delete.useMutation({ + onSuccess: () => { + toast({ + description: "User deleted", + }); + invalidateUserList(); + }, + onError: (e) => { + toast({ + variant: "destructive", + description: `Something went wrong: ${e.message}`, + }); + }, + }); + + if (!users) { + return <LoadingSpinner />; + } + + return ( + <> + <div className="mb-2 text-xl font-medium">Users List</div> + + <Table> + <TableHeader className="bg-gray-200"> + <TableHead>Name</TableHead> + <TableHead>Email</TableHead> + <TableHead>Role</TableHead> + <TableHead>Action</TableHead> + </TableHeader> + <TableBody> + {users.users.map((u) => ( + <TableRow key={u.id}> + <TableCell className="py-1">{u.name}</TableCell> + <TableCell className="py-1">{u.email}</TableCell> + <TableCell className="py-1 capitalize">{u.role}</TableCell> + <TableCell className="py-1"> + <ActionButton + variant="outline" + onClick={() => deleteUser({ userId: u.id })} + loading={isDeletionPending} + disabled={session!.user.id == u.id} + > + <Trash size={16} color="red" /> + </ActionButton> + </TableCell> + </TableRow> + ))} + </TableBody> + </Table> + </> + ); +} |
