Feat: Add CRUD operation and tag management

This commit is contained in:
munna-yadav
2025-06-30 12:04:43 +05:30
parent b0afe3f1f1
commit c53c3c73e9
15 changed files with 1330 additions and 240 deletions

View File

@@ -4,6 +4,11 @@ import { clientEnv } from "@/lib/env/client-env";
import axios, { type AxiosError } from "axios";
import { toast } from "sonner";
interface RenameFileParams {
id: string;
name: string;
}
export function useFileOperations() {
const deleteFileMutation = useMutation({
mutationFn: async ({ id }: DeleteFileParams) => {
@@ -27,11 +32,40 @@ export function useFileOperations() {
},
});
const renameFileMutation = useMutation({
mutationFn: async ({ id, name }: RenameFileParams) => {
const response = await axios.put(`${clientEnv.NEXT_PUBLIC_BACKEND_URL}/api/files`, null, {
params: { id, name },
headers: {
"Content-Type": "application/json",
},
withCredentials: true,
signal: new AbortController().signal,
});
return response.data;
},
onSuccess: () => {
toast.success("File renamed successfully");
},
onError: (error: AxiosError) => {
console.error("Error renaming file:", error);
const errorMessage = error.message || "Failed to rename file";
toast.error(errorMessage);
},
});
const handleDeleteFile = (id: string) => {
deleteFileMutation.mutate({ id });
};
const handleRenameFile = (id: string, name: string) => {
return renameFileMutation.mutateAsync({ id, name });
};
return {
handleDeleteFile,
handleRenameFile,
isDeleting: deleteFileMutation.isPending,
isRenaming: renameFileMutation.isPending,
};
}