-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add store queries to react medusa
- Loading branch information
Showing
7 changed files
with
74 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"medusa-react": patch | ||
"@medusajs/medusa-js": patch | ||
"@medusajs/medusa": patch | ||
--- | ||
|
||
feat(medusa, medusa-js, medusa-react): Add store queries to react medusa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
54 changes: 54 additions & 0 deletions
54
packages/medusa-react/src/hooks/store/product-categories/queries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
StoreGetProductCategoriesParams, | ||
StoreGetProductCategoriesRes, | ||
StoreGetProductCategoriesCategoryParams, | ||
StoreGetProductCategoriesCategoryRes, | ||
} from "@medusajs/medusa" | ||
import { Response } from "@medusajs/medusa-js" | ||
import { useQuery } from "@tanstack/react-query" | ||
|
||
import { useMedusa } from "../../../contexts" | ||
import { UseQueryOptionsWrapper } from "../../../types" | ||
import { queryKeysFactory } from "../../utils" | ||
|
||
const STORE_PRODUCT_CATEGORIES_QUERY_KEY = `product_categories` as const | ||
export const storeProductCategoryKeys = queryKeysFactory( | ||
STORE_PRODUCT_CATEGORIES_QUERY_KEY | ||
) | ||
type ProductCategoryQueryKeys = typeof storeProductCategoryKeys | ||
|
||
export const useStoreProductCategories = ( | ||
query?: StoreGetProductCategoriesParams, | ||
options?: UseQueryOptionsWrapper< | ||
Response<StoreGetProductCategoriesRes>, | ||
Error, | ||
ReturnType<ProductCategoryQueryKeys["list"]> | ||
> | ||
) => { | ||
const { client } = useMedusa() | ||
const { data, ...rest } = useQuery( | ||
storeProductCategoryKeys.list(query), | ||
() => client.store.productCategories.list(query), | ||
options | ||
) | ||
return { ...data, ...rest } as const | ||
} | ||
|
||
export const useStoreProductCategory = ( | ||
id: string, | ||
query?: StoreGetProductCategoriesCategoryParams, | ||
options?: UseQueryOptionsWrapper< | ||
Response<StoreGetProductCategoriesCategoryRes>, | ||
Error, | ||
ReturnType<ProductCategoryQueryKeys["detail"]> | ||
> | ||
) => { | ||
const { client } = useMedusa() | ||
const { data, ...rest } = useQuery( | ||
storeProductCategoryKeys.detail(id), | ||
() => client.store.productCategories.retrieve(id, query), | ||
options | ||
) | ||
|
||
return { ...data, ...rest } as const | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters