- {personalCapabilites.isSuccess &&
- personalCapabilites.data.map((cat) => (
-
- ))}
+ {userCapabilites.map((cat) => (
+
+ ))}
{moreCats.map((cat) => (
))}
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index 18faf0e3..dc5fb81e 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -1,10 +1,13 @@
+import { api } from '@src/trpc/server';
import NavMenu from './NavMenu';
// Keep in mind that in all routes we need pl-72 for the sidebar
-const Sidebar = () => {
+const Sidebar = async () => {
+ const userSidebarCapabilities =
+ await api.userMetadata.getUserSidebarCapabilities();
return (
-
+
);
};
diff --git a/src/utils/sidebarCapabilities.ts b/src/utils/sidebarCapabilities.ts
new file mode 100644
index 00000000..91f82df4
--- /dev/null
+++ b/src/utils/sidebarCapabilities.ts
@@ -0,0 +1,35 @@
+import { type personalCats } from '@src/constants/categories';
+import { getServerAuthSession } from '@src/server/auth';
+import { db } from '@src/server/db';
+import { admin } from '@src/server/db/schema/admin';
+import { userMetadataToClubs } from '@src/server/db/schema/users';
+import { and, eq, or } from 'drizzle-orm';
+import { cache } from 'react';
+
+export const getUserSidebarCapabilities = cache(async () => {
+ const session = await getServerAuthSession();
+ const capabilites: (typeof personalCats)[number][] = [];
+ if (!session) return capabilites;
+ if (
+ await db.query.userMetadataToClubs.findFirst({
+ where: and(
+ eq(userMetadataToClubs.userId, session.user.id),
+ or(
+ eq(userMetadataToClubs.memberType, 'Officer'),
+ eq(userMetadataToClubs.memberType, 'President'),
+ ),
+ ),
+ })
+ ) {
+ capabilites.push('Manage Clubs');
+ }
+ if (
+ (
+ await db.query.admin.findMany({
+ where: eq(admin.userId, session.user.id),
+ })
+ ).length === 1
+ )
+ capabilites.push('Admin');
+ return capabilites;
+});