feat: modules and module-editor pages
This commit is contained in:
32
src/app/module-editor/[moduleId]/hooks/useAttributesList.ts
Normal file
32
src/app/module-editor/[moduleId]/hooks/useAttributesList.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AttributeSchema } from "@/lib/client";
|
||||
import {
|
||||
getAttributesOptions,
|
||||
getProjectsQueryKey,
|
||||
} from "@/lib/client/@tanstack/react-query.gen";
|
||||
|
||||
const useAttributesList = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { data, refetch } = useQuery(getAttributesOptions());
|
||||
|
||||
const queryKey = getProjectsQueryKey();
|
||||
|
||||
const setAttributes = (attributes: AttributeSchema[]) => {
|
||||
queryClient.setQueryData(
|
||||
queryKey,
|
||||
(old: { items: AttributeSchema[] }) => ({
|
||||
...old,
|
||||
items: attributes,
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
return {
|
||||
attributes: data?.items ?? [],
|
||||
setAttributes,
|
||||
refetch,
|
||||
queryKey,
|
||||
};
|
||||
};
|
||||
|
||||
export default useAttributesList;
|
||||
Reference in New Issue
Block a user