diff --git a/apps/nextjs/src/app/(home)/page.tsx b/apps/nextjs/src/app/(home)/page.tsx
index dab8b13..deb9d09 100644
--- a/apps/nextjs/src/app/(home)/page.tsx
+++ b/apps/nextjs/src/app/(home)/page.tsx
@@ -1,102 +1,45 @@
-import React from "react";
-import Image from "next/image";
-import Link from "next/link";
+import { Suspense } from "react";
+import dynamic from "next/dynamic";
-import { Card, CardContent, CardFooter, CardHeader } from "@amaxa/ui/card";
-
-import { getUserProjects } from "~/components/navbar/switcher";
import { checkAuth } from "~/lib/auth";
-import { CreateProject } from "./_components/create-project-dialog";
-import { findAllProjects } from "./_queries";
+import AllProjects from "./_components/all-projects";
+import UserProjects from "./_components/user-projects";
+
+const CreateProject = dynamic(
+ () =>
+ import("./_components/create-project-dialog").then(
+ (mod) => mod.CreateProject,
+ ),
+ {
+ loading: () =>
Loading...
,
+ },
+);
export default async function Page() {
const session = await checkAuth();
- const [usersProjects, allProjects] = await Promise.all([
- getUserProjects(session.user.id),
- findAllProjects(),
- ]);
return (
-
-
-
-
-
Your Project
- {session.user.role === "Admin" ? : null}
-
-
- {session.user.status == "Pending" ? (
-
-
- Your account is pending approval, please wait for the admin
- to approve your account
-
-
- ) : session.user.status == "Unverified" ? (
-
-
- Your account is unverified, please wait till we verify your
- account to access the platform
-
-
- ) : (
-
- {usersProjects.map((project) => {
- return (
-
-
-
-
-
-
- {project.name}
-
-
-
- );
- })}
-
- )}
-
-
-
-
Explore Projects
-
- {allProjects.map((project) => {
- return (
-
-
-
-
-
-
- {project.name}
-
-
-
- );
- })}
-
+
+
+
+
Your Projects
+ {session.user.role === "Admin" && }
+
Loading your projects... }>
+
+
+
+
+
Explore Projects
+ Loading all projects... }>
+
+
);
}
-
-export const dynamic = "force-dynamic";
diff --git a/apps/nextjs/src/app/_components/flow-provider.tsx b/apps/nextjs/src/app/_components/flow-provider.tsx
index f52cb69..064c343 100644
--- a/apps/nextjs/src/app/_components/flow-provider.tsx
+++ b/apps/nextjs/src/app/_components/flow-provider.tsx
@@ -1,4 +1,5 @@
"use client";
+import { SessionProvider } from 'next-auth/react'
import React from "react";
import { ReactFlowProvider } from "@xyflow/react";
@@ -11,7 +12,12 @@ import "reactflow/dist/style.css";
function FlowProvider({ children }: { children: React.ReactNode }) {
return (
- {children}
+
+
+ {children}
+
+
+
);
}
diff --git a/apps/nextjs/src/components/layout-tabs.tsx b/apps/nextjs/src/components/layout-tabs.tsx
index 954f0bb..6982284 100644
--- a/apps/nextjs/src/components/layout-tabs.tsx
+++ b/apps/nextjs/src/components/layout-tabs.tsx
@@ -5,21 +5,32 @@ import Link from "next/link";
import { usePathname } from "next/navigation";
import * as TabsPrimitive from "@radix-ui/react-tabs";
import { motion } from "framer-motion";
+import { useSession } from "next-auth/react";
import { cn } from "@amaxa/ui";
-interface TabLink {
- href: string;
- label: string;
-}
-
interface VercelTabsProps {
- links?: TabLink[];
className?: string;
}
-export function AppNav({ links, className }: VercelTabsProps) {
+export function AppNav({ className }: VercelTabsProps) {
const pathname = usePathname();
+ const session = useSession();
+
+ const links = [
+ { href: "/", label: "Projects" },
+ { href: "/events", label: "Events" },
+ { href: "/guides/action-guides", label: "Guides" },
+ session?.data?.user.role === "Admin"
+ ? {
+ href: "/admin",
+ label: "Admin",
+ }
+ : {
+ href: "/",
+ label: "",
+ },
+ ];
if (!links || links.length === 0) {
return null;
diff --git a/apps/nextjs/src/components/navbar/switcher/index.tsx b/apps/nextjs/src/components/navbar/switcher/index.tsx
index 99f3c2a..872c49f 100644
--- a/apps/nextjs/src/components/navbar/switcher/index.tsx
+++ b/apps/nextjs/src/components/navbar/switcher/index.tsx
@@ -9,8 +9,8 @@ import { next_cache } from "~/lib/cache";
import { TeamSwitcherClient } from "./team-switcher-client";
export const getUserProjects = next_cache(
- async (userId: string) =>
- await db
+ (userId: string) =>
+ db
.select({
id: Projects.id,
name: Projects.name,
@@ -20,14 +20,10 @@ export const getUserProjects = next_cache(
.where(eq(project_tracker.userId, userId))
.innerJoin(Projects, eq(Projects.id, project_tracker.projectId)),
["getUserProjects"],
- {
- revalidate: 60 * 60 * 10, // 10 hours,
- },
);
export const TeamSwitcher = async () => {
const session = await checkAuth();
-
const projects = await getUserProjects(session.user.id);
return
;
diff --git a/apps/nextjs/src/lib/cache.ts b/apps/nextjs/src/lib/cache.ts
index 58ca126..6f35881 100644
--- a/apps/nextjs/src/lib/cache.ts
+++ b/apps/nextjs/src/lib/cache.ts
@@ -1,9 +1,8 @@
-import { cache } from "react";
import { unstable_cache as next_unstable_cache } from "next/cache";
// next_unstable_cache doesn't handle deduplication, so we wrap it in React's cache
export const next_cache =
(
callback: (...args: Inputs) => Promise,
key: string[],
- options: { revalidate: number },
-) => cache(next_unstable_cache(callback, key, options));
+ options?: { revalidate: number | false },
+) => next_unstable_cache(callback, key, options);
diff --git a/packages/api/src/router/projects.ts b/packages/api/src/router/projects.ts
index 52bc024..c8e8d5b 100644
--- a/packages/api/src/router/projects.ts
+++ b/packages/api/src/router/projects.ts
@@ -1,5 +1,6 @@
// import { and, ilike } from "@amaxa/db";
// import { Projects } from "@amaxa/db/schema";
+import { revalidatePath } from "next/cache";
import { TRPCError } from "@trpc/server";
import { z } from "zod";
@@ -27,6 +28,7 @@ export const projectsRouter = createTRPCRouter({
code: "UNAUTHORIZED",
message: "You do not have permissions to create a project",
});
+ revalidatePath("/");
await ctx.db.insert(Projects).values(input);
}),
forDashboard: protectedProcedure