mirror of
https://github.com/nimbusdotstorage/Nimbus
synced 2026-04-29 17:47:16 +02:00
feat(api): fixed middleware, Added Google Drive support, refactored API to remove RoR controllers
This commit is contained in:
42
apps/web/src/hooks/useFileOperations.ts
Normal file
42
apps/web/src/hooks/useFileOperations.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { clientEnv } from "@/lib/env/client-env";
|
||||
import axios, { type AxiosError } from "axios";
|
||||
import { toast } from "sonner";
|
||||
|
||||
interface DeleteFileParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export function useFileOperations() {
|
||||
const deleteFileMutation = useMutation({
|
||||
mutationFn: async ({ id }: DeleteFileParams) => {
|
||||
const response = await axios.delete(`${clientEnv.NEXT_PUBLIC_BACKEND_URL}/api/files`, {
|
||||
params: { id },
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
withCredentials: true,
|
||||
signal: new AbortController().signal,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success("File deleted successfully");
|
||||
},
|
||||
onError: (error: AxiosError) => {
|
||||
console.error("Error deleting file:", error);
|
||||
const errorMessage = error.message || "Failed to delete file";
|
||||
toast.error(errorMessage);
|
||||
},
|
||||
});
|
||||
|
||||
const handleDeleteFile = (id: string) => {
|
||||
deleteFileMutation.mutate({ id });
|
||||
};
|
||||
|
||||
return {
|
||||
handleDeleteFile,
|
||||
};
|
||||
}
|
||||
|
||||
export default useFileOperations;
|
||||
Reference in New Issue
Block a user