From b90ad369e82fa4ea1bdc4524bc6d1e93a2d1e9bb Mon Sep 17 00:00:00 2001 From: Sid-80 Date: Tue, 11 Jun 2024 19:35:12 +0530 Subject: [PATCH] feat: rename file functionality --- convex/teams.tsx | 2 +- src/app/dashboard/_components/FileList.tsx | 4 +-- .../_components/SideNavTopSection.tsx | 7 ++++- src/components/shared/RenameFileForm.tsx | 18 ++++++++--- src/components/shared/RenameFileModal.tsx | 31 ++++++++++++++++--- src/components/shared/RenameTeamForm.tsx | 1 - 6 files changed, 48 insertions(+), 15 deletions(-) diff --git a/convex/teams.tsx b/convex/teams.tsx index ede81e9..3bba994 100644 --- a/convex/teams.tsx +++ b/convex/teams.tsx @@ -77,7 +77,7 @@ export const renameTeam = mutation({ }, handler: async (ctx,args) => { const { _id,newName } = args; - const res = await ctx.db.patch(_id,{fileName:newName}); + const res = await ctx.db.patch(_id,{teamName:newName}); return res; } }) \ No newline at end of file diff --git a/src/app/dashboard/_components/FileList.tsx b/src/app/dashboard/_components/FileList.tsx index 01c83d0..853bcf6 100644 --- a/src/app/dashboard/_components/FileList.tsx +++ b/src/app/dashboard/_components/FileList.tsx @@ -160,7 +160,7 @@ const FileRow = ({ /> - + {pathname === "/dashboard" && ( {file.fileName}
- + {pathname === "/dashboard" && ( state.team.teamId); + console.log(id) const menu = [ { id: 1, @@ -62,6 +65,8 @@ function SideNavTopSection({ user, setActiveTeamInfo }: any) { ); }; + console.log(teamList) + const onMenuClick = (item: any) => { if (item.path) { router.push(item.path); diff --git a/src/components/shared/RenameFileForm.tsx b/src/components/shared/RenameFileForm.tsx index 6e816f2..bf8b842 100644 --- a/src/components/shared/RenameFileForm.tsx +++ b/src/components/shared/RenameFileForm.tsx @@ -14,10 +14,10 @@ import { } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { useConvex } from "convex/react"; -import { SetStateAction } from "react"; import { PencilIcon } from "lucide-react"; -import { useSelector } from "react-redux"; -import { RootState } from "@/app/store"; +import { api } from "../../../convex/_generated/api"; +import { Id } from "../../../convex/_generated/dataModel"; +import { SetStateAction } from "react"; const FormSchema = z.object({ newName: z.string().min(1, { @@ -25,10 +25,13 @@ const FormSchema = z.object({ }), }); +type Props = { + id:string; + setIsSubmitted: React.Dispatch>; +} -export function RenameFileForm() { +export function RenameFileForm({id,setIsSubmitted}:Props) { const convex = useConvex(); - const id = useSelector((state: RootState) => state.team.teamId); const form = useForm>({ resolver: zodResolver(FormSchema), @@ -38,7 +41,12 @@ export function RenameFileForm() { }); async function onSubmit(data: z.infer) { + const result = await convex.mutation(api.files.renameFile,{ + _id:id as Id<"files">, + newName:data.newName + }) + setIsSubmitted(true); } return ( diff --git a/src/components/shared/RenameFileModal.tsx b/src/components/shared/RenameFileModal.tsx index b4f04ba..5cf3e6f 100644 --- a/src/components/shared/RenameFileModal.tsx +++ b/src/components/shared/RenameFileModal.tsx @@ -4,30 +4,51 @@ import { Dialog, DialogContent, DialogDescription, + DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "../ui/dialog"; import { RenameFileForm } from "./RenameFileForm"; import { Button } from "../ui/button"; +import { useState } from "react"; +import { useRouter } from "next/navigation"; -export default function RenameFileModal() { +type Props = { + id: string; +}; + +export default function RenameFileModal({ id }: Props) { + const router = useRouter(); + const [isSubmitted, setIsSubmitted] = useState(false); return ( - + + {!isSubmitted && (

Rename File

- +
+ )} + {isSubmitted && ( + <> + + File renamed successfully!! + + + + + + )}
); diff --git a/src/components/shared/RenameTeamForm.tsx b/src/components/shared/RenameTeamForm.tsx index c55b936..8a5db84 100644 --- a/src/components/shared/RenameTeamForm.tsx +++ b/src/components/shared/RenameTeamForm.tsx @@ -14,7 +14,6 @@ import { FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; -import { useRouter } from "next/navigation"; import { useConvex } from "convex/react"; import { api } from "../../../convex/_generated/api"; import { Id } from "../../../convex/_generated/dataModel";