From 62ec222e54c4c8afe1b0b489b8200b7163a9c774 Mon Sep 17 00:00:00 2001 From: Sid-80 Date: Fri, 28 Jun 2024 19:36:36 +0530 Subject: [PATCH] feat: api for team members --- src/app/api/teams/get/route.ts | 16 ----------- src/app/api/teams/members/[id]/route.ts | 28 +++++++++++++++++++ src/app/dashboard/_components/SideNav.tsx | 1 + .../_components/SideNavBottomSection.tsx | 27 +++++++++++++++--- .../profile/_components/TeamList.tsx | 1 - src/app/dashboard/team/page.tsx | 6 ++++ src/components/shared/MemberCarousel.tsx | 7 +++++ 7 files changed, 65 insertions(+), 21 deletions(-) delete mode 100644 src/app/api/teams/get/route.ts create mode 100644 src/app/api/teams/members/[id]/route.ts create mode 100644 src/app/dashboard/team/page.tsx create mode 100644 src/components/shared/MemberCarousel.tsx diff --git a/src/app/api/teams/get/route.ts b/src/app/api/teams/get/route.ts deleted file mode 100644 index e5d5b23..0000000 --- a/src/app/api/teams/get/route.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { NextResponse } from "next/server"; -import { api } from "../../../../../convex/_generated/api"; -import { ConvexHttpClient } from "convex/browser"; - -export const GET = async () => { - try { - - const client = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!); - - const teamInfo = await client.query(api.teams.getAllTeam); - - return NextResponse.json(teamInfo); - } catch (err) { - console.log(err) - } -}; diff --git a/src/app/api/teams/members/[id]/route.ts b/src/app/api/teams/members/[id]/route.ts new file mode 100644 index 0000000..ccd9cd0 --- /dev/null +++ b/src/app/api/teams/members/[id]/route.ts @@ -0,0 +1,28 @@ +import { ConvexHttpClient } from "convex/browser"; +import { api } from "../../../../../../convex/_generated/api"; +import { Id } from "../../../../../../convex/_generated/dataModel"; + +export async function GET( + request: Request, + { params }: { params: { id: string } } +) { + const {id} = params; + + + if (!id) return new Response('Parameters missing!!',{status: 401}); + + const client = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!); + + const teamInfo = await client.query(api.teams.getTeamById,{_id:id as Id<"teams">}); + + const memberDataPromises = teamInfo.teamMembers.map((mem:string) => + client.query(api.user.getUser, { email: mem }) + ); + + const results = await Promise.all(memberDataPromises); + + const memberData = results.flatMap((result) => result || []); + + return Response.json({memberData}); + +} diff --git a/src/app/dashboard/_components/SideNav.tsx b/src/app/dashboard/_components/SideNav.tsx index 17e1083..4f392d9 100644 --- a/src/app/dashboard/_components/SideNav.tsx +++ b/src/app/dashboard/_components/SideNav.tsx @@ -111,6 +111,7 @@ function SideNav() {
([]); const [fileInput, setFileInput] = useState(""); @@ -115,6 +123,17 @@ function SideNavBottomSection({ onFileCreate, totalFiles, activeTeam }: any) { ))} + {user?.email === activeTeam?.createdBy && +

+ + Team Settings +

+ } + {/* Add New File Button */} diff --git a/src/app/dashboard/profile/_components/TeamList.tsx b/src/app/dashboard/profile/_components/TeamList.tsx index 204db08..356611a 100644 --- a/src/app/dashboard/profile/_components/TeamList.tsx +++ b/src/app/dashboard/profile/_components/TeamList.tsx @@ -15,7 +15,6 @@ import { import moment from "moment"; import { useConvex } from "convex/react"; import { api } from "../../../../../convex/_generated/api"; -import { useState } from "react"; type Props = { teamList: Team[]; diff --git a/src/app/dashboard/team/page.tsx b/src/app/dashboard/team/page.tsx new file mode 100644 index 0000000..07c1556 --- /dev/null +++ b/src/app/dashboard/team/page.tsx @@ -0,0 +1,6 @@ + +export default function Page() { + return ( +
Page
+ ) +} \ No newline at end of file diff --git a/src/components/shared/MemberCarousel.tsx b/src/components/shared/MemberCarousel.tsx new file mode 100644 index 0000000..fc5b58a --- /dev/null +++ b/src/components/shared/MemberCarousel.tsx @@ -0,0 +1,7 @@ +import React from 'react' + +export default function MemberCarousel() { + return ( +
MemberCarousel
+ ) +} \ No newline at end of file