Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: team settings page #500

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/api/files/get/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function GET(

await mongoDB();

const files = await FileModel.find({teamId:id}).populate("createdBy")
const files = await FileModel.find({teamId:id}).populate("createdBy");

return NextResponse.json(files,{ status: 200 });
} catch (err) {
Expand Down
3 changes: 1 addition & 2 deletions src/app/api/teams/getTeamById/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export async function GET(

await mongoDB();

const teams = await TeamModel.findById({ _id: id }).populate("createdBy");

const teams = await TeamModel.findById({ _id: id }).populate("createdBy").populate("files");

return NextResponse.json(teams, { status: 200 });
} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions src/app/dashboard/_components/SideNavBottomSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ function SideNavBottomSection({getFiles, totalFiles, activeTeam }: any) {
const [fileList, setFileList] = useState<any>([]);
const [fileInput, setFileInput] = useState<string>("");
const [error, setError] = useState<string>("");

const email = ((state:RootState) => state.auth.user.email)

const user = useSelector((state:RootState)=>state.auth.user);
const axiosInstance = createAxiosInstance(user.accessToken);
const [filePrivate,setFileprivate] = useState(false);
Expand Down Expand Up @@ -132,6 +131,7 @@ function SideNavBottomSection({getFiles, totalFiles, activeTeam }: any) {
console.log(err)
}
}
console.log(activeTeam)

return (
<div>
Expand All @@ -148,7 +148,7 @@ function SideNavBottomSection({getFiles, totalFiles, activeTeam }: any) {
</Link>
))}

