29 lines
784 B
TypeScript
29 lines
784 B
TypeScript
import { makeKeysFactory } from "./../utils/index"
|
|
import { StoreCartsRes } from "@medusajs/medusa"
|
|
import { Response } from "@medusajs/medusa-js"
|
|
import { useQuery } from "react-query"
|
|
import { useMedusa } from "../../contexts/medusa"
|
|
import { UseQueryOptionsWrapper } from "../../types"
|
|
|
|
const CARTS_QUERY_KEY = `carts` as const
|
|
|
|
export const cartKeys = makeKeysFactory(CARTS_QUERY_KEY)
|
|
type CartQueryKey = typeof cartKeys
|
|
|
|
export const useGetCart = (
|
|
id: string,
|
|
options?: UseQueryOptionsWrapper<
|
|
Response<StoreCartsRes>,
|
|
Error,
|
|
ReturnType<CartQueryKey["detail"]>
|
|
>
|
|
) => {
|
|
const { client } = useMedusa()
|
|
const { data, ...rest } = useQuery(
|
|
cartKeys.detail(id),
|
|
() => client.carts.retrieve(id),
|
|
options
|
|
)
|
|
return { ...data, ...rest } as const
|
|
}
|