feat: Categories retrieve + list API (#7009)
This commit is contained in:
@@ -1,21 +1,30 @@
|
||||
import {
|
||||
AdminProductCategoryListResponse,
|
||||
AdminProductCategoryResponse,
|
||||
} from "@medusajs/types"
|
||||
import { QueryKey, UseQueryOptions, useQuery } from "@tanstack/react-query"
|
||||
import { client } from "../../lib/client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { CategoriesListRes, CategoryRes } from "../../types/api-responses"
|
||||
|
||||
const CATEGORIES_QUERY_KEY = "categories" as const
|
||||
export const categoriesQueryKeys = queryKeysFactory(CATEGORIES_QUERY_KEY)
|
||||
|
||||
export const useCategory = (
|
||||
id: string,
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
UseQueryOptions<CategoryRes, Error, CategoryRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
AdminProductCategoryResponse,
|
||||
Error,
|
||||
AdminProductCategoryResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryKey: categoriesQueryKeys.detail(id),
|
||||
queryFn: async () => client.categories.retrieve(id),
|
||||
queryKey: categoriesQueryKeys.detail(id, query),
|
||||
queryFn: async () => client.categories.retrieve(id, query),
|
||||
...options,
|
||||
})
|
||||
|
||||
@@ -25,7 +34,12 @@ export const useCategory = (
|
||||
export const useCategories = (
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
UseQueryOptions<CategoriesListRes, Error, CategoriesListRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
AdminProductCategoryListResponse,
|
||||
Error,
|
||||
AdminProductCategoryListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
|
||||
Reference in New Issue
Block a user