{email === activeTeam?.createdBy && <Link href={`/teams/settings/${activeTeam?._id}`}>
{activeTeam && user.id === activeTeam.createdBy && <Link href={`/teams/settings/${activeTeam?._id}`}>
<h2
className={`flex gap-2 p-1 ${
pathname == `/dashboard/team` ? "bg-muted" : ""
Expand Down
54 changes: 27 additions & 27 deletions src/app/teams/settings/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
"use client";
import MemberCarousel, { USER } from "@/components/shared/MemberCarousel";
import axiosInstance from "@/config/AxiosInstance";
import { getTeamMembersData } from "@/lib/API-URLs";
import FileList, { FILE } from "../_components/FileList";
import { useConvex } from "convex/react";
import { api } from "../../../../../convex/_generated/api";
import MemberCarousel from "@/components/shared/MemberCarousel";
import { getFileUrl, getTeamMembersData } from "@/lib/API-URLs";
import { ArrowBigLeft } from "lucide-react";
import Link from "next/link";
import { useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { RootState } from "@/config/store";
import createAxiosInstance from "@/config/AxiosProtectedRoute";
import { FILE } from "@/types/types";
import FileList from "../_components/FileList";

export default function Page({ params }: { params: { id: string } }) {
const teamId = params.id;
const convex = useConvex();
const [teamMembersData, setData] = useState(null);
const [focusedUser, setFocusedUser] = useState<USER | null>(null);
const [focusedUser, setFocusedUser] = useState<any | null>(null);
const [fileList, setFileList] = useState<FILE[]>([]);
const [updated,setIsUpdated] = useState(true);
const user = useSelector((state:RootState) => state.auth.user);
const axiosInstance = createAxiosInstance(user.accessToken);


useEffect(() => {
const getData = async () => {
const res = await convex.query(api.files.getFiles, { teamId: teamId });
setFileList(res);
setIsUpdated(false);

const getFiles = async () => {
const result = await axiosInstance.get(`${getFileUrl}/${teamId}`);
setFileList(result.data);
};

if (teamId && updated) {
getData();
getFiles();
}
}, [teamId,updated]);

useEffect(() => {
const getData = async () => {
try {
const res = await axiosInstance.get(`${getTeamMembersData}/${teamId}`);
setData(res.data.memberData);
} catch (err) {
console.log(err);
}
};
if (teamId) {
getData();
console.log(fileList)

useEffect(()=>{
const getData = async() => {
const res = await axiosInstance.get(`${getTeamMembersData}/${teamId}`);
setData(res.data)
}
}, [teamId]);
getData()

},[])

return (
<div className="w-[full] bg-background flex relative flex-col gap-5 flex-1 items-start justify-center overflow-y-auto overflow-x-hidden">
Expand All @@ -65,9 +65,9 @@ export default function Page({ params }: { params: { id: string } }) {
)}

<div className=" w-full px-10">
{focusedUser !== null && (
{focusedUser !== null &&
<FileList setIsUpdated={setIsUpdated} teamId={teamId} user={focusedUser} fileList={fileList} />
)}
}
</div>
</div>
);
Expand Down
56 changes: 12 additions & 44 deletions src/app/teams/settings/_components/FileList.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,13 @@
import { useState, useEffect, SetStateAction } from "react";
import {
Loader2,
ChevronsUpDown,
ArchiveIcon,
CheckCircle2,
Edit3Icon,
ChevronsUpDown
} from "lucide-react";
import { usePathname, useRouter } from "next/navigation";
import { useConvex } from "convex/react";
import { Button } from "@/components/ui/button";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { useRouter } from "next/navigation";
import { Badge } from "@/components/ui/badge";
import ReadAccessModal from "@/components/shared/ReadAccessModal";
import WriteAccessModal from "@/components/shared/WriteAccessModal";

export interface FILE {
archive: boolean;
createdBy: string;
document: string;
fileName: string;
teamId: string;
whiteboard: string;
_id: string;
_creationTime: number;
private: boolean;
read: boolean;
write: boolean;
readBy: string[];
writtenBy: string[];
}
import { FILE } from "@/types/types";

const FileRow = ({
file,
Expand All @@ -64,21 +33,21 @@ const FileRow = ({
className="whitespace-nowrap px-4 py-2 text-muted-foreground"
onClick={() => router.push("/workspace/" + file._id)}
>
{file.createdBy}
{file.createdBy.email}
</td>
<td
className="whitespace-nowrap px-4 py-2 text-muted-foreground"
onClick={() => router.push("/workspace/" + file._id)}
>
{file.readBy
? file.readBy.includes(user.email.toString()) && <Badge>Read</Badge>
? file.readBy.includes(user._id) && <Badge>Read</Badge>
: ""}
{file.writtenBy
? file.writtenBy &&
file.writtenBy.includes(user.email) && <Badge>Write</Badge>
file.writtenBy.includes(user._id) && <Badge>Write</Badge>
: ""}
{!file.readBy.includes(user.email) &&
!file.writtenBy.includes(user.email) && <Badge>No Access</Badge>}
{!file.readBy.includes(user._id) &&
!file.writtenBy.includes(user._id) && <Badge>No Access</Badge>}
</td>
<td className="flex gap-2 whitespace-nowrap px-4 py-2 text-muted-foreground">
<ReadAccessModal
Expand Down Expand Up @@ -109,7 +78,6 @@ function FileList({
setIsUpdated: React.Dispatch<SetStateAction<boolean>>;
}) {
const router = useRouter();
const convex = useConvex();
const [sortConfig, setSortConfig] = useState<{
key: keyof FILE;
direction: string;
Expand Down Expand Up @@ -245,14 +213,14 @@ function FileList({
</div>
<div className="flex justify-between items-center mb-2">
<div className="flex flex-col">
{file.readBy && file.readBy.includes(user.email) && (
{file.readBy && file.readBy.includes(user._id) && (
<Badge>Read</Badge>
)}
{file.writtenBy && file.writtenBy.includes(user.email) && (
{file.writtenBy && file.writtenBy.includes(user._id) && (
<Badge>Write</Badge>
)}
{!file.readBy.includes(user.email) &&
!file.writtenBy.includes(user.email) && (
{!file.readBy.includes(user._id) &&
!file.writtenBy.includes(user._id) && (
<Badge>No Access</Badge>
)}
</div>
Expand Down
21 changes: 7 additions & 14 deletions src/components/shared/MemberCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@ import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar";
import { SetStateAction } from "react";
import DeleteTeamMember from "./DeleteTeamMember";

export type USER = {
name: string;
_id: string;
email: string;
image: string;
};

type Props = {
teamMembersData: USER[];
focusedUser:USER | null;
setFocusedUser:React.Dispatch<SetStateAction<USER | null>>;
teamMembersData: any[];
focusedUser:any;
setFocusedUser:React.Dispatch<SetStateAction<any | null>>;
};

export default function MemberCarousel({ teamMembersData,focusedUser,setFocusedUser }: Props) {
Expand All @@ -36,7 +29,7 @@ export default function MemberCarousel({ teamMembersData,focusedUser,setFocusedU
<CarouselPrevious />
<CarouselContent>
{teamMembersData !== null &&
teamMembersData.map((user: USER, index) => (
teamMembersData.map((user: any, index) => (
<CarouselItem
onClick={() => setFocusedUser(user)}
key={index}
Expand All @@ -48,12 +41,12 @@ export default function MemberCarousel({ teamMembersData,focusedUser,setFocusedU
>
<CardHeader className="flex sm:flex-row flex-col gap-3 items-center justify-start">
<Avatar className="w-[50px] h-[50px]">
<AvatarImage src={user.image} />
<AvatarImage src={user.image || ""} />
<AvatarFallback className=" text-2xl">
{user.name.charAt(0)}
{user.firstName.charAt(0)}
</AvatarFallback>
</Avatar>
{user.name}
{user.firstName}{" "}{user.lastName}
</CardHeader>
<CardContent>
<CardDescription className="flex sm:flex-row gap-3 sm:gap-0 flex-col items-center justify-between">
Expand Down
Loading