Skip to content

Commit

Permalink
feat/384
Browse files Browse the repository at this point in the history
  • Loading branch information
Sid-80 committed Jul 1, 2024
1 parent 185dc9d commit 90b1299
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/app/api/teams/members/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ export async function GET(
);

const results = await Promise.all(memberDataPromises);
console.log(results)

const memberData = results.flatMap((result) => result || []);

return Response.json({ memberData });
}

export async function DELETE(
export async function PUT(
request: Request,
{ params }: { params: { id: string } }
) {
Expand All @@ -49,6 +50,6 @@ export async function DELETE(

await client.mutation(api.teams.addMember, { _id: id as Id<"teams">, memberArray:updatedTeamMembers });

return new Response("Member removed!!", { status: 200 });
return new Response("Member removd!!", { status: 200 });

}
2 changes: 2 additions & 0 deletions src/app/dashboard/_components/SideNavTopSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function SideNavTopSection({ user, setActiveTeamInfo }: any) {
const [teamMembersData, setTeamData] = useState<any[]>([]);
const [ActiveTeamMembers, setActiveTeamMembers] = useState<string[]>([]);

console.log(activeTeam)

useEffect(() => {
user && getTeamList();
}, [user]);
Expand Down
88 changes: 88 additions & 0 deletions src/components/shared/DeleteTeamMember.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"use client";
import React, { useState } from "react";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "../ui/alert-dialog";
import { Button } from "../ui/button";
import { CheckCircle2, Trash2 } from "lucide-react";
import axiosInstance from "@/config/AxiosInstance";
import { deleteTeamMemberUrl } from "@/lib/API-URLs";
import { useSelector } from "react-redux";
import { RootState } from "@/app/store";
import { useRouter } from "next/navigation";

type Props = {
email: string;
};

export default function DeleteTeamMember({ email }: Props) {
const [isSubmitted, setIsSubmitted] = useState(false);
const router = useRouter();
const teamId = useSelector((state: RootState) => state.team.teamId);

const DeleteHandler = async () => {
try {
axiosInstance.put(`${deleteTeamMemberUrl}/${teamId}`, { email })
.then((res)=>{
if(res.status === 200) setIsSubmitted(true);
})
} catch (err) {
console.log(err);
}
};

return (
<AlertDialog>
<AlertDialogTrigger>
<Button size={"icon"} className=" bg-red-600 hover:bg-red-700">
<Trash2 className="w-5 h-5" />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
{!isSubmitted && (
<>
<AlertDialogHeader>
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will remove the member from
the team and files created by the member will be permanently
deleted.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<Button onClick={() => DeleteHandler()}>Continue</Button>
</AlertDialogFooter>
</>
)}
{isSubmitted && (
<>
<AlertDialogHeader>
<AlertDialogTitle className="flex gap-2">
<p>Team Member Removed Successfully!!</p>{" "}
<CheckCircle2 className="w-6 h-6" />
</AlertDialogTitle>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogAction
onClick={() => {
router.push('/dashboard')
}}
>
Continue
</AlertDialogAction>
</AlertDialogFooter>
</>
)}
</AlertDialogContent>
</AlertDialog>
);
}
13 changes: 3 additions & 10 deletions src/components/shared/MemberCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import {
CardHeader,
} from "@/components/ui/card";
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar";
import { Button } from "../ui/button";
import { Trash2 } from "lucide-react";
import { SetStateAction, useState } from "react";
import { SetStateAction } from "react";
import DeleteTeamMember from "./DeleteTeamMember";

export type USER = {
name: string;
Expand All @@ -31,7 +30,6 @@ type Props = {
};

export default function MemberCarousel({ teamMembersData,focusedUser,setFocusedUser }: Props) {

return (
<div className="flex flex-col items-center justify-center p-10 w-[75%]">
<Carousel className="w-full">
Expand Down Expand Up @@ -60,12 +58,7 @@ export default function MemberCarousel({ teamMembersData,focusedUser,setFocusedU
<CardContent>
<CardDescription className="flex items-center justify-between">
<h1>Email : {user.email}</h1>
<Button
size={"icon"}
className=" bg-red-600 hover:bg-red-700"
>
<Trash2 className="w-5 h-5" />
</Button>
<DeleteTeamMember email={user.email} />
</CardDescription>
</CardContent>
</Card>
Expand Down
3 changes: 2 additions & 1 deletion src/lib/API-URLs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const changeToPrivateUrl = "/api/files/private"
export const changeToPublicUrl = "/api/files/public"
export const getTeamMembersData = "/api/teams/members";
export const getTeamMembersData = "/api/teams/members";
export const deleteTeamMemberUrl = "/api/teams/members";

0 comments on commit 90b1299

Please sign in to comment.