Skip to content

Commit

Permalink
feat: profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
Sid-80 committed Jul 16, 2024
1 parent db8e6d3 commit c4c262b
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 141 deletions.
6 changes: 6 additions & 0 deletions src/app/api/files/create/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mongoDB } from "@/lib/MongoDB";
import { AuthMiddleware } from "@/Middleware/AuthMiddleware";
import FileModel from "@/models/file";
import TeamModel from "@/models/team";
import { ApiUser } from "@/types/types";
import { NextResponse } from "next/server";

Expand Down Expand Up @@ -29,6 +30,11 @@ export const POST = async (req: Request) => {
writtenBy:[user._id],
teamId:teamId
});

await TeamModel.updateOne(
{ _id: teamId },
{ $push: { files: file._id } }
);

return NextResponse.json({ status: 200 });
} catch (err) {
Expand Down
32 changes: 32 additions & 0 deletions src/app/api/files/getAllFiles/[userId]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { mongoDB } from "@/lib/MongoDB";
import { AuthMiddleware } from "@/Middleware/AuthMiddleware";
import FileModel from "@/models/file";
import { NextResponse } from "next/server";

export async function GET(
request: Request,
{ params }: { params: { userId: string } }
) {

const result = await AuthMiddleware(request);

if (result instanceof NextResponse) {

try {

const { userId } = params;

if (!userId) return new Response("Parameters missing!!", { status: 401 });

await mongoDB();

const files = await FileModel.find({createdBy:userId}).populate("createdBy")

return NextResponse.json(files,{ status: 200 });
} catch (err) {
return NextResponse.json(`Err : ${err}`, {status:500});
}
} else {
return result;
}
}
3 changes: 2 additions & 1 deletion src/app/api/teams/create/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const POST = async (req: Request) => {
const team = await TeamModel.create({
teamName,
createdBy:user._id,
teamMembers:[user._id]
teamMembers:[user._id],
files:[]
});

return NextResponse.json({teamId:team._id,teamName:team.teamName},{ status: 200 });
Expand Down
39 changes: 8 additions & 31 deletions src/app/dashboard/_components/FileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import {
import moment from "moment";
import Image from "next/image";
import { usePathname, useRouter } from "next/navigation";
import { useConvex, useMutation } from "convex/react";
import { api } from "../../../../convex/_generated/api";
import { Id } from "../../../../convex/_generated/dataModel";
import { Button } from "@/components/ui/button";
import {
AlertDialog,
Expand All @@ -29,29 +26,10 @@ import {
} from "@/components/ui/alert-dialog";
import RenameFileModal from "@/components/shared/RenameFileModal";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Badge } from "@/components/ui/badge";
import FileStatusModal from "@/components/shared/FileStatusModal";
import { RootState } from "@/config/store";
import createAxiosInstance from "@/config/AxiosProtectedRoute";
import { deleteFileUrl, updateFileUrl } from "@/lib/API-URLs";

export interface FILE {
archive: boolean;
createdBy: {
email: string;
firstName: string;
lastName: string;
};
document: string;
fileName: string;
teamId: string;
whiteboard: string;
_id: string;
_creationTime: number;
filePrivate: boolean;
readBy:any[];
writtenBy:any[];
}
import { FILE } from "@/types/types";

const ActionDialog = ({
buttonIcon: ButtonIcon,
Expand Down Expand Up @@ -152,13 +130,13 @@ const FileRow = ({
className="whitespace-nowrap px-4 py-2 text-muted-foreground"
onClick={() => router.push("/workspace/" + file._id)}
>
{moment(file._creationTime).format("DD MMM YYYY")}
{moment(file.createdAt).format("DD MMM YYYY")}
</td>
<td
className="whitespace-nowrap px-4 py-2 text-muted-foreground"
onClick={() => router.push("/workspace/" + file._id)}
>
{moment(file._creationTime).format("DD MMM YYYY")}
{moment(file.createdAt).format("DD MMM YYYY")}
</td>
<td
className="whitespace-nowrap px-4 py-2 text-muted-foreground"
Expand Down Expand Up @@ -231,12 +209,11 @@ function FileList({
picture,
user,
}: {
fileList?: FILE[];
fileList: FILE[];
picture: string;
user: any;
}) {
const router = useRouter();
const convex = useConvex();
const [sortConfig, setSortConfig] = useState<{
key: keyof FILE;
direction: string;
Expand Down Expand Up @@ -340,7 +317,7 @@ function FileList({
</td>
<td
className="whitespace-nowrap px-4 py-2 font-medium cursor-pointer"
onClick={() => requestSort("_creationTime")}
onClick={() => requestSort("createdAt")}
>
Created At <ChevronsUpDown className="inline-block ml-2" />
</td>
Expand Down Expand Up @@ -398,7 +375,7 @@ function FileList({
</div>
<div
className="cursor-pointer"
onClick={() => requestSort("_creationTime")}
onClick={() => requestSort("createdAt")}
>
Created At <ChevronsUpDown className="inline-block ml-2" />
</div>
Expand Down Expand Up @@ -449,11 +426,11 @@ function FileList({
<div className="flex flex-col">
<div className="mb-2 text-muted-foreground">
<Clock className="inline-block mr-2" size={20} />
{moment(file._creationTime).format("YYYY-MM-DD")}
{moment(file.createdAt).format("YYYY-MM-DD")}
</div>
<div className="mb-2 text-muted-foreground">
<Edit className="inline-block mr-2" size={20} />
{moment(file._creationTime).format("YYYY-MM-DD")}
{moment(file.createdAt).format("YYYY-MM-DD")}
</div>
</div>
<FileStatusModal
Expand Down
4 changes: 0 additions & 4 deletions src/app/dashboard/_components/SideNavBottomSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import { FileListContext } from "@/app/_context/FilesListContext";
import { ErrorMessage } from "@/components/ui/error";
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import { Id } from "../../../../convex/_generated/dataModel";
import { useMutation } from "convex/react";
import { api } from "../../../../convex/_generated/api";
import { toast } from "sonner";
import {
AlertDialog,
Expand Down Expand Up @@ -88,7 +85,6 @@ function SideNavBottomSection({getFiles, totalFiles, activeTeam }: any) {
const [error, setError] = useState<string>("");

const email = ((state:RootState) => state.auth.user.email)
const deleteTeam = useMutation(api.teams.deleteTeam);
const user = useSelector((state:RootState)=>state.auth.user);
const axiosInstance = createAxiosInstance(user.accessToken);
const [filePrivate,setFileprivate] = useState(false);
Expand Down
5 changes: 0 additions & 5 deletions src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
"use client";
import type { RootState } from "../../config/store";
import { FileListContext } from "@/app/_context/FilesListContext";
import { api } from "../../../convex/_generated/api";
import { useConvex, useMutation } from "convex/react";
import FileList from "./_components/FileList";
import { useState, useContext, useEffect } from "react";
import { Input } from "@/components/ui/input";
import ThemeTogglebutton from "@/components/ui/ThemeToggle";
import { Search } from "lucide-react";
import Image from "next/image";
import { toggleClose } from "../Redux/Menu/menuSlice";
import { useSelector, useDispatch } from "react-redux";
import Link from "next/link";
Expand Down Expand Up @@ -38,8 +35,6 @@ export interface FILE {
}

function Dashboard() {
const convex = useConvex();
const createUser = useMutation(api.user.createUser);
const count = useSelector((state: RootState) => state.counter.value);
const activeTeamId = useSelector((state: RootState) => state.team.teamId);
const dispatch = useDispatch();
Expand Down
42 changes: 20 additions & 22 deletions src/app/dashboard/profile/_components/FileList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use client";
import { FILE } from "../../page";
import { useEffect, useState } from "react";
import {
Loader2,
Expand All @@ -12,7 +11,6 @@ import {
} from "lucide-react";
import moment from "moment";
import { useRouter } from "next/navigation";
import { useMutation } from "convex/react";
import { Button } from "@/components/ui/button";
import {
AlertDialog,
Expand All @@ -25,16 +23,9 @@ import {
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Id } from "../../../../../convex/_generated/dataModel";
import { api } from "../../../../../convex/_generated/api";

export interface Team {
createdBy: string;
teamName: string;
_creationTime: number;
_id: string;
fileCount?: number;
}
import { FILE, TEAM } from "@/types/types";
import createAxiosInstance from "@/config/AxiosProtectedRoute";
import { deleteFileUrl } from "@/lib/API-URLs";

const ActionDialog = ({
buttonIcon: ButtonIcon,
Expand Down Expand Up @@ -125,13 +116,13 @@ const FileRow = ({
className="whitespace-nowrap px-8 py-2 text-muted-foreground"
onClick={() => router.push("/workspace/" + file._id)}
>
{moment(file._creationTime).format("DD MMM YYYY")}
{moment(file.createdAt).format("DD MMM YYYY")}
</td>
<td
className="whitespace-nowrap px-8 py-2 text-muted-foreground"
onClick={() => router.push("/workspace/" + file._id)}
>
{moment(file._creationTime).format("DD MMM YYYY")}
{moment(file.createdAt).format("DD MMM YYYY")}
</td>
<td className="whitespace-nowrap px-8 py-2 text-muted-foreground">
{teamLookup[file.teamId] || "Unknown Team"}
Expand All @@ -153,9 +144,11 @@ const FileRow = ({
export default function FileList({
fileList,
teamList,
user
}: {
user:any;
fileList?: FILE[];
teamList: Team[];
teamList: TEAM[];
}) {
const router = useRouter();
const [sortConfig, setSortConfig] = useState<{
Expand All @@ -167,6 +160,8 @@ export default function FileList({
const [isSubmitted, setIsSubmitted] = useState(false);
const safeFileList = Array.isArray(fileList) ? fileList : [];

const axiosInstance = createAxiosInstance(user.accessToken)

const sortedFiles = [...safeFileList];
if (sortConfig !== null) {
sortedFiles.sort((a, b) => {
Expand All @@ -180,11 +175,14 @@ export default function FileList({
});
}

const deleteFile = useMutation(api.files.deleteFile);
const deleteFunc = async (e: any, id: string) => {
e.stopPropagation();
await deleteFile({ _id: id as Id<"files"> });
setIsSubmitted(true);
try {
await axiosInstance.delete(`${deleteFileUrl}/${id}`)
setIsSubmitted(true);
} catch (err) {
console.log(err);
}
};

const requestSort = (key: keyof FILE) => {
Expand Down Expand Up @@ -234,7 +232,7 @@ export default function FileList({
</td>
<td
className="whitespace-nowrap px-8 py-2 font-medium cursor-pointer"
onClick={() => requestSort("_creationTime")}
onClick={() => requestSort("createdAt")}
>
Created At <ChevronsUpDown className="inline-block ml-2" />
</td>
Expand Down Expand Up @@ -285,7 +283,7 @@ export default function FileList({
</div>
<div
className="cursor-pointer"
onClick={() => requestSort("_creationTime")}
onClick={() => requestSort("createdAt")}
>
Created At <ChevronsUpDown className="inline-block ml-2" />
</div>
Expand All @@ -309,11 +307,11 @@ export default function FileList({
</div>
<div className="mb-2 text-muted-foreground">
<Clock className="inline-block mr-2" size={20} />
{moment(file._creationTime).format("YYYY-MM-DD")}
{moment(file.createdAt).format("YYYY-MM-DD")}
</div>
<div className="mb-2 text-muted-foreground">
<Edit className="inline-block mr-2" size={20} />
{moment(file._creationTime).format("YYYY-MM-DD")}
{moment(file.createdAt).format("YYYY-MM-DD")}
</div>
<div className="mb-2 text-muted-foreground">
<Users className="inline-block mr-2" size={20} />
Expand Down
Loading

0 comments on commit c4c262b

Please sign in to comment.