diff --git a/src/components/layout/admin/main-admin.layout.tsx b/src/components/layout/admin/main-admin.layout.tsx index 6895b9a25..ded91e20d 100644 --- a/src/components/layout/admin/main-admin.layout.tsx +++ b/src/components/layout/admin/main-admin.layout.tsx @@ -14,6 +14,7 @@ import { TextInput, ThemeIcon, UnstyledButton, + useMantineTheme, } from '@mantine/core'; import { IconAlertTriangle, @@ -47,11 +48,12 @@ interface MainLayoutProps { export const MainLayout = ({ children }: MainLayoutProps) => { const { t } = useTranslation(); const { attributes } = usePackageAttributesStore(); + const theme = useMantineTheme(); return ( { - return ( - - Manage users - - ) -} + const { isLoading, data, fetchNextPage, fetchPreviousPage } = api.user.getAll.useInfiniteQuery( + { + limit: 10, + }, + { + getNextPageParam: (lastPage) => lastPage.nextCursor, + } + ); -export default ManageUsersPage; \ No newline at end of file + const [activePage, _] = useState(1); + + return ( + + + Users • Homarr + + Manage users + + + + + + + + + + {data && ( + <> + + + + + + + + {data.pages[0].users.map((user) => ( + + + + ))} + +
User
+ + + + {user.name} + + + + + + + +
+ + + )} +
+ ); +}; + +export default ManageUsersPage; diff --git a/src/pages/manage/users/invites.tsx b/src/pages/manage/users/invites.tsx index ceda212c4..8c0762a23 100644 --- a/src/pages/manage/users/invites.tsx +++ b/src/pages/manage/users/invites.tsx @@ -1,12 +1,16 @@ -import { Title } from "@mantine/core"; -import { MainLayout } from "~/components/layout/admin/main-admin.layout"; +import { Title } from '@mantine/core'; +import { Head } from 'next/document'; +import { MainLayout } from '~/components/layout/admin/main-admin.layout'; const ManageUserInvitesPage = () => { - return ( - - Manage user invites - - ) -} + return ( + + + User invites • Homarr + + Manage user invites + + ); +}; -export default ManageUserInvitesPage; \ No newline at end of file +export default ManageUserInvitesPage; diff --git a/src/server/api/routers/user.ts b/src/server/api/routers/user.ts index d5b5e5d09..a6d417bcb 100644 --- a/src/server/api/routers/user.ts +++ b/src/server/api/routers/user.ts @@ -110,7 +110,7 @@ export const userRouter = createTRPCRouter({ }, }); }), - getWithSettings: protectedProcedure.query(async ({ ctx }) => { + getWithSettings: protectedProcedure.query(async ({ ctx, input }) => { const user = await ctx.prisma.user.findUnique({ where: { id: ctx.session?.user?.id, @@ -133,4 +133,36 @@ export const userRouter = createTRPCRouter({ settings: user.settings, }; }), + + getAll: publicProcedure + .input( + z.object({ + limit: z.number().min(1).max(100).nullish(), + cursor: z.number().nullish(), + }) + ) + .query(async ({ ctx, input }) => { + const limit = input.limit ?? 50; + const cursor = input.cursor; + const users = await ctx.prisma.user.findMany({ + take: limit + 1, // get an extra item at the end which we'll use as next cursor + cursor: cursor ? { myCursor: cursor } : undefined, + }); + + let nextCursor: typeof cursor | undefined = undefined; + if (users.length > limit) { + const nextItem = users.pop(); + nextCursor = nextItem!.myCursor; + } + + return { + users: users.map((user) => ({ + id: user.id, + name: user.name, + email: user.email, + emailVerified: user.emailVerified + })), + nextCursor, + }; + }), });