update section
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import * as api from "../service/PrintService";
|
||||
import type { CreateSectionType } from "../types/Types";
|
||||
|
||||
export const useGetSections = () => {
|
||||
return useQuery({
|
||||
@@ -8,8 +9,31 @@ export const useGetSections = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetSectionsDetail = (id: number) => {
|
||||
return useQuery({
|
||||
queryKey: ["section", id],
|
||||
queryFn: () => api.getSectionDetail(id),
|
||||
});
|
||||
};
|
||||
|
||||
export const useCreateSection = () => {
|
||||
return useMutation({
|
||||
mutationFn: api.createSection,
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateSection = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, params }: { id: number; params: CreateSectionType }) =>
|
||||
api.updateSection(id, params),
|
||||
onSuccess: (_, params) => {
|
||||
queryClient.refetchQueries({
|
||||
queryKey: ["sections"],
|
||||
});
|
||||
queryClient.refetchQueries({
|
||||
queryKey: ["section", params.id],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user