am updateing course

This commit is contained in:
2024-08-28 09:20:13 -06:00
parent 5b3f8a8515
commit 1051c4fb6e
5 changed files with 127 additions and 17 deletions

View File

@@ -1,5 +1,10 @@
import { LocalCourse } from "@/models/local/localCourse";
import { useSuspenseQuery } from "@tanstack/react-query";
import {
dataTagSymbol,
useMutation,
useQueryClient,
useSuspenseQuery,
} from "@tanstack/react-query";
import axios from "axios";
export const localCourseKeys = {
@@ -32,3 +37,22 @@ export const useLocalCourseDetailsQuery = (courseName: string) => {
},
});
};
export const useUpdateCourseMutation = (courseName: string) => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (body: {
updatedCourse: LocalCourse;
previousCourse: LocalCourse;
}) => {
const url = `/api/courses/${courseName}`;
await axios.put(url, body);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: localCourseKeys.allCourses }); //optimize?
},
scope: {
id: "update course",
},
});
};