update section

This commit is contained in:
hamid zarghami
2026-02-02 10:03:24 +03:30
parent a25ab81d08
commit 7f2000ec6d
7 changed files with 154 additions and 3 deletions
+25 -1
View File
@@ -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],
});
},
});
};