Skip to content

Commit

Permalink
Merge pull request #269 from Sid-80/feat/267
Browse files Browse the repository at this point in the history
feat: rename file functionality
  • Loading branch information
subhadeeproy3902 authored Jun 11, 2024
2 parents fe0d465 + b90ad36 commit 71817e5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion convex/teams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
})
4 changes: 2 additions & 2 deletions src/app/dashboard/_components/FileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const FileRow = ({
/>
</td>
<td className="flex gap-2 whitespace-nowrap px-4 py-2 text-muted-foreground">
<RenameFileModal />
<RenameFileModal id={file._id} />
{pathname === "/dashboard" && (
<ActionDialog
isSubmitted={isSubmitted}
Expand Down Expand Up @@ -356,7 +356,7 @@ function FileList({
<div className="flex justify-between items-center mb-2">
<span className="font-bold text-xl">{file.fileName}</span>
<div className="flex gap-2">
<RenameFileModal />
<RenameFileModal id={file._id} />
{pathname === "/dashboard" && (
<ActionDialog
isSubmitted={isSubmitted}
Expand Down
7 changes: 6 additions & 1 deletion src/app/dashboard/_components/SideNavTopSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { useConvex } from "convex/react";
import { api } from "../../../../convex/_generated/api";
import { useRouter } from "next/navigation";
import { Button } from "@/components/ui/button";
import { useDispatch } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { setTeamInfo } from "@/app/Redux/Team/team-slice";
import RenameTeamModal from "@/components/shared/RenameTeamModal";
import { RootState } from "@/app/store";

export interface TEAM {
createdBy: String;
Expand All @@ -23,6 +24,8 @@ export interface TEAM {
teamMembers?: string[];
}
function SideNavTopSection({ user, setActiveTeamInfo }: any) {
const id = useSelector((state: RootState) => state.team.teamId);
console.log(id)
const menu = [
{
id: 1,
Expand Down Expand Up @@ -62,6 +65,8 @@ function SideNavTopSection({ user, setActiveTeamInfo }: any) {
);
};

console.log(teamList)

const onMenuClick = (item: any) => {
if (item.path) {
router.push(item.path);
Expand Down
18 changes: 13 additions & 5 deletions src/components/shared/RenameFileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ 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, {
message: "Team Name required!",
}),
});

type Props = {
id:string;
setIsSubmitted: React.Dispatch<SetStateAction<boolean>>;
}

export function RenameFileForm() {
export function RenameFileForm({id,setIsSubmitted}:Props) {
const convex = useConvex();
const id = useSelector((state: RootState) => state.team.teamId);

const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
Expand All @@ -38,7 +41,12 @@ export function RenameFileForm() {
});

async function onSubmit(data: z.infer<typeof FormSchema>) {
const result = await convex.mutation(api.files.renameFile,{
_id:id as Id<"files">,
newName:data.newName
})

setIsSubmitted(true);
}

return (
Expand Down
31 changes: 26 additions & 5 deletions src/components/shared/RenameFileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Dialog>
<DialogTrigger>
<Button variant={"secondary"} size="icon">
<PencilIcon className="w-4 h-4" />
</Button>
<Button variant={"secondary"} size="icon">
<PencilIcon className="w-4 h-4" />
</Button>
</DialogTrigger>
<DialogContent>
{!isSubmitted && (
<DialogHeader>
<DialogTitle>
<h1>Rename File</h1>
</DialogTitle>
<DialogDescription>
<RenameFileForm />
<RenameFileForm id={id} setIsSubmitted={setIsSubmitted} />
</DialogDescription>
</DialogHeader>
)}
{isSubmitted && (
<>
<DialogHeader>
<DialogTitle>File renamed successfully!!</DialogTitle>
</DialogHeader>
<DialogFooter>
<Button onClick={() => router.refresh()}>Close</Button>
</DialogFooter>
</>
)}
</DialogContent>
</Dialog>
);
Expand Down
1 change: 0 additions & 1 deletion src/components/shared/RenameTeamForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 71817e5

Please sign in to comment.