feat: attribute selects and options editors
This commit is contained in:
32
src/hooks/lists/useAttrSelectsList.ts
Normal file
32
src/hooks/lists/useAttrSelectsList.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AttrSelectSchema } from "@/lib/client";
|
||||
import {
|
||||
getAttrSelectsOptions,
|
||||
getAttrSelectsQueryKey,
|
||||
} from "@/lib/client/@tanstack/react-query.gen";
|
||||
|
||||
const useAttrSelectsList = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { data, refetch } = useQuery(getAttrSelectsOptions());
|
||||
|
||||
const queryKey = getAttrSelectsQueryKey();
|
||||
|
||||
const setSelects = (selects: AttrSelectSchema[]) => {
|
||||
queryClient.setQueryData(
|
||||
queryKey,
|
||||
(old: { items: AttrSelectSchema[] }) => ({
|
||||
...old,
|
||||
items: selects,
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
return {
|
||||
selects: data?.items ?? [],
|
||||
setSelects,
|
||||
refetch,
|
||||
queryKey,
|
||||
};
|
||||
};
|
||||
|
||||
export default useAttrSelectsList;
|
||||
Reference in New Issue
Block a user