mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
creating assignments
This commit is contained in:
@@ -127,3 +127,46 @@ export const useUpdateAssignmentMutation = () => {
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export const useCreateAssignmentMutation = () => {
|
||||
const { courseName } = useCourseContext();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
assignment,
|
||||
moduleName,
|
||||
assignmentName,
|
||||
}: {
|
||||
assignment: LocalAssignment;
|
||||
moduleName: string;
|
||||
assignmentName: string;
|
||||
}) => {
|
||||
queryClient.setQueryData(
|
||||
localCourseKeys.assignment(courseName, moduleName, assignmentName),
|
||||
assignment
|
||||
);
|
||||
const url =
|
||||
"/api/courses/" +
|
||||
encodeURIComponent(courseName) +
|
||||
"/modules/" +
|
||||
encodeURIComponent(moduleName) +
|
||||
"/assignments/" +
|
||||
encodeURIComponent(assignmentName);
|
||||
await axiosClient.post(url, assignment);
|
||||
},
|
||||
onSuccess: (_, { moduleName, assignmentName }) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: localCourseKeys.assignment(
|
||||
courseName,
|
||||
moduleName,
|
||||
assignmentName
|
||||
),
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: localCourseKeys.assignmentNames(courseName, moduleName),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user