diff --git a/app/(protected)/projects/page-client.tsx b/app/(protected)/projects/page-client.tsx index 32364234..85aa8c36 100644 --- a/app/(protected)/projects/page-client.tsx +++ b/app/(protected)/projects/page-client.tsx @@ -90,9 +90,11 @@ export default function PageClient({ email }: { email: string }) { } function ProjectCard({ + key, project, teamId, }: { + key: number; project: Project; teamId: string; }) { @@ -111,7 +113,7 @@ function ProjectCard({ return
Loading...
; } return ( -
+
{!fetchProjecStats.isLoading && fetchProjecStats.data && diff --git a/app/(protected)/settings/members/page-client.tsx b/app/(protected)/settings/members/page-client.tsx index 85471691..351f0efd 100644 --- a/app/(protected)/settings/members/page-client.tsx +++ b/app/(protected)/settings/members/page-client.tsx @@ -76,6 +76,8 @@ export function InviteMember({ user }: { user: any }) { email: data.email, name: data.name, team_id: user.teamId, + role: "member", + status: "invited", }), }); @@ -215,11 +217,11 @@ function ManageRole({ member }: { member: any }) { defaultValue={type} >
- +

- Create projects and deploy AI models. + Standard-level permissions. Can view and edit projects.

@@ -254,21 +256,19 @@ function ManageRole({ member }: { member: any }) { function RemoveMemberDialog({ member }: { member: any }) { const [busy, setBusy] = useState(false); - const [type, setType] = useState(member.role); const [open, setOpen] = useState(false); const queryClient = useQueryClient(); const removeUser = async (member: any) => { try { setBusy(true); - await fetch(`/api/user?id=${member.id}`, { - method: "PUT", + await fetch("/api/user", { + method: "DELETE", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ id: member.id, - teamId: null, }), }); queryClient.invalidateQueries({ queryKey: ["getUsers"] }).then(() => { diff --git a/app/api/user/route.ts b/app/api/user/route.ts index 9ab6ce52..d7e95f34 100644 --- a/app/api/user/route.ts +++ b/app/api/user/route.ts @@ -52,7 +52,7 @@ export async function PUT(req: NextRequest) { } const data = await req.json(); - const { id, name, teamId, role } = data; + const { id, name, teamId, role, status } = data; if ("teamId" in data) { const user = await prisma.user.update({ @@ -82,6 +82,21 @@ export async function PUT(req: NextRequest) { }); } + if ("status" in data) { + console.log("updating status"); + const user = await prisma.user.update({ + where: { + id, + }, + data: { + status, + }, + }); + return NextResponse.json({ + data: user, + }); + } + const user = await prisma.user.update({ where: { id, @@ -96,7 +111,6 @@ export async function PUT(req: NextRequest) { }); } -// may not work / be necessary if users only get created through google auth export async function POST(req: NextRequest) { const session = await getServerSession(authOptions); if (!session || !session.user) { @@ -104,13 +118,15 @@ export async function POST(req: NextRequest) { } const data = await req.json(); - const { email, name, team_id } = data; + const { email, name, team_id, status, role } = data; const user = await prisma.user.create({ data: { email, name, teamId: team_id, + status, + role, }, }); @@ -118,3 +134,21 @@ export async function POST(req: NextRequest) { data: user, }); } + +export async function DELETE(req: NextRequest) { + const session = await getServerSession(authOptions); + if (!session || !session.user) { + redirect("/login"); + } + + const data = await req.json(); + const { id } = data; + + const user = await prisma.user.delete({ + where: { + id, + }, + }); + + return NextResponse.json({}); +} diff --git a/lib/auth/options.ts b/lib/auth/options.ts index 8d69afee..c5a15f98 100644 --- a/lib/auth/options.ts +++ b/lib/auth/options.ts @@ -40,6 +40,8 @@ export const authOptions: NextAuthOptions = { email: process.env.ADMIN_EMAIL, name: "Admin", image: null, + role: "owner", + status: "active", }, }); } diff --git a/lib/middleware/app.ts b/lib/middleware/app.ts index 848e9d27..74b0112c 100644 --- a/lib/middleware/app.ts +++ b/lib/middleware/app.ts @@ -16,7 +16,7 @@ export default async function AppMiddleware(req: NextRequest) { email?: string; user?: User; }; - if (session && path === "/login") { + if (session && (path === "/login" || path === "/signup")) { const userReq = await fetch( `${process.env.NEXT_PUBLIC_HOST}/api/user?email=${session?.email}`, { @@ -28,18 +28,22 @@ export default async function AppMiddleware(req: NextRequest) { ); const response = await userReq.json(); const user = response.data; - if (user && !user.teamId) { - // create a team - await fetch(`${process.env.NEXT_PUBLIC_HOST}/api/team`, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - name: "My Team", - userId: user.id, - }), - }); + if (user) { + if (!user.teamId) { + // create a team + await fetch(`${process.env.NEXT_PUBLIC_HOST}/api/team`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: "My Team", + userId: user.id, + role: "owner", + status: "active", + }), + }); + } } // if there's a session diff --git a/prisma/migrations/20240401042126_user_schema_fix/migration.sql b/prisma/migrations/20240401042126_user_schema_fix/migration.sql new file mode 100644 index 00000000..7b21d326 --- /dev/null +++ b/prisma/migrations/20240401042126_user_schema_fix/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "User" ALTER COLUMN "role" SET DEFAULT 'owner'; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 2f1cef1c..6ec8461e 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -53,7 +53,7 @@ model User { teamId String? Team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade) status String? @default("active") // invited, active - role Role? @default(member) + role Role? @default(owner) createdAt DateTime @default(now()) Evaluation Evaluation[] }