docs: generate medusa-react reference (#6004)

* add new plugin for better organization

* added handling in theme for mutations and query types

* added tsdoc to hooks

* added tsdocs to utility functions

* added tsdoc to providers

* generated reference

* general fixes for generated reference

* generated api reference specs + general fixes

* add missing import react

* split utilities into different directories

* added overview page

* added link to customer authentication section

* fix lint errors

* added changeset

* fix readme

* fixed build error

* added expand fields + other sections to overview

* updated what's new section

* general refactoring

* remove unnecessary query field

* fix links

* added ignoreApi option
This commit is contained in:
Shahed Nasser
2024-01-05 17:03:38 +02:00
committed by GitHub
parent 6fc6a9de6a
commit 7d650771d1
2811 changed files with 231856 additions and 455063 deletions
@@ -0,0 +1,124 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/auth
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Auth
Queries and mutations listed here are used to send requests to the [Admin Auth API Routes](https://docs.medusajs.com/api/admin#auth\_getauth).
They allow admin users to manage their session, such as login or log out.
You can send authenticated requests for an admin user either using the Cookie header, their API token, or the JWT Token.
When you log the admin user in using the [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin) hook, Medusa React will automatically attach the
cookie header in all subsequent requests.
Related Guide: [How to implement user profiles](https://docs.medusajs.com/modules/users/admin/manage-profile).
## Mutations
### useAdminLogin
This hook is used to log a User in using their credentials. If the user is authenticated successfully,
the cookie is automatically attached to subsequent requests sent with other hooks.
#### Example
```ts
import React from "react"
import { useAdminLogin } from "medusa-react"
const Login = () => {
const adminLogin = useAdminLogin()
// ...
const handleLogin = () => {
adminLogin.mutate({
email: "user@example.com",
password: "supersecret",
}, {
onSuccess: ({ user }) => {
console.log(user)
}
})
}
// ...
}
export default Login
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminPostAuthReq","type":"[AdminPostAuthReq](../../../medusa/classes/medusa.AdminPostAuthReq.mdx)","optional":false,"defaultValue":"","description":"The admin's credentials used to log in.","expandable":false,"children":[{"name":"email","type":"`string`","description":"The user's email.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"password","type":"`string`","description":"The user's password.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminAuthRes","type":"[AdminAuthRes](../../../medusa/types/medusa.AdminAuthRes.mdx)","optional":false,"defaultValue":"","description":"The user's details.","expandable":false,"children":[{"name":"user","type":"Omit&#60;[User](../../../entities/classes/entities.User.mdx), \"password_hash\"&#62;","description":"User details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"api_token","type":"`string`","description":"An API token associated with the user.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The email of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The first name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The user's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The last name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRoles](../../../entities/enums/entities.UserRoles.mdx)","description":"The user's role. These roles don't provide any different privileges.","optional":false,"defaultValue":"member","expandable":false,"children":[{"name":"ADMIN","type":"`\"admin\"`","description":"The user is an admin.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DEVELOPER","type":"`\"developer\"`","description":"The user is a developer.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"MEMBER","type":"`\"member\"`","description":"The user is a team member.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminDeleteSession
This hook is used to Log out the user and remove their authentication session. This will only work if you're using Cookie session for authentication. If the API token is still passed in the header,
the user is still authorized to perform admin functionalities in other API Routes.
This hook requires [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
#### Example
```ts
import React from "react"
import { useAdminDeleteSession } from "medusa-react"
const Logout = () => {
const adminLogout = useAdminDeleteSession()
// ...
const handleLogout = () => {
adminLogout.mutate(undefined, {
onSuccess: () => {
// user logged out.
}
})
}
// ...
}
export default Logout
```
___
## Queries
### useAdminGetSession
This hook is used to get the currently logged in user's details. Can also be used to check if there is an authenticated user.
This hook requires [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
#### Example
```ts
import React from "react"
import { useAdminGetSession } from "medusa-react"
const Profile = () => {
const { user, isLoading } = useAdminGetSession()
return (
<div>
{isLoading && <span>Loading...</span>}
{user && <span>{user.email}</span>}
</div>
)
}
export default Profile
```
#### Query Returned Data
<ParameterTypes parameters={[{"name":"user","type":"Omit&#60;[User](../../../entities/classes/entities.User.mdx), \"password_hash\"&#62;","description":"User details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"api_token","type":"`string`","description":"An API token associated with the user.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The email of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The first name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The user's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The last name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRoles](../../../entities/enums/entities.UserRoles.mdx)","description":"The user's role. These roles don't provide any different privileges.","optional":false,"defaultValue":"member","expandable":false,"children":[{"name":"ADMIN","type":"`\"admin\"`","description":"The user is an admin.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DEVELOPER","type":"`\"developer\"`","description":"The user is a developer.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"MEMBER","type":"`\"member\"`","description":"The user is a team member.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,145 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/currencies
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Currencies
Queries and Mutations listed here are used to send requests to the [Admin Currency API Routes](https://docs.medusajs.com/api/admin#currencies).
All hooks listed require [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
A store can use unlimited currencies, and each region must be associated with at least one currency.
Currencies are defined within the Medusa backend. The methods in this class allow admins to list and update currencies.
Related Guide: [How to manage currencies](https://docs.medusajs.com/modules/regions-and-currencies/admin/manage-currencies).
## Mutations
### useAdminUpdateCurrency
This hook updates a currency's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateCurrency } from "medusa-react"
type Props = {
currencyCode: string
}
const Currency = ({ currencyCode }: Props) => {
const updateCurrency = useAdminUpdateCurrency(currencyCode)
// ...
const handleUpdate = (includes_tax: boolean) => {
updateCurrency.mutate({
includes_tax,
}, {
onSuccess: ({ currency }) => {
console.log(currency)
}
})
}
// ...
}
export default Currency
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"code","type":"`string`","description":"The currency's code.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminPostCurrenciesCurrencyReq","type":"[AdminPostCurrenciesCurrencyReq](../../../medusa/classes/medusa.AdminPostCurrenciesCurrencyReq.mdx)","optional":false,"defaultValue":"","description":"The details to update in the currency","expandable":false,"children":[{"name":"includes_tax","type":"`boolean`","description":"Tax included in prices of currency.","optional":true,"defaultValue":"","expandable":false,"featureFlag":"tax_inclusive_pricing","children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminCurrenciesRes","type":"[AdminCurrenciesRes](../../../medusa/types/medusa.AdminCurrenciesRes.mdx)","optional":false,"defaultValue":"","description":"A currency's details.","expandable":false,"children":[{"name":"currency","type":"[Currency](../../../entities/classes/entities.Currency.mdx)","description":"Currency details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The 3 character ISO code for the currency.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The written name of the currency","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"symbol","type":"`string`","description":"The symbol used to indicate the currency.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"symbol_native","type":"`string`","description":"The native symbol used to indicate the currency.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"includes_tax","type":"`boolean`","description":"Whether the currency prices include tax","optional":true,"defaultValue":"false","expandable":false,"featureFlag":"tax_inclusive_pricing","children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
___
## Queries
### useAdminCurrencies
This hook retrieves a list of currencies. The currencies can be filtered by fields such as `code`.
The currencies can also be sorted or paginated.
#### Example
To list currencies:
```ts
import React from "react"
import { useAdminCurrencies } from "medusa-react"
const Currencies = () => {
const { currencies, isLoading } = useAdminCurrencies()
return (
<div>
{isLoading && <span>Loading...</span>}
{currencies && !currencies.length && (
<span>No Currencies</span>
)}
{currencies && currencies.length > 0 && (
<ul>
{currencies.map((currency) => (
<li key={currency.code}>{currency.name}</li>
))}
</ul>
)}
</div>
)
}
export default Currencies
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```ts
import React from "react"
import { useAdminCurrencies } from "medusa-react"
const Currencies = () => {
const { currencies, limit, offset, isLoading } = useAdminCurrencies({
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{currencies && !currencies.length && (
<span>No Currencies</span>
)}
{currencies && currencies.length > 0 && (
<ul>
{currencies.map((currency) => (
<li key={currency.code}>{currency.name}</li>
))}
</ul>
)}
</div>
)
}
export default Currencies
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"query","type":"[AdminGetCurrenciesParams](../../../medusa/classes/medusa.AdminGetCurrenciesParams.mdx)","description":"Filters and pagination configurations to apply on retrieved currencies.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"Code to filter currencies by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"includes_tax","type":"`boolean`","description":"Filter currencies by whether they include tax.","optional":true,"defaultValue":"","expandable":false,"featureFlag":"tax_inclusive_pricing","children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.\nBy default, the returned currencies will be sorted by their `created_at` field.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currencies","type":"[Currency](../../../entities/classes/entities.Currency.mdx)[]","description":"An array of currency details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"code","type":"`string`","description":"The 3 character ISO code for the currency.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The written name of the currency","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"symbol","type":"`string`","description":"The symbol used to indicate the currency.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"symbol_native","type":"`string`","description":"The native symbol used to indicate the currency.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"includes_tax","type":"`boolean`","description":"Whether the currency prices include tax","optional":true,"defaultValue":"false","expandable":false,"featureFlag":"tax_inclusive_pricing","children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
@@ -0,0 +1,181 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/custom
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Custom
This class is used to send requests custom API Routes. All its method
are available in the JS Client under the `medusa.admin.custom` property.
## Mutations
### useAdminCustomDelete
This hook sends a `DELETE` request to a custom API Route.
#### Example
```ts
import React from "react"
import { useAdminCustomDelete } from "medusa-react"
type Props = {
customId: string
}
const Custom = ({ customId }: Props) => {
const customDelete = useAdminCustomDelete(
`/blog/posts/${customId}`,
["posts"]
)
// ...
const handleAction = (title: string) => {
customDelete.mutate(void 0, {
onSuccess: () => {
// Delete action successful
}
})
}
// ...
}
export default Custom
```
#### Type Parameters
<ParameterTypes parameters={[{"name":"TResponse","type":"`object`","description":"The response's type which defaults to `any`.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Hook Parameters
<ParameterTypes parameters={[{"name":"path","type":"`string`","description":"The path to the custom endpoint.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"queryKey","type":"`QueryKey`","description":"A list of query keys, used to invalidate data.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"relatedDomains","type":"`RelatedDomains`","description":"A list of related domains that should be invalidated and refetch when the mutation\nfunction is invoked.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"TResponse","type":"`TResponse`","optional":false,"defaultValue":"","description":"The response based on the type provided for ","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminCustomPost
This hook sends a `POST` request to a custom API Route.
#### Example
```ts
import React from "react"
import { useAdminCustomPost } from "medusa-react"
import Post from "./models/Post"
type PostRequest = {
title: string
}
type PostResponse = {
post: Post
}
const Custom = () => {
const customPost = useAdminCustomPost
<PostRequest, PostResponse>(
"/blog/posts",
["posts"]
)
// ...
const handleAction = (title: string) => {
customPost.mutate({
title
}, {
onSuccess: ({ post }) => {
console.log(post)
}
})
}
// ...
}
export default Custom
```
#### Type Parameters
<ParameterTypes parameters={[{"name":"TPayload","type":"`Record<string, any>`","description":"The type of accepted body parameters which defaults to `Record<string, any>`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TResponse","type":"`object`","description":"The type of response, which defaults to `any`.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Hook Parameters
<ParameterTypes parameters={[{"name":"path","type":"`string`","description":"The path to the custom endpoint.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"queryKey","type":"`QueryKey`","description":"A list of query keys, used to invalidate data.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"relatedDomains","type":"`RelatedDomains`","description":"A list of related domains that should be invalidated and refetch when the mutation\nfunction is invoked.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"TPayload","type":"`TPayload`","optional":false,"defaultValue":"","description":"The payload based on the specified type for ","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"TResponse","type":"`TResponse`","optional":false,"defaultValue":"","description":"The response based on the specified type for ","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminCustomQuery
This hook sends a `GET` request to a custom API Route.
#### Example
```ts
import React from "react"
import { useAdminCustomQuery } from "medusa-react"
import Post from "./models/Post"
type RequestQuery = {
title: string
}
type ResponseData = {
posts: Post
}
const Custom = () => {
const { data, isLoading } = useAdminCustomQuery
<RequestQuery, ResponseData>(
"/blog/posts",
["posts"],
{
title: "My post"
}
)
return (
<div>
{isLoading && <span>Loading...</span>}
{data?.posts && !data.posts.length && (
<span>No Post</span>
)}
{data?.posts && data.posts?.length > 0 && (
<ul>
{data.posts.map((post) => (
<li key={post.id}>{post.title}</li>
))}
</ul>
)}
</div>
)
}
export default Custom
```
#### Type Parameters
<ParameterTypes parameters={[{"name":"TQuery","type":"`Record<string, any>`","description":"The type of accepted query parameters which defaults to `Record<string, any>`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TResponse","type":"`object`","description":"The type of response which defaults to `any`.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Hook Parameters
<ParameterTypes parameters={[{"name":"path","type":"`string`","description":"The path to the custom endpoint.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"queryKey","type":"`QueryKey`","description":"A list of query keys, used to invalidate data.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"`TQuery`","description":"Query parameters to pass to the request.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"TResponse","type":"`TResponse`","optional":false,"defaultValue":"","description":"The response based on the type specified for ","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,182 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/invites
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Invites
Queries and Mutations listed here are used to send requests to the [Admin Invite API Routes](https://docs.medusajs.com/api/admin#invites).
All hooks listed require [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
An admin can invite new users to manage their team. This would allow new users to authenticate as admins and perform admin functionalities.
Related Guide: [How to manage invites](https://docs.medusajs.com/modules/users/admin/manage-invites).
## Mutations
### useAdminAcceptInvite
This hook accepts an Invite. This will also delete the invite and create a new user that can log in and perform admin functionalities.
The user will have the email associated with the invite, and the password provided in the mutation function's parameter.
#### Example
```ts
import React from "react"
import { useAdminAcceptInvite } from "medusa-react"
const AcceptInvite = () => {
const acceptInvite = useAdminAcceptInvite()
// ...
const handleAccept = (
token: string,
firstName: string,
lastName: string,
password: string
) => {
acceptInvite.mutate({
token,
user: {
first_name: firstName,
last_name: lastName,
password,
},
}, {
onSuccess: () => {
// invite accepted successfully.
}
})
}
// ...
}
export default AcceptInvite
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminPostInvitesInviteAcceptReq","type":"[AdminPostInvitesInviteAcceptReq](../../../medusa/classes/medusa.AdminPostInvitesInviteAcceptReq.mdx)","optional":false,"defaultValue":"","description":"The details of the invite to be accepted.","expandable":false,"children":[{"name":"token","type":"`string`","description":"The token of the invite to accept. This is a unique token generated when the invite was created or resent.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"user","type":"[AdminPostInvitesInviteAcceptUserReq](../../../medusa/classes/medusa.AdminPostInvitesInviteAcceptUserReq.mdx)","description":"The details of the user to create.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"first_name","type":"`string`","description":"The invite's first name.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The invite's last name.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"password","type":"`string`","description":"The invite's password","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminResendInvite
This hook resends an invite. This renews the expiry date by seven days and generates a new token for the invite. It also triggers the `invite.created` event,
so if you have a Notification Provider installed that handles this event, a notification should be sent to the email associated with the
invite to allow them to accept the invite.
#### Example
```ts
import React from "react"
import { useAdminResendInvite } from "medusa-react"
type Props = {
inviteId: string
}
const ResendInvite = ({ inviteId }: Props) => {
const resendInvite = useAdminResendInvite(inviteId)
// ...
const handleResend = () => {
resendInvite.mutate(void 0, {
onSuccess: () => {
// invite resent successfully
}
})
}
// ...
}
export default ResendInvite
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The invite's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminDeleteInvite
This hook deletes an invite. Only invites that weren't accepted can be deleted.
#### Example
```ts
import React from "react"
import { useAdminDeleteInvite } from "medusa-react"
type Props = {
inviteId: string
}
const DeleteInvite = ({ inviteId }: Props) => {
const deleteInvite = useAdminDeleteInvite(inviteId)
// ...
const handleDelete = () => {
deleteInvite.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default Invite
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The invite's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../medusa/interfaces/medusa.DeleteResponse.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
___
## Queries
### useAdminInvites
This hook retrieves a list of invites.
#### Example
```ts
import React from "react"
import { useAdminInvites } from "medusa-react"
const Invites = () => {
const { invites, isLoading } = useAdminInvites()
return (
<div>
{isLoading && <span>Loading...</span>}
{invites && !invites.length && (
<span>No Invites</span>)
}
{invites && invites.length > 0 && (
<ul>
{invites.map((invite) => (
<li key={invite.id}>{invite.user_email}</li>
))}
</ul>
)}
</div>
)
}
export default Invites
```
#### Query Returned Data
<ParameterTypes parameters={[{"name":"invites","type":"[Invite](../../../entities/classes/entities.Invite.mdx)[]","description":"An array of invites","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"accepted","type":"`boolean`","description":"Whether the invite was accepted or not.","optional":false,"defaultValue":"false","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"expires_at","type":"`Date`","description":"The date the invite expires at.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The invite's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRoles](../../../entities/enums/entities.UserRoles.mdx)","description":"The user's role. These roles don't change the privileges of the user.","optional":false,"defaultValue":"member","expandable":false,"children":[{"name":"ADMIN","type":"`\"admin\"`","description":"The user is an admin.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DEVELOPER","type":"`\"developer\"`","description":"The user is a developer.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"MEMBER","type":"`\"member\"`","description":"The user is a team member.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"token","type":"`string`","description":"The token used to accept the invite.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"user_email","type":"`string`","description":"The email of the user being invited.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
@@ -0,0 +1,257 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/notes
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Notes
Queries and Mutations listed here are used to send requests to the [Admin Note API Routes](https://docs.medusajs.com/api/admin#notes).
All hooks listed require [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
Notes are created by admins and can be associated with any resource. For example, an admin can add a note to an order for additional details or remarks.
## Mutations
### useAdminCreateNote
This hook creates a Note which can be associated with any resource.
#### Example
```ts
import React from "react"
import { useAdminCreateNote } from "medusa-react"
const CreateNote = () => {
const createNote = useAdminCreateNote()
// ...
const handleCreate = () => {
createNote.mutate({
resource_id: "order_123",
resource_type: "order",
value: "We delivered this order"
}, {
onSuccess: ({ note }) => {
console.log(note.id)
}
})
}
// ...
}
export default CreateNote
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminPostNotesReq","type":"[AdminPostNotesReq](../../../medusa/classes/medusa.AdminPostNotesReq.mdx)","optional":false,"defaultValue":"","description":"The details of the note to be created.","expandable":false,"children":[{"name":"resource_id","type":"`string`","description":"The ID of the resource which the Note relates to. For example, an order ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"resource_type","type":"`string`","description":"The type of resource which the Note relates to. For example, `order`.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The content of the Note to create.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminNotesRes","type":"[AdminNotesRes](../../../medusa/types/medusa.AdminNotesRes.mdx)","optional":false,"defaultValue":"","description":"The note's details.","expandable":false,"children":[{"name":"note","type":"[Note](../../../entities/classes/entities.Note.mdx)","description":"Note details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"author","type":"[User](../../../entities/classes/entities.User.mdx)","description":"The details of the user that created the note.","optional":false,"defaultValue":"","expandable":true,"children":[{"name":"api_token","type":"`string`","description":"An API token associated with the user.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The email of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The first name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The user's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The last name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"password_hash","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRoles](../../../entities/enums/entities.UserRoles.mdx)","description":"The user's role. These roles don't provide any different privileges.","optional":false,"defaultValue":"member","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"author_id","type":"`string`","description":"The ID of the user that created the note.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The note's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"resource_id","type":"`string`","description":"The ID of the resource that the Note refers to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"resource_type","type":"`string`","description":"The type of resource that the Note refers to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The contents of the note.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminUpdateNote
This hook updates a Note's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateNote } from "medusa-react"
type Props = {
noteId: string
}
const Note = ({ noteId }: Props) => {
const updateNote = useAdminUpdateNote(noteId)
// ...
const handleUpdate = (
value: string
) => {
updateNote.mutate({
value
}, {
onSuccess: ({ note }) => {
console.log(note.value)
}
})
}
// ...
}
export default Note
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The note's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminPostNotesNoteReq","type":"[AdminPostNotesNoteReq](../../../medusa/classes/medusa.AdminPostNotesNoteReq.mdx)","optional":false,"defaultValue":"","description":"The details to update of the note.","expandable":false,"children":[{"name":"value","type":"`string`","description":"The description of the Note.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminNotesRes","type":"[AdminNotesRes](../../../medusa/types/medusa.AdminNotesRes.mdx)","optional":false,"defaultValue":"","description":"The note's details.","expandable":false,"children":[{"name":"note","type":"[Note](../../../entities/classes/entities.Note.mdx)","description":"Note details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"author","type":"[User](../../../entities/classes/entities.User.mdx)","description":"The details of the user that created the note.","optional":false,"defaultValue":"","expandable":true,"children":[{"name":"api_token","type":"`string`","description":"An API token associated with the user.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The email of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The first name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The user's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The last name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"password_hash","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRoles](../../../entities/enums/entities.UserRoles.mdx)","description":"The user's role. These roles don't provide any different privileges.","optional":false,"defaultValue":"member","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"author_id","type":"`string`","description":"The ID of the user that created the note.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The note's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"resource_id","type":"`string`","description":"The ID of the resource that the Note refers to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"resource_type","type":"`string`","description":"The type of resource that the Note refers to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The contents of the note.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminDeleteNote
This hook deletes a Note.
#### Example
```ts
import React from "react"
import { useAdminDeleteNote } from "medusa-react"
type Props = {
noteId: string
}
const Note = ({ noteId }: Props) => {
const deleteNote = useAdminDeleteNote(noteId)
// ...
const handleDelete = () => {
deleteNote.mutate()
}
// ...
}
export default Note
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The note's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../medusa/interfaces/medusa.DeleteResponse.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
___
## Queries
### useAdminNotes
This hook retrieves a list of notes. The notes can be filtered by fields such as `resource_id` passed in
the `query` parameter. The notes can also be paginated.
#### Example
To list notes:
```tsx
import React from "react"
import { useAdminNotes } from "medusa-react"
const Notes = () => {
const { notes, isLoading } = useAdminNotes()
return (
<div>
{isLoading && <span>Loading...</span>}
{notes && !notes.length && <span>No Notes</span>}
{notes && notes.length > 0 && (
<ul>
{notes.map((note) => (
<li key={note.id}>{note.resource_type}</li>
))}
</ul>
)}
</div>
)
}
export default Notes
```
By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminNotes } from "medusa-react"
const Notes = () => {
const {
notes,
limit,
offset,
isLoading
} = useAdminNotes({
limit: 40,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{notes && !notes.length && <span>No Notes</span>}
{notes && notes.length > 0 && (
<ul>
{notes.map((note) => (
<li key={note.id}>{note.resource_type}</li>
))}
</ul>
)}
</div>
)
}
export default Notes
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"query","type":"[AdminGetNotesParams](../../../medusa/classes/medusa.AdminGetNotesParams.mdx)","description":"Filters and pagination configurations applied on retrieved notes.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":false,"defaultValue":"50","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"resource_id","type":"`string`","description":"Resource ID to filter notes by.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"notes","type":"[Note](../../../entities/classes/entities.Note.mdx)[]","description":"An array of notes","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"author","type":"[User](../../../entities/classes/entities.User.mdx)","description":"The details of the user that created the note.","optional":false,"defaultValue":"","expandable":true,"children":[{"name":"api_token","type":"`string`","description":"An API token associated with the user.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The email of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The first name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The user's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The last name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"password_hash","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRoles](../../../entities/enums/entities.UserRoles.mdx)","description":"The user's role. These roles don't provide any different privileges.","optional":false,"defaultValue":"member","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"author_id","type":"`string`","description":"The ID of the user that created the note.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The note's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"resource_id","type":"`string`","description":"The ID of the resource that the Note refers to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"resource_type","type":"`string`","description":"The type of resource that the Note refers to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The contents of the note.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminNote
This hook retrieves a note's details.
#### Example
```ts
import React from "react"
import { useAdminNote } from "medusa-react"
type Props = {
noteId: string
}
const Note = ({ noteId }: Props) => {
const { note, isLoading } = useAdminNote(noteId)
return (
<div>
{isLoading && <span>Loading...</span>}
{note && <span>{note.resource_type}</span>}
</div>
)
}
export default Note
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The note's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"note","type":"[Note](../../../entities/classes/entities.Note.mdx)","description":"Note details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"author","type":"[User](../../../entities/classes/entities.User.mdx)","description":"The details of the user that created the note.","optional":false,"defaultValue":"","expandable":true,"children":[{"name":"api_token","type":"`string`","description":"An API token associated with the user.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The email of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The first name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The user's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The last name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"password_hash","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRoles](../../../entities/enums/entities.UserRoles.mdx)","description":"The user's role. These roles don't provide any different privileges.","optional":false,"defaultValue":"member","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"author_id","type":"`string`","description":"The ID of the user that created the note.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The note's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"resource_id","type":"`string`","description":"The ID of the resource that the Note refers to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"resource_type","type":"`string`","description":"The type of resource that the Note refers to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The contents of the note.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,105 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/product_tags
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Product Tags
Queries and Mutations listed here are used to send requests to the [Admin Product Tag API Routes](https://docs.medusajs.com/api/admin#product-tags).
All hooks listed require [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
Product tags are string values created when you create or update a product with a new tag.
Products can have more than one tag, and products can share tags. This allows admins to associate products to similar tags that can be used to filter products.
## Queries
### useAdminProductTags
This hook retrieves a list of product tags. The product tags can be filtered by fields such as `q` or `value` passed
in the `query` parameter. The product tags can also be sorted or paginated.
#### Example
To list product tags:
```tsx
import React from "react"
import { useAdminProductTags } from "medusa-react"
function ProductTags() {
const {
product_tags,
isLoading
} = useAdminProductTags()
return (
<div>
{isLoading && <span>Loading...</span>}
{product_tags && !product_tags.length && (
<span>No Product Tags</span>
)}
{product_tags && product_tags.length > 0 && (
<ul>
{product_tags.map(
(tag) => (
<li key={tag.id}>{tag.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default ProductTags
```
By default, only the first `10` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminProductTags } from "medusa-react"
function ProductTags() {
const {
product_tags,
limit,
offset,
isLoading
} = useAdminProductTags({
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_tags && !product_tags.length && (
<span>No Product Tags</span>
)}
{product_tags && product_tags.length > 0 && (
<ul>
{product_tags.map(
(tag) => (
<li key={tag.id}>{tag.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default ProductTags
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"query","type":"[AdminGetProductTagsParams](../../../medusa/classes/medusa.AdminGetProductTagsParams.mdx)","description":"Filters and pagination configurations to apply on the retrieved product tags.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":false,"defaultValue":"10","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":false,"defaultValue":"0","expandable":false,"children":[]},{"name":"created_at","type":"[DateComparisonOperator](../../../medusa/classes/medusa.DateComparisonOperator.mdx)","description":"Date filters to apply on the product tags' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"discount_condition_id","type":"`string`","description":"Filter product tags by their associated discount condition's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../medusa/classes/medusa.StringComparisonOperator.mdx)","description":"IDs to filter product tags by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search product tags' value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"[DateComparisonOperator](../../../medusa/classes/medusa.DateComparisonOperator.mdx)","description":"Date filters to apply on the product tags' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"value","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../medusa/classes/medusa.StringComparisonOperator.mdx)","description":"Values to search product tags by.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_tags","type":"[ProductTag](../../../entities/classes/entities.ProductTag.mdx)[]","description":"An array of product tag details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The product tag's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value that the Product Tag represents","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
@@ -0,0 +1,105 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/product_types
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Product Types
Queries and Mutations listed here are used to send requests to the [Admin Product Type API Routes](https://docs.medusajs.com/api/admin#product-types).
All hooks listed require [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
Product types are string values created when you create or update a product with a new type.
Products can have one type, and products can share types. This allows admins to associate products with a type that can be used to filter products.
## Queries
### useAdminProductTypes
This hook retrieves a list of product types. The product types can be filtered by fields such as `q` or `value` passed in the `query` parameter.
The product types can also be sorted or paginated.
#### Example
To list product types:
```tsx
import React from "react"
import { useAdminProductTypes } from "medusa-react"
function ProductTypes() {
const {
product_types,
isLoading
} = useAdminProductTypes()
return (
<div>
{isLoading && <span>Loading...</span>}
{product_types && !product_types.length && (
<span>No Product Tags</span>
)}
{product_types && product_types.length > 0 && (
<ul>
{product_types.map(
(type) => (
<li key={type.id}>{type.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default ProductTypes
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminProductTypes } from "medusa-react"
function ProductTypes() {
const {
product_types,
limit,
offset,
isLoading
} = useAdminProductTypes({
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_types && !product_types.length && (
<span>No Product Tags</span>
)}
{product_types && product_types.length > 0 && (
<ul>
{product_types.map(
(type) => (
<li key={type.id}>{type.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default ProductTypes
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"query","type":"[AdminGetProductTypesParams](../../../medusa/classes/medusa.AdminGetProductTypesParams.mdx)","description":"Filters and pagination configurations to apply on the retrieved product types.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"[DateComparisonOperator](../../../medusa/classes/medusa.DateComparisonOperator.mdx)","description":"Date filters to apply on the product types' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"discount_condition_id","type":"`string`","description":"Filter product types by their associated discount condition's ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../medusa/classes/medusa.StringComparisonOperator.mdx)","description":"IDs to filter product types by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search terms to search product types' value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"[DateComparisonOperator](../../../medusa/classes/medusa.DateComparisonOperator.mdx)","description":"Date filters to apply on the product types' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"value","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../medusa/classes/medusa.StringComparisonOperator.mdx)","description":"Values to filter product types by.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_types","type":"[ProductType](../../../entities/classes/entities.ProductType.mdx)[]","description":"An array of product types details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The product type's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value that the Product Type represents.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
@@ -0,0 +1,246 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/product_variants
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Product Variants
Queries listed here are used to send requests to the [Admin Product Variant API Routes](https://docs.medusajs.com/api/admin#product-variants).
All hooks listed require [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
Product variants are the actual salable item in your store. Each variant is a combination of the different option values available on the product.
Related Guide: [How to manage product variants](https://docs.medusajs.com/modules/products/admin/manage-products#manage-product-variants).
## Queries
### useAdminVariants
This hook retrieves a list of product variants. The product variant can be filtered by fields such as `id` or `title`
passed in the `query` parameter. The product variant can also be paginated.
#### Example
To list product variants:
```tsx
import React from "react"
import { useAdminVariants } from "medusa-react"
const Variants = () => {
const { variants, isLoading } = useAdminVariants()
return (
<div>
{isLoading && <span>Loading...</span>}
{variants && !variants.length && (
<span>No Variants</span>
)}
{variants && variants.length > 0 && (
<ul>
{variants.map((variant) => (
<li key={variant.id}>{variant.title}</li>
))}
</ul>
)}
</div>
)
}
export default Variants
```
To specify relations that should be retrieved within the product variants:
```tsx
import React from "react"
import { useAdminVariants } from "medusa-react"
const Variants = () => {
const { variants, isLoading } = useAdminVariants({
expand: "options"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{variants && !variants.length && (
<span>No Variants</span>
)}
{variants && variants.length > 0 && (
<ul>
{variants.map((variant) => (
<li key={variant.id}>{variant.title}</li>
))}
</ul>
)}
</div>
)
}
export default Variants
```
By default, only the first `100` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminVariants } from "medusa-react"
const Variants = () => {
const {
variants,
limit,
offset,
isLoading
} = useAdminVariants({
expand: "options",
limit: 50,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{variants && !variants.length && (
<span>No Variants</span>
)}
{variants && variants.length > 0 && (
<ul>
{variants.map((variant) => (
<li key={variant.id}>{variant.title}</li>
))}
</ul>
)}
</div>
)
}
export default Variants
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"query","type":"[AdminGetVariantsParams](../../../medusa/classes/medusa.AdminGetVariantsParams.mdx)","description":"Filters and pagination configurations to apply on the retrieved product variants.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"cart_id","type":"`string`","description":"Retrieve prices for a cart ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"`string`","description":"Retrieve prices for a currency code.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"customer_id","type":"`string`","description":"Retrieve prices for a customer ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[]","description":"IDs to filter product variants by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_quantity","type":"`number` \\| [NumericalComparisonOperator](../../../medusa/classes/medusa.NumericalComparisonOperator.mdx)","description":"Number filters to apply on product variants' `inventory_quantity` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search product variants' IDs.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"Retrieve prices for a region ID.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"title","type":"`string` \\| `string`[]","description":"Titles to filter product variants by.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"variants","type":"[PricedVariant](../../../medusa/types/medusa.PricedVariant.mdx)[]","description":"An array of product variant details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminVariant
This hook retrieves a product variant's details.
#### Example
A simple example that retrieves a product variant by its ID:
```tsx
import React from "react"
import { useAdminVariant } from "medusa-react"
type Props = {
variantId: string
}
const Variant = ({ variantId }: Props) => {
const { variant, isLoading } = useAdminVariant(
variantId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{variant && <span>{variant.title}</span>}
</div>
)
}
export default Variant
```
To specify relations that should be retrieved:
```tsx
import React from "react"
import { useAdminVariant } from "medusa-react"
type Props = {
variantId: string
}
const Variant = ({ variantId }: Props) => {
const { variant, isLoading } = useAdminVariant(
variantId, {
expand: "options"
}
)
return (
<div>
{isLoading && <span>Loading...</span>}
{variant && <span>{variant.title}</span>}
</div>
)
}
export default Variant
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The product variant's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"query","type":"[AdminGetVariantParams](../../../medusa/classes/medusa.AdminGetVariantParams.mdx)","description":"Configurations to apply on the retrieved product variant.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"variant","type":"[PricedVariant](../../../medusa/types/medusa.PricedVariant.mdx)","description":"Product variant's details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminVariantsInventory
This hook retrieves the available inventory of a product variant.
#### Example
```ts
import React from "react"
import { useAdminVariantsInventory } from "medusa-react"
type Props = {
variantId: string
}
const VariantInventory = ({ variantId }: Props) => {
const { variant, isLoading } = useAdminVariantsInventory(
variantId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{variant && variant.inventory.length === 0 && (
<span>Variant doesn't have inventory details</span>
)}
{variant && variant.inventory.length > 0 && (
<ul>
{variant.inventory.map((inventory) => (
<li key={inventory.id}>{inventory.title}</li>
))}
</ul>
)}
</div>
)
}
export default VariantInventory
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The product variant's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"variant","type":"[VariantInventory](../../../medusa/types/medusa.VariantInventory.mdx)","description":"The product variant's inventory details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"the ID of the variant","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory","type":"[ResponseInventoryItem](../../../medusa/types/medusa.ResponseInventoryItem.mdx)[]","description":"The inventory details.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channel_availability","type":"`object`[]","description":"Details about the variant's inventory availability in sales channels.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"available_quantity","type":"`number`","description":"Available quantity in the sales channel","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"channel_id","type":"`string`","description":"Sales channel's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"channel_name","type":"`string`","description":"Sales channel's name","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,314 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/reservations
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Reservations
Queries and Mutations listed here are used to send requests to the [Admin Reservation API Routes](https://docs.medusajs.com/api/admin#reservations).
To use these hooks, make sure to install the
[@medusajs/inventory](https://docs.medusajs.com/modules/multiwarehouse/install-modules#inventory-module) module in your Medusa backend.
All hooks listed require [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
Reservations, provided by the [Inventory Module](https://docs.medusajs.com/modules/multiwarehouse/inventory-module),
are quantities of an item that are reserved, typically when an order is placed but not yet fulfilled.
Reservations can be associated with any resources, but commonly with line items of an order.
Related Guide: [How to manage item allocations in orders](https://docs.medusajs.com/modules/multiwarehouse/admin/manage-item-allocations-in-orders).
## Mutations
### useAdminCreateReservation
This hook creates a reservation which can be associated with any resource, such as an order's line item.
#### Example
```ts
import React from "react"
import { useAdminCreateReservation } from "medusa-react"
const CreateReservation = () => {
const createReservation = useAdminCreateReservation()
// ...
const handleCreate = (
locationId: string,
inventoryItemId: string,
quantity: number
) => {
createReservation.mutate({
location_id: locationId,
inventory_item_id: inventoryItemId,
quantity,
}, {
onSuccess: ({ reservation }) => {
console.log(reservation.id)
}
})
}
// ...
}
export default CreateReservation
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminPostReservationsReq","type":"[AdminPostReservationsReq](../../../medusa/classes/medusa.AdminPostReservationsReq.mdx)","optional":false,"defaultValue":"","description":"The details of the reservation to create.","expandable":false,"children":[{"name":"inventory_item_id","type":"`string`","description":"The ID of the inventory item the reservation is associated with.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The ID of the location of the reservation.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity to reserve.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The reservation's description.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"line_item_id","type":"`string`","description":"The ID of the line item of the reservation.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminReservationsRes","type":"[AdminReservationsRes](../../../medusa/types/medusa.AdminReservationsRes.mdx)","optional":false,"defaultValue":"","description":"The reservation's details.","expandable":false,"children":[{"name":"reservation","type":"[ReservationItemDTO](../../../medusa/types/medusa.ReservationItemDTO.mdx)","description":"Reservation details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`","description":"The id of the inventory item the reservation relates to","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The id of the location of the reservation","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`string` \\| `null`","description":"UserId of user who created the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"line_item_id","type":"`string` \\| `null`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminUpdateReservation
This hook updates a reservation's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateReservation } from "medusa-react"
type Props = {
reservationId: string
}
const Reservation = ({ reservationId }: Props) => {
const updateReservation = useAdminUpdateReservation(
reservationId
)
// ...
const handleUpdate = (
quantity: number
) => {
updateReservation.mutate({
quantity,
})
}
// ...
}
export default Reservation
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The reservation's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminPostReservationsReservationReq","type":"[AdminPostReservationsReservationReq](../../../medusa/classes/medusa.AdminPostReservationsReservationReq.mdx)","optional":false,"defaultValue":"","description":"The details to update of the reservation.","expandable":false,"children":[{"name":"description","type":"`string`","description":"The reservation's description.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The ID of the location associated with the reservation.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The quantity to reserve.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminReservationsRes","type":"[AdminReservationsRes](../../../medusa/types/medusa.AdminReservationsRes.mdx)","optional":false,"defaultValue":"","description":"The reservation's details.","expandable":false,"children":[{"name":"reservation","type":"[ReservationItemDTO](../../../medusa/types/medusa.ReservationItemDTO.mdx)","description":"Reservation details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`","description":"The id of the inventory item the reservation relates to","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The id of the location of the reservation","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`string` \\| `null`","description":"UserId of user who created the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"line_item_id","type":"`string` \\| `null`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminDeleteReservation
This hook deletes a reservation. Associated resources, such as the line item, will not be deleted.
#### Example
```ts
import React from "react"
import { useAdminDeleteReservation } from "medusa-react"
type Props = {
reservationId: string
}
const Reservation = ({ reservationId }: Props) => {
const deleteReservation = useAdminDeleteReservation(
reservationId
)
// ...
const handleDelete = () => {
deleteReservation.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default Reservation
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The reservation's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../medusa/interfaces/medusa.DeleteResponse.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
___
## Queries
### useAdminReservations
This hook retrieves a list of reservations. The reservations can be filtered by fields such as `location_id` or `quantity`
passed in the `query` parameter. The reservations can also be paginated.
#### Example
To list reservations:
```tsx
import React from "react"
import { useAdminReservations } from "medusa-react"
const Reservations = () => {
const { reservations, isLoading } = useAdminReservations()
return (
<div>
{isLoading && <span>Loading...</span>}
{reservations && !reservations.length && (
<span>No Reservations</span>
)}
{reservations && reservations.length > 0 && (
<ul>
{reservations.map((reservation) => (
<li key={reservation.id}>{reservation.quantity}</li>
))}
</ul>
)}
</div>
)
}
export default Reservations
```
To specify relations that should be retrieved within the reservations:
```tsx
import React from "react"
import { useAdminReservations } from "medusa-react"
const Reservations = () => {
const {
reservations,
isLoading
} = useAdminReservations({
expand: "location"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{reservations && !reservations.length && (
<span>No Reservations</span>
)}
{reservations && reservations.length > 0 && (
<ul>
{reservations.map((reservation) => (
<li key={reservation.id}>{reservation.quantity}</li>
))}
</ul>
)}
</div>
)
}
export default Reservations
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminReservations } from "medusa-react"
const Reservations = () => {
const {
reservations,
limit,
offset,
isLoading
} = useAdminReservations({
expand: "location",
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{reservations && !reservations.length && (
<span>No Reservations</span>
)}
{reservations && reservations.length > 0 && (
<ul>
{reservations.map((reservation) => (
<li key={reservation.id}>{reservation.quantity}</li>
))}
</ul>
)}
</div>
)
}
export default Reservations
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"query","type":"[AdminGetReservationsParams](../../../medusa/classes/medusa.AdminGetReservationsParams.mdx)","description":"Filters and pagination parameters to apply on the retrieved reservations.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"[DateComparisonOperator](../../../medusa/classes/medusa.DateComparisonOperator.mdx)","description":"Date filters to apply on the reservations' `created_at` field.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"created_by","type":"`string`[]","description":"\"Create by\" user IDs to filter reservations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| [StringComparisonOperator](../../../medusa/classes/medusa.StringComparisonOperator.mdx)","description":"String filters tp apply on the reservations' `description` field.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`[]","description":"Inventory item IDs to filter reservations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"line_item_id","type":"`string`[]","description":"Line item IDs to filter reservations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string` \\| `string`[]","description":"Location IDs to filter reservations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"quantity","type":"[NumericalComparisonOperator](../../../medusa/classes/medusa.NumericalComparisonOperator.mdx)","description":"Numerical filters to apply on the reservations' `quantity` field.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"gt","type":"`number`","description":"The filtered number must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`number`","description":"The filtered number must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lt","type":"`number`","description":"The filtered number must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`number`","description":"The filtered number must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"reservations","type":"[ReservationItemDTO](../../../medusa/types/medusa.ReservationItemDTO.mdx)[]","description":"An array of reservations details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`","description":"The id of the inventory item the reservation relates to","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The id of the location of the reservation","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`string` \\| `null`","description":"UserId of user who created the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"line_item_id","type":"`string` \\| `null`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminReservation
This hook retrieves a reservation's details.
#### Example
```ts
import React from "react"
import { useAdminReservation } from "medusa-react"
type Props = {
reservationId: string
}
const Reservation = ({ reservationId }: Props) => {
const { reservation, isLoading } = useAdminReservation(
reservationId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{reservation && (
<span>{reservation.inventory_item_id}</span>
)}
</div>
)
}
export default Reservation
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The reservation's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"reservation","type":"[ReservationItemDTO](../../../medusa/types/medusa.ReservationItemDTO.mdx)","description":"Reservation details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"inventory_item_id","type":"`string`","description":"The id of the inventory item the reservation relates to","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"location_id","type":"`string`","description":"The id of the location of the reservation","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"The id of the reservation item","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"`string` \\| `null`","description":"UserId of user who created the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string` \\| `null`","description":"Description of the reservation item","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"line_item_id","type":"`string` \\| `null`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
@@ -0,0 +1,234 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/return_reasons
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Return Reasons
Queries and Mutations listed here are used to send requests to the [Admin Return Reason API Routes](https://docs.medusajs.com/api/admin#return-reasons).
All hooks listed require [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
Return reasons are key-value pairs that are used to specify why an order return is being created.
Admins can manage available return reasons, and they can be used by both admins and customers when creating a return.
Related Guide: [How to manage return reasons](https://docs.medusajs.com/modules/orders/admin/manage-returns#manage-return-reasons).
## Mutations
### useAdminCreateReturnReason
This hook creates a return reason.
#### Example
```ts
import React from "react"
import { useAdminCreateReturnReason } from "medusa-react"
const CreateReturnReason = () => {
const createReturnReason = useAdminCreateReturnReason()
// ...
const handleCreate = (
label: string,
value: string
) => {
createReturnReason.mutate({
label,
value,
}, {
onSuccess: ({ return_reason }) => {
console.log(return_reason.id)
}
})
}
// ...
}
export default CreateReturnReason
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminPostReturnReasonsReq","type":"[AdminPostReturnReasonsReq](../../../medusa/classes/medusa.AdminPostReturnReasonsReq.mdx)","optional":false,"defaultValue":"","description":"The details of the return reason to create.","expandable":false,"children":[{"name":"label","type":"`string`","description":"The label to display to the Customer.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"A unique value of the return reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The description of the Reason.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason_id","type":"`string`","description":"The ID of the parent return reason.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminReturnReasonsRes","type":"[AdminReturnReasonsRes](../../../medusa/types/medusa.AdminReturnReasonsRes.mdx)","optional":false,"defaultValue":"","description":"The return reason's details.","expandable":false,"children":[{"name":"return_reason","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The return reason's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"A description of the Reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The return reason's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"A text that can be displayed to the Customer as a reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason","type":"`null` \\| [ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The details of the parent reason.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"parent_return_reason_id","type":"`null` \\| `string`","description":"The ID of the parent reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_reason_children","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The details of the child reasons.","optional":false,"defaultValue":"","expandable":true,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"A description of the Reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The return reason's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"A text that can be displayed to the Customer as a reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason","type":"`null` \\| [ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The details of the parent reason.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"parent_return_reason_id","type":"`null` \\| `string`","description":"The ID of the parent reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_reason_children","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The details of the child reasons.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value to identify the reason by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value to identify the reason by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminUpdateReturnReason
This hook updates a return reason's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateReturnReason } from "medusa-react"
type Props = {
returnReasonId: string
}
const ReturnReason = ({ returnReasonId }: Props) => {
const updateReturnReason = useAdminUpdateReturnReason(
returnReasonId
)
// ...
const handleUpdate = (
label: string
) => {
updateReturnReason.mutate({
label,
}, {
onSuccess: ({ return_reason }) => {
console.log(return_reason.label)
}
})
}
// ...
}
export default ReturnReason
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The return reason's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminPostReturnReasonsReasonReq","type":"[AdminPostReturnReasonsReasonReq](../../../medusa/classes/medusa.AdminPostReturnReasonsReasonReq.mdx)","optional":false,"defaultValue":"","description":"The details to update of the return reason.","expandable":false,"children":[{"name":"description","type":"`string`","description":"The description of the Reason.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"The label to display to the Customer.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional set of key-value pairs with additional information.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"A unique value of the return reason.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminReturnReasonsRes","type":"[AdminReturnReasonsRes](../../../medusa/types/medusa.AdminReturnReasonsRes.mdx)","optional":false,"defaultValue":"","description":"The return reason's details.","expandable":false,"children":[{"name":"return_reason","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The return reason's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"A description of the Reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The return reason's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"A text that can be displayed to the Customer as a reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason","type":"`null` \\| [ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The details of the parent reason.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"parent_return_reason_id","type":"`null` \\| `string`","description":"The ID of the parent reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_reason_children","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The details of the child reasons.","optional":false,"defaultValue":"","expandable":true,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"A description of the Reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The return reason's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"A text that can be displayed to the Customer as a reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason","type":"`null` \\| [ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The details of the parent reason.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"parent_return_reason_id","type":"`null` \\| `string`","description":"The ID of the parent reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_reason_children","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The details of the child reasons.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value to identify the reason by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value to identify the reason by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminDeleteReturnReason
This hook deletes a return reason.
#### Example
```ts
import React from "react"
import { useAdminDeleteReturnReason } from "medusa-react"
type Props = {
returnReasonId: string
}
const ReturnReason = ({ returnReasonId }: Props) => {
const deleteReturnReason = useAdminDeleteReturnReason(
returnReasonId
)
// ...
const handleDelete = () => {
deleteReturnReason.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default ReturnReason
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The return reason's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../medusa/interfaces/medusa.DeleteResponse.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
___
## Queries
### useAdminReturnReasons
This hook retrieves a list of return reasons.
#### Example
```ts
import React from "react"
import { useAdminReturnReasons } from "medusa-react"
const ReturnReasons = () => {
const { return_reasons, isLoading } = useAdminReturnReasons()
return (
<div>
{isLoading && <span>Loading...</span>}
{return_reasons && !return_reasons.length && (
<span>No Return Reasons</span>
)}
{return_reasons && return_reasons.length > 0 && (
<ul>
{return_reasons.map((reason) => (
<li key={reason.id}>
{reason.label}: {reason.value}
</li>
))}
</ul>
)}
</div>
)
}
export default ReturnReasons
```
#### Query Returned Data
<ParameterTypes parameters={[{"name":"return_reasons","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The list of return reasons.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"A description of the Reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The return reason's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"A text that can be displayed to the Customer as a reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason","type":"`null` \\| [ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The details of the parent reason.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"parent_return_reason_id","type":"`null` \\| `string`","description":"The ID of the parent reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_reason_children","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The details of the child reasons.","optional":false,"defaultValue":"","expandable":true,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"A description of the Reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The return reason's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"A text that can be displayed to the Customer as a reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason","type":"`null` \\| [ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The details of the parent reason.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"parent_return_reason_id","type":"`null` \\| `string`","description":"The ID of the parent reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_reason_children","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The details of the child reasons.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value to identify the reason by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value to identify the reason by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminReturnReason
This hook retrieves a return reason's details.
#### Example
```ts
import React from "react"
import { useAdminReturnReason } from "medusa-react"
type Props = {
returnReasonId: string
}
const ReturnReason = ({ returnReasonId }: Props) => {
const { return_reason, isLoading } = useAdminReturnReason(
returnReasonId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{return_reason && <span>{return_reason.label}</span>}
</div>
)
}
export default ReturnReason
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The return reason's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"return_reason","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The return reason's details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"A description of the Reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The return reason's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"A text that can be displayed to the Customer as a reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason","type":"`null` \\| [ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The details of the parent reason.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"parent_return_reason_id","type":"`null` \\| `string`","description":"The ID of the parent reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_reason_children","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The details of the child reasons.","optional":false,"defaultValue":"","expandable":true,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"A description of the Reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The return reason's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"A text that can be displayed to the Customer as a reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason","type":"`null` \\| [ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The details of the parent reason.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"parent_return_reason_id","type":"`null` \\| `string`","description":"The ID of the parent reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_reason_children","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The details of the child reasons.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value to identify the reason by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value to identify the reason by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,318 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/stock_locations
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Stock Locations
Queries and Mutations listed here are used to send requests to the [Admin Stock Location API Routes](https://docs.medusajs.com/api/admin#stock-locations).
To use these hooks, make sure to install the
[@medusajs/stock-location](https://docs.medusajs.com/modules/multiwarehouse/install-modules#stock-location-module) module in your Medusa backend.
All hooks listed require [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
A stock location, provided by the [Stock Location module](https://docs.medusajs.com/modules/multiwarehouse/stock-location-module),
indicates a physical address that stock-kept items, such as physical products, can be stored in.
An admin can create and manage available stock locations.
Related Guide: [How to manage stock locations](https://docs.medusajs.com/modules/multiwarehouse/admin/manage-stock-locations).
## Mutations
### useAdminCreateStockLocation
This hook creates a stock location.
#### Example
```ts
import React from "react"
import { useAdminCreateStockLocation } from "medusa-react"
const CreateStockLocation = () => {
const createStockLocation = useAdminCreateStockLocation()
// ...
const handleCreate = (name: string) => {
createStockLocation.mutate({
name,
}, {
onSuccess: ({ stock_location }) => {
console.log(stock_location.id)
}
})
}
// ...
}
export default CreateStockLocation
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminPostStockLocationsReq","type":"[AdminPostStockLocationsReq](../../../medusa/classes/medusa.AdminPostStockLocationsReq.mdx)","optional":false,"defaultValue":"","description":"The details of the stock location to create.","expandable":false,"children":[{"name":"name","type":"`string`","description":"the name of the stock location","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address","type":"[StockLocationAddress](../../../medusa/classes/medusa.StockLocationAddress.mdx)","description":"A new stock location address to create and associate with the stock location. Only required if `address\\_id` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"address_1","type":"`string`","description":"Stock location address","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"The two character ISO code for the country.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_2","type":"`string`","description":"Stock location address' complement","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"city","type":"`string`","description":"Stock location address' city","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`string`","description":"Stock location address' company","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string`","description":"Stock location address' phone number","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"postal_code","type":"`string`","description":"Stock location address' postal code","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"province","type":"`string`","description":"Stock location address' province","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"address_id","type":"`string`","description":"the ID of an existing stock location address to associate with the stock location. Only required if `address` is not provided.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminStockLocationsRes","type":"[AdminStockLocationsRes](../../../medusa/types/medusa.AdminStockLocationsRes.mdx)","optional":false,"defaultValue":"","description":"The stock location's details.","expandable":false,"children":[{"name":"stock_location","type":"[StockLocationExpandedDTO](../../../medusa/types/medusa.StockLocationExpandedDTO.mdx)","description":"Stock location details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"address_id","type":"`string`","description":"Stock location address' ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The stock location's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the stock location","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address","type":"[StockLocationAddressDTO](../../../medusa/types/medusa.StockLocationAddressDTO.mdx)","description":"The Address of the Stock Location","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"address_1","type":"`string`","description":"Stock location address","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"Stock location address' country","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_2","type":"`string` \\| `null`","description":"Stock location address' complement","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"city","type":"`string` \\| `null`","description":"Stock location address' city","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`string` \\| `null`","description":"Stock location company' name","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The stock location address' ID","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string` \\| `null`","description":"Stock location address' phone number","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"postal_code","type":"`string` \\| `null`","description":"Stock location address' postal code","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"province","type":"`string` \\| `null`","description":"Stock location address' province","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sales_channels","type":"`any`[]","description":"The associated sales channels.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminUpdateStockLocation
This hook updates a stock location's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateStockLocation } from "medusa-react"
type Props = {
stockLocationId: string
}
const StockLocation = ({ stockLocationId }: Props) => {
const updateLocation = useAdminUpdateStockLocation(
stockLocationId
)
// ...
const handleUpdate = (
name: string
) => {
updateLocation.mutate({
name
}, {
onSuccess: ({ stock_location }) => {
console.log(stock_location.name)
}
})
}
}
export default StockLocation
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The stock location's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminPostStockLocationsLocationReq","type":"[AdminPostStockLocationsLocationReq](../../../medusa/classes/medusa.AdminPostStockLocationsLocationReq.mdx)","optional":false,"defaultValue":"","description":"The details to update of the stock location.","expandable":false,"children":[{"name":"address","type":"[StockLocationAddress](../../../medusa/classes/medusa.StockLocationAddress-1.mdx)","description":"The data of an associated address to create or update.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"address_1","type":"`string`","description":"First line address.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"Country code.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_2","type":"`string`","description":"Second line address.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"city","type":"`string`","description":"City.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`string`","description":"Company.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string`","description":"Phone.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"postal_code","type":"`string`","description":"Postal code.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"province","type":"`string`","description":"Province.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"address_id","type":"`string`","description":"the stock location address ID","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"the name of the stock location","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminStockLocationsRes","type":"[AdminStockLocationsRes](../../../medusa/types/medusa.AdminStockLocationsRes.mdx)","optional":false,"defaultValue":"","description":"The stock location's details.","expandable":false,"children":[{"name":"stock_location","type":"[StockLocationExpandedDTO](../../../medusa/types/medusa.StockLocationExpandedDTO.mdx)","description":"Stock location details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"address_id","type":"`string`","description":"Stock location address' ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The stock location's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the stock location","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address","type":"[StockLocationAddressDTO](../../../medusa/types/medusa.StockLocationAddressDTO.mdx)","description":"The Address of the Stock Location","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"address_1","type":"`string`","description":"Stock location address","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"Stock location address' country","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_2","type":"`string` \\| `null`","description":"Stock location address' complement","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"city","type":"`string` \\| `null`","description":"Stock location address' city","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`string` \\| `null`","description":"Stock location company' name","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The stock location address' ID","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string` \\| `null`","description":"Stock location address' phone number","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"postal_code","type":"`string` \\| `null`","description":"Stock location address' postal code","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"province","type":"`string` \\| `null`","description":"Stock location address' province","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sales_channels","type":"`any`[]","description":"The associated sales channels.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminDeleteStockLocation
This hook deletes a stock location.
#### Example
```ts
import React from "react"
import { useAdminDeleteStockLocation } from "medusa-react"
type Props = {
stockLocationId: string
}
const StockLocation = ({ stockLocationId }: Props) => {
const deleteLocation = useAdminDeleteStockLocation(
stockLocationId
)
// ...
const handleDelete = () => {
deleteLocation.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
}
export default StockLocation
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The stock location's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../medusa/types/medusa.DeleteResponse-1.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of the item that was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the item that was deleted.","optional":false,"defaultValue":"stock_location","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
___
## Queries
### useAdminStockLocations
This hook retrieves a list of stock locations. The stock locations can be filtered by fields such as `name` or `created_at` passed in the `query` parameter.
The stock locations can also be sorted or paginated.
#### Example
To list stock locations:
```tsx
import React from "react"
import { useAdminStockLocations } from "medusa-react"
function StockLocations() {
const {
stock_locations,
isLoading
} = useAdminStockLocations()
return (
<div>
{isLoading && <span>Loading...</span>}
{stock_locations && !stock_locations.length && (
<span>No Locations</span>
)}
{stock_locations && stock_locations.length > 0 && (
<ul>
{stock_locations.map(
(location) => (
<li key={location.id}>{location.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default StockLocations
```
To specify relations that should be retrieved within the stock locations:
```tsx
import React from "react"
import { useAdminStockLocations } from "medusa-react"
function StockLocations() {
const {
stock_locations,
isLoading
} = useAdminStockLocations({
expand: "address"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{stock_locations && !stock_locations.length && (
<span>No Locations</span>
)}
{stock_locations && stock_locations.length > 0 && (
<ul>
{stock_locations.map(
(location) => (
<li key={location.id}>{location.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default StockLocations
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useAdminStockLocations } from "medusa-react"
function StockLocations() {
const {
stock_locations,
limit,
offset,
isLoading
} = useAdminStockLocations({
expand: "address",
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{stock_locations && !stock_locations.length && (
<span>No Locations</span>
)}
{stock_locations && stock_locations.length > 0 && (
<ul>
{stock_locations.map(
(location) => (
<li key={location.id}>{location.name}</li>
)
)}
</ul>
)}
</div>
)
}
export default StockLocations
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"query","type":"[AdminGetStockLocationsParams](../../../medusa/classes/medusa.AdminGetStockLocationsParams.mdx)","description":"Filters and pagination configurations to apply on the retrieved stock locations.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"address_id","type":"`string` \\| `string`[]","description":"Filter stock locations by the ID of their associated addresses.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"expand","type":"`string`","description":"Comma-separated relations that should be expanded in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"fields","type":"`string`","description":"Comma-separated fields that should be included in the returned data.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[]","description":"IDs to filter stock locations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"name","type":"`string` \\| `string`[]","description":"Names to filter stock locations by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"sales_channel_id","type":"`string` \\| `string`[]","description":"Filter stock locations by the ID of their associated sales channels.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"count","type":"`number`","description":"The total number of notifications","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"The number of notifications per page","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of notifications skipped when retrieving the notifications.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"stock_locations","type":"[StockLocationExpandedDTO](../../../medusa/types/medusa.StockLocationExpandedDTO.mdx)[]","description":"The list of stock locations.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"address_id","type":"`string`","description":"Stock location address' ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The stock location's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the stock location","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address","type":"[StockLocationAddressDTO](../../../medusa/types/medusa.StockLocationAddressDTO.mdx)","description":"The Address of the Stock Location","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"address_1","type":"`string`","description":"Stock location address","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"Stock location address' country","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_2","type":"`string` \\| `null`","description":"Stock location address' complement","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"city","type":"`string` \\| `null`","description":"Stock location address' city","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`string` \\| `null`","description":"Stock location company' name","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The stock location address' ID","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string` \\| `null`","description":"Stock location address' phone number","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"postal_code","type":"`string` \\| `null`","description":"Stock location address' postal code","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"province","type":"`string` \\| `null`","description":"Stock location address' province","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sales_channels","type":"`any`[]","description":"The associated sales channels.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminStockLocation
This hook retrieves a stock location's details.
#### Example
```ts
import React from "react"
import { useAdminStockLocation } from "medusa-react"
type Props = {
stockLocationId: string
}
const StockLocation = ({ stockLocationId }: Props) => {
const {
stock_location,
isLoading
} = useAdminStockLocation(stockLocationId)
return (
<div>
{isLoading && <span>Loading...</span>}
{stock_location && (
<span>{stock_location.name}</span>
)}
</div>
)
}
export default StockLocation
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The stock location's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"stock_location","type":"[StockLocationExpandedDTO](../../../medusa/types/medusa.StockLocationExpandedDTO.mdx)","description":"Stock location details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"address_id","type":"`string`","description":"Stock location address' ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The stock location's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"`string`","description":"The name of the stock location","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address","type":"[StockLocationAddressDTO](../../../medusa/types/medusa.StockLocationAddressDTO.mdx)","description":"The Address of the Stock Location","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"address_1","type":"`string`","description":"Stock location address","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"country_code","type":"`string`","description":"Stock location address' country","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`string` \\| `Date` \\| `null`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`string` \\| `Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"address_2","type":"`string` \\| `null`","description":"Stock location address' complement","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"city","type":"`string` \\| `null`","description":"Stock location address' city","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"company","type":"`string` \\| `null`","description":"Stock location company' name","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The stock location address' ID","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>` \\| `null`","description":"An optional key-value map with additional details","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"phone","type":"`string` \\| `null`","description":"Stock location address' phone number","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"postal_code","type":"`string` \\| `null`","description":"Stock location address' postal code","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"province","type":"`string` \\| `null`","description":"Stock location address' province","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sales_channels","type":"`any`[]","description":"The associated sales channels.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,166 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/uploads
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Uploads
Mutations listed here are used to send requests to the [Admin Upload API Routes](https://docs.medusajs.com/api/admin#uploads).
All hooks listed require [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
The methods in this class are used to upload any type of resources. For example, they can be used to upload CSV files that are used to import products into the store.
Related Guide: [How to upload CSV file when importing a product](https://docs.medusajs.com/modules/products/admin/import-products#1-upload-csv-file).
## Mutations
### useAdminUploadFile
This hook uploads a file to a public bucket or storage. The file upload is handled by the file service installed on the Medusa backend.
#### Example
```ts
import React from "react"
import { useAdminUploadFile } from "medusa-react"
const UploadFile = () => {
const uploadFile = useAdminUploadFile()
// ...
const handleFileUpload = (file: File) => {
uploadFile.mutate(file, {
onSuccess: ({ uploads }) => {
console.log(uploads[0].key)
}
})
}
// ...
}
export default UploadFile
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminCreateUploadPayload","type":"`AdminCreateUploadPayload`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"AdminCreateUploadPayload","type":"`AdminCreateUploadPayload`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminUploadsRes","type":"[AdminUploadsRes](../../../medusa/types/medusa.AdminUploadsRes.mdx)","optional":false,"defaultValue":"","description":"The list of uploaded files.","expandable":false,"children":[{"name":"uploads","type":"[FileServiceUploadResult](../../../medusa/types/medusa.FileServiceUploadResult.mdx)[]","description":"Uploaded files details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"key","type":"`string`","description":"The key of the file that is identifiable by the file service. It can be used later to retrieve or manipulate the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"url","type":"`string`","description":"The URL of the uploaded file.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminUploadProtectedFile
This hook uploads a file to an ACL or a non-public bucket. The file upload is handled by the file service installed on the Medusa backend.
#### Example
```ts
import React from "react"
import { useAdminUploadProtectedFile } from "medusa-react"
const UploadFile = () => {
const uploadFile = useAdminUploadProtectedFile()
// ...
const handleFileUpload = (file: File) => {
uploadFile.mutate(file, {
onSuccess: ({ uploads }) => {
console.log(uploads[0].key)
}
})
}
// ...
}
export default UploadFile
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminCreateUploadPayload","type":"`AdminCreateUploadPayload`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"AdminCreateUploadPayload","type":"`AdminCreateUploadPayload`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminUploadsRes","type":"[AdminUploadsRes](../../../medusa/types/medusa.AdminUploadsRes.mdx)","optional":false,"defaultValue":"","description":"The list of uploaded files.","expandable":false,"children":[{"name":"uploads","type":"[FileServiceUploadResult](../../../medusa/types/medusa.FileServiceUploadResult.mdx)[]","description":"Uploaded files details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"key","type":"`string`","description":"The key of the file that is identifiable by the file service. It can be used later to retrieve or manipulate the file.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"url","type":"`string`","description":"The URL of the uploaded file.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminCreatePresignedDownloadUrl
This hook creates and retrieve a presigned or public download URL for a file. The URL creation is handled by the file service installed on the Medusa backend.
#### Example
```ts
import React from "react"
import { useAdminCreatePresignedDownloadUrl } from "medusa-react"
const Image = () => {
const createPresignedUrl = useAdminCreatePresignedDownloadUrl()
// ...
const handlePresignedUrl = (fileKey: string) => {
createPresignedUrl.mutate({
file_key: fileKey
}, {
onSuccess: ({ download_url }) => {
console.log(download_url)
}
})
}
// ...
}
export default Image
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminPostUploadsDownloadUrlReq","type":"[AdminPostUploadsDownloadUrlReq](../../../medusa/classes/medusa.AdminPostUploadsDownloadUrlReq.mdx)","optional":false,"defaultValue":"","description":"The details of the file to retrieve its download URL.","expandable":false,"children":[{"name":"file_key","type":"`string`","description":"key of the file to obtain the download link for. This is obtained when you first uploaded the file, or by the file service if you used it directly.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminUploadsDownloadUrlRes","type":"[AdminUploadsDownloadUrlRes](../../../medusa/types/medusa.AdminUploadsDownloadUrlRes.mdx)","optional":false,"defaultValue":"","description":"The download URL details.","expandable":false,"children":[{"name":"download_url","type":"`string`","description":"The Download URL of the file","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminDeleteFile
This hook deletes an uploaded file from storage. The file is deleted using the installed file service on the Medusa backend.
#### Example
```ts
import React from "react"
import { useAdminDeleteFile } from "medusa-react"
const Image = () => {
const deleteFile = useAdminDeleteFile()
// ...
const handleDeleteFile = (fileKey: string) => {
deleteFile.mutate({
file_key: fileKey
}, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default Image
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminDeleteUploadsReq","type":"[AdminDeleteUploadsReq](../../../medusa/classes/medusa.AdminDeleteUploadsReq.mdx)","optional":false,"defaultValue":"","description":"The details of the file to delete.","expandable":false,"children":[{"name":"file_key","type":"`string`","description":"key of the file to delete. This is obtained when you first uploaded the file, or by the file service if you used it directly.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../medusa/interfaces/medusa.DeleteResponse.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
@@ -0,0 +1,304 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/admin/users
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Users
Queries and Mutations listed here are used to send requests to the [Admin User API Routes](https://docs.medusajs.com/api/admin#users).
All hooks listed require [user authentication](medusa_react.Hooks.Admin.Auth.mdx#useadminlogin).
A store can have more than one user, each having the same privileges. Admins can manage users, their passwords, and more.
Related Guide: [How to manage users](https://docs.medusajs.com/modules/users/admin/manage-users).
## Mutations
### useAdminCreateUser
This hook creates an admin user. The user has the same privileges as all admin users, and will be able to
authenticate and perform admin functionalities right after creation.
#### Example
```ts
import React from "react"
import { useAdminCreateUser } from "medusa-react"
const CreateUser = () => {
const createUser = useAdminCreateUser()
// ...
const handleCreateUser = () => {
createUser.mutate({
email: "user@example.com",
password: "supersecret",
}, {
onSuccess: ({ user }) => {
console.log(user.id)
}
})
}
// ...
}
export default CreateUser
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminCreateUserPayload","type":"`AdminCreateUserPayload`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"AdminCreateUserPayload","type":"`AdminCreateUserPayload`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminUserRes","type":"[AdminUserRes](../../../medusa/types/medusa.AdminUserRes.mdx)","optional":false,"defaultValue":"","description":"The user's details.","expandable":false,"children":[{"name":"user","type":"Omit&#60;[User](../../../entities/classes/entities.User.mdx), \"password_hash\"&#62;","description":"User details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"api_token","type":"`string`","description":"An API token associated with the user.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The email of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The first name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The user's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The last name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRoles](../../../entities/enums/entities.UserRoles.mdx)","description":"The user's role. These roles don't provide any different privileges.","optional":false,"defaultValue":"member","expandable":false,"children":[{"name":"ADMIN","type":"`\"admin\"`","description":"The user is an admin.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DEVELOPER","type":"`\"developer\"`","description":"The user is a developer.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"MEMBER","type":"`\"member\"`","description":"The user is a team member.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminUpdateUser
This hook updates an admin user's details.
#### Example
```ts
import React from "react"
import { useAdminUpdateUser } from "medusa-react"
type Props = {
userId: string
}
const User = ({ userId }: Props) => {
const updateUser = useAdminUpdateUser(userId)
// ...
const handleUpdateUser = (
firstName: string
) => {
updateUser.mutate({
first_name: firstName,
}, {
onSuccess: ({ user }) => {
console.log(user.first_name)
}
})
}
// ...
}
export default User
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The user's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminUpdateUserPayload","type":"`AdminUpdateUserPayload`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"AdminUpdateUserPayload","type":"`AdminUpdateUserPayload`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminUserRes","type":"[AdminUserRes](../../../medusa/types/medusa.AdminUserRes.mdx)","optional":false,"defaultValue":"","description":"The user's details.","expandable":false,"children":[{"name":"user","type":"Omit&#60;[User](../../../entities/classes/entities.User.mdx), \"password_hash\"&#62;","description":"User details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"api_token","type":"`string`","description":"An API token associated with the user.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The email of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The first name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The user's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The last name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRoles](../../../entities/enums/entities.UserRoles.mdx)","description":"The user's role. These roles don't provide any different privileges.","optional":false,"defaultValue":"member","expandable":false,"children":[{"name":"ADMIN","type":"`\"admin\"`","description":"The user is an admin.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DEVELOPER","type":"`\"developer\"`","description":"The user is a developer.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"MEMBER","type":"`\"member\"`","description":"The user is a team member.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminDeleteUser
This hook deletes a user. Once deleted, the user will not be able to authenticate or perform admin functionalities.
#### Example
```ts
import React from "react"
import { useAdminDeleteUser } from "medusa-react"
type Props = {
userId: string
}
const User = ({ userId }: Props) => {
const deleteUser = useAdminDeleteUser(userId)
// ...
const handleDeleteUser = () => {
deleteUser.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default User
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The user's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"DeleteResponse","type":"[DeleteResponse](../../../medusa/interfaces/medusa.DeleteResponse.mdx)","optional":false,"defaultValue":"","description":"The response returned for a \n\n`DELETE`\n\n request.","expandable":false,"children":[{"name":"deleted","type":"`boolean`","description":"Whether the item was deleted successfully.","optional":false,"defaultValue":"true","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The ID of the deleted item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"object","type":"`string`","description":"The type of the deleted item.","optional":false,"defaultValue":"product-collection","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminResetPassword
This hook resets the password of an admin user using their reset password token. You must generate a reset password token first
for the user using the [useAdminSendResetPasswordToken](medusa_react.Hooks.Admin.Users.mdx#useadminsendresetpasswordtoken) hook, then use that token to reset the password in this hook.
#### Example
```ts
import React from "react"
import { useAdminResetPassword } from "medusa-react"
const ResetPassword = () => {
const resetPassword = useAdminResetPassword()
// ...
const handleResetPassword = (
token: string,
password: string
) => {
resetPassword.mutate({
token,
password,
}, {
onSuccess: ({ user }) => {
console.log(user.id)
}
})
}
// ...
}
export default ResetPassword
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminResetPasswordRequest","type":"[AdminResetPasswordRequest](../../../medusa/classes/medusa.AdminResetPasswordRequest.mdx)","optional":false,"defaultValue":"","description":"The details of the password reset request.","expandable":false,"children":[{"name":"password","type":"`string`","description":"The User's new password.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"token","type":"`string`","description":"The password-reset token generated when the password reset was requested.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The User's email.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Mutation Function Returned Data
<ParameterTypes parameters={[{"name":"AdminUserRes","type":"[AdminUserRes](../../../medusa/types/medusa.AdminUserRes.mdx)","optional":false,"defaultValue":"","description":"The user's details.","expandable":false,"children":[{"name":"user","type":"Omit&#60;[User](../../../entities/classes/entities.User.mdx), \"password_hash\"&#62;","description":"User details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"api_token","type":"`string`","description":"An API token associated with the user.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The email of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The first name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The user's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The last name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRoles](../../../entities/enums/entities.UserRoles.mdx)","description":"The user's role. These roles don't provide any different privileges.","optional":false,"defaultValue":"member","expandable":false,"children":[{"name":"ADMIN","type":"`\"admin\"`","description":"The user is an admin.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DEVELOPER","type":"`\"developer\"`","description":"The user is a developer.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"MEMBER","type":"`\"member\"`","description":"The user is a team member.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminSendResetPasswordToken
This hook generates a password token for an admin user with a given email. This also triggers the `user.password_reset` event. So, if you have a Notification Service installed
that can handle this event, a notification, such as an email, will be sent to the user. The token is triggered as part of the `user.password_reset` event's payload.
That token must be used later to reset the password using the [useAdminResetPassword](medusa_react.Hooks.Admin.Users.mdx#useadminresetpassword) hook.
#### Example
```ts
import React from "react"
import { useAdminSendResetPasswordToken } from "medusa-react"
const Login = () => {
const requestPasswordReset = useAdminSendResetPasswordToken()
// ...
const handleResetPassword = (
email: string
) => {
requestPasswordReset.mutate({
email
}, {
onSuccess: () => {
// successful
}
})
}
// ...
}
export default Login
```
#### Mutation Function Parameters
<ParameterTypes parameters={[{"name":"AdminResetPasswordTokenRequest","type":"[AdminResetPasswordTokenRequest](../../../medusa/classes/medusa.AdminResetPasswordTokenRequest.mdx)","optional":false,"defaultValue":"","description":"The details of the password reset token request.","expandable":false,"children":[{"name":"email","type":"`string`","description":"The User's email.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
___
## Queries
### useAdminUsers
This hook retrieves all admin users.
#### Example
```ts
import React from "react"
import { useAdminUsers } from "medusa-react"
const Users = () => {
const { users, isLoading } = useAdminUsers()
return (
<div>
{isLoading && <span>Loading...</span>}
{users && !users.length && <span>No Users</span>}
{users && users.length > 0 && (
<ul>
{users.map((user) => (
<li key={user.id}>{user.email}</li>
))}
</ul>
)}
</div>
)
}
export default Users
```
#### Query Returned Data
<ParameterTypes parameters={[{"name":"users","type":"Omit&#60;[User](../../../entities/classes/entities.User.mdx), \"password_hash\"&#62;[]","description":"An array of users details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"api_token","type":"`string`","description":"An API token associated with the user.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The email of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The first name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The user's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The last name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRoles](../../../entities/enums/entities.UserRoles.mdx)","description":"The user's role. These roles don't provide any different privileges.","optional":false,"defaultValue":"member","expandable":false,"children":[{"name":"ADMIN","type":"`\"admin\"`","description":"The user is an admin.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DEVELOPER","type":"`\"developer\"`","description":"The user is a developer.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"MEMBER","type":"`\"member\"`","description":"The user is a team member.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useAdminUser
This hook retrieves an admin user's details.
#### Example
```ts
import React from "react"
import { useAdminUser } from "medusa-react"
type Props = {
userId: string
}
const User = ({ userId }: Props) => {
const { user, isLoading } = useAdminUser(
userId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{user && <span>{user.first_name} {user.last_name}</span>}
</div>
)
}
export default User
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The user's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"user","type":"Omit&#60;[User](../../../entities/classes/entities.User.mdx), \"password_hash\"&#62;","description":"User details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"api_token","type":"`string`","description":"An API token associated with the user.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The email of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"first_name","type":"`string`","description":"The first name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The user's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"last_name","type":"`string`","description":"The last name of the User","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"role","type":"[UserRoles](../../../entities/enums/entities.UserRoles.mdx)","description":"The user's role. These roles don't provide any different privileges.","optional":false,"defaultValue":"member","expandable":false,"children":[{"name":"ADMIN","type":"`\"admin\"`","description":"The user is an admin.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"DEVELOPER","type":"`\"developer\"`","description":"The user is a developer.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"MEMBER","type":"`\"member\"`","description":"The user is a team member.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,103 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/store/product_tags
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Product Tags
Queries listed here are used to send requests to the [Store Product Tag API Routes](https://docs.medusajs.com/api/store#product-tags).
Product tags are string values that can be used to filter products by.
Products can have more than one tag, and products can share tags.
## Queries
### useProductTags
This hook retrieves a list of product tags. The product tags can be filtered by fields such as `id` or `q`
passed in the `query` parameter. The product tags can also be sorted or paginated.
#### Example
To list product tags:
```tsx
import React from "react"
import { useProductTags } from "medusa-react"
function Tags() {
const {
product_tags,
isLoading,
} = useProductTags()
return (
<div>
{isLoading && <span>Loading...</span>}
{product_tags && !product_tags.length && (
<span>No Product Tags</span>
)}
{product_tags && product_tags.length > 0 && (
<ul>
{product_tags.map(
(tag) => (
<li key={tag.id}>{tag.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default Tags
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useProductTags } from "medusa-react"
function Tags() {
const {
product_tags,
limit,
offset,
isLoading,
} = useProductTags({
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_tags && !product_tags.length && (
<span>No Product Tags</span>
)}
{product_tags && product_tags.length > 0 && (
<ul>
{product_tags.map(
(tag) => (
<li key={tag.id}>{tag.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default Tags
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"query","type":"[StoreGetProductTagsParams](../../../medusa/classes/medusa.StoreGetProductTagsParams.mdx)","description":"Filters and pagination configurations to apply on the retrieved product tags.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"[DateComparisonOperator](../../../medusa/classes/medusa.DateComparisonOperator.mdx)","description":"Date filters to apply to the product tags' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"discount_condition_id","type":"`string`","description":"Filter product tags by the ID of their associated discount condition.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../medusa/classes/medusa.StringComparisonOperator.mdx)","description":"IDs to filter product tags by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search product tags' values.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"[DateComparisonOperator](../../../medusa/classes/medusa.DateComparisonOperator.mdx)","description":"Date filters to apply to the product tags' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"value","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../medusa/classes/medusa.StringComparisonOperator.mdx)","description":"Values to filter product tags by.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_tags","type":"[ProductTag](../../../entities/classes/entities.ProductTag.mdx)[]","description":"An array of product tags details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The product tag's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value that the Product Tag represents","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
@@ -0,0 +1,103 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/store/product_types
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Product Types
Queries listed here are used to send requests to the [Store Product Type API Routes](https://docs.medusajs.com/api/store#product-types).
Product types are string values that can be used to filter products by.
Products can have more than one tag, and products can share types.
## Queries
### useProductTypes
This hook retrieves a list of product types. The product types can be filtered by fields such as `value` or `q` passed
in the `query` parameter. The product types can also be sorted or paginated.
#### Example
To list product types:
```tsx
import React from "react"
import { useProductTypes } from "medusa-react"
function Types() {
const {
product_types,
isLoading,
} = useProductTypes()
return (
<div>
{isLoading && <span>Loading...</span>}
{product_types && !product_types.length && (
<span>No Product Types</span>
)}
{product_types && product_types.length > 0 && (
<ul>
{product_types.map(
(type) => (
<li key={type.id}>{type.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default Types
```
By default, only the first `20` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
```tsx
import React from "react"
import { useProductTypes } from "medusa-react"
function Types() {
const {
product_types,
limit,
offset,
isLoading,
} = useProductTypes({
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_types && !product_types.length && (
<span>No Product Types</span>
)}
{product_types && product_types.length > 0 && (
<ul>
{product_types.map(
(type) => (
<li key={type.id}>{type.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default Types
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"query","type":"[StoreGetProductTypesParams](../../../medusa/classes/medusa.StoreGetProductTypesParams.mdx)","description":"Filters and pagination configurations to apply on retrieved product types.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"[DateComparisonOperator](../../../medusa/classes/medusa.DateComparisonOperator.mdx)","description":"Date filters to apply on the product types' `created_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"discount_condition_id","type":"`string`","description":"Filter product types by the ID of their associated discount condition.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../medusa/classes/medusa.StringComparisonOperator.mdx)","description":"IDs to filter product types by.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"Limit the number of items returned in the list.","optional":true,"defaultValue":"20","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items to skip when retrieving a list.","optional":true,"defaultValue":"0","expandable":false,"children":[]},{"name":"order","type":"`string`","description":"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"q","type":"`string`","description":"Search term to search product types' values.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"[DateComparisonOperator](../../../medusa/classes/medusa.DateComparisonOperator.mdx)","description":"Date filters to apply on the product types' `updated_at` date.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"gt","type":"`Date`","description":"The filtered date must be greater than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"gte","type":"`Date`","description":"The filtered date must be greater than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lt","type":"`Date`","description":"The filtered date must be less than this value.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"lte","type":"`Date`","description":"The filtered date must be less than or equal to this value.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"value","type":"`string` \\| `string`[] \\| [StringComparisonOperator](../../../medusa/classes/medusa.StringComparisonOperator.mdx)","description":"Values to filter product types by.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"count","type":"`number`","description":"The total number of items available.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"limit","type":"`number`","description":"The maximum number of items that can be returned in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"offset","type":"`number`","description":"The number of items skipped before the returned items in the list.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_types","type":"[ProductType](../../../entities/classes/entities.ProductType.mdx)[]","description":"An array of product types details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The product type's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value that the Product Type represents.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,94 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/store/return_reasons
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Return Reasons
Queries listed here are used to send requests to the [Store Return Reason API Routes](https://docs.medusajs.com/api/store#return-reasons).
Return reasons are key-value pairs that are used to specify why an order return is being created.
## Queries
### useReturnReasons
This hook retrieves a list of Return Reasons. This is useful when implementing a Create Return flow in the storefront.
#### Example
```ts
import React from "react"
import { useReturnReasons } from "medusa-react"
const ReturnReasons = () => {
const {
return_reasons,
isLoading
} = useReturnReasons()
return (
<div>
{isLoading && <span>Loading...</span>}
{return_reasons?.length && (
<ul>
{return_reasons.map((returnReason) => (
<li key={returnReason.id}>
{returnReason.label}
</li>
))}
</ul>
)}
</div>
)
}
export default ReturnReasons
```
#### Query Returned Data
<ParameterTypes parameters={[{"name":"return_reasons","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"An array of return reasons details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"A description of the Reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The return reason's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"A text that can be displayed to the Customer as a reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason","type":"`null` \\| [ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The details of the parent reason.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"parent_return_reason_id","type":"`null` \\| `string`","description":"The ID of the parent reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_reason_children","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The details of the child reasons.","optional":false,"defaultValue":"","expandable":true,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"A description of the Reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The return reason's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"A text that can be displayed to the Customer as a reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason","type":"`null` \\| [ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The details of the parent reason.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"parent_return_reason_id","type":"`null` \\| `string`","description":"The ID of the parent reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_reason_children","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The details of the child reasons.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value to identify the reason by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value to identify the reason by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useReturnReason
This hook retrieves a Return Reason's details.
#### Example
```ts
import React from "react"
import { useReturnReason } from "medusa-react"
type Props = {
returnReasonId: string
}
const ReturnReason = ({ returnReasonId }: Props) => {
const {
return_reason,
isLoading
} = useReturnReason(
returnReasonId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{return_reason && <span>{return_reason.label}</span>}
</div>
)
}
export default ReturnReason
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"id","type":"`string`","description":"The return reason's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"return_reason","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"Return reason details.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"A description of the Reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The return reason's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"A text that can be displayed to the Customer as a reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason","type":"`null` \\| [ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The details of the parent reason.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"parent_return_reason_id","type":"`null` \\| `string`","description":"The ID of the parent reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_reason_children","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The details of the child reasons.","optional":false,"defaultValue":"","expandable":true,"children":[{"name":"created_at","type":"`Date`","description":"The date with timezone at which the resource was created.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"`null` \\| `Date`","description":"The date with timezone at which the resource was deleted.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"A description of the Reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"`string`","description":"The return reason's ID","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"label","type":"`string`","description":"A text that can be displayed to the Customer as a reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"`Record<string, unknown>`","description":"An optional key-value map with additional details","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"parent_return_reason","type":"`null` \\| [ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)","description":"The details of the parent reason.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"parent_return_reason_id","type":"`null` \\| `string`","description":"The ID of the parent reason.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"return_reason_children","type":"[ReturnReason](../../../entities/classes/entities.ReturnReason.mdx)[]","description":"The details of the child reasons.","optional":false,"defaultValue":"","expandable":true,"children":[]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value to identify the reason by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"updated_at","type":"`Date`","description":"The date with timezone at which the resource was updated.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"value","type":"`string`","description":"The value to identify the reason by.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
File diff suppressed because one or more lines are too long
@@ -0,0 +1,110 @@
---
displayed_sidebar: medusaReactSidebar
slug: /references/medusa-react/hooks/store/shipping_options
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Shipping Options
Queries listed here are used to send requests to the [Store Shipping Option API Routes](https://docs.medusajs.com/api/store#shipping-options).
A shipping option is used to define the available shipping methods during checkout or when creating a return.
Related Guide: [Shipping Option architecture](https://docs.medusajs.com/modules/carts-and-checkout/shipping#shipping-option).
## Queries
### useShippingOptions
This hook retrieves a list of shipping options. The shipping options can be filtered using the `query` parameter.
#### Example
```ts
import React from "react"
import { useShippingOptions } from "medusa-react"
const ShippingOptions = () => {
const {
shipping_options,
isLoading,
} = useShippingOptions()
return (
<div>
{isLoading && <span>Loading...</span>}
{shipping_options?.length &&
shipping_options?.length > 0 && (
<ul>
{shipping_options?.map((shipping_option) => (
<li key={shipping_option.id}>
{shipping_option.id}
</li>
))}
</ul>
)}
</div>
)
}
export default ShippingOptions
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"query","type":"[StoreGetShippingOptionsParams](../../../medusa/classes/medusa.StoreGetShippingOptionsParams.mdx)","description":"The filters to apply on the shipping options.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"is_return","type":"`string`","description":"Filter the shipping options by whether they're return shipping options.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product_ids","type":"`string`","description":"Product ID that is used to filter shipping options by whether they can be used to ship that product.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"region_id","type":"`string`","description":"Filter the shipping options by the ID of their associated region.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"shipping_options","type":"[PricedShippingOption](../../../medusa/types/medusa.PricedShippingOption.mdx)[]","description":"An array of shipping options details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
### useCartShippingOptions
This hook retrieves a list of shipping options available for a cart.
#### Example
```ts
import React from "react"
import { useCartShippingOptions } from "medusa-react"
type Props = {
cartId: string
}
const ShippingOptions = ({ cartId }: Props) => {
const { shipping_options, isLoading } =
useCartShippingOptions(cartId)
return (
<div>
{isLoading && <span>Loading...</span>}
{shipping_options && !shipping_options.length && (
<span>No shipping options</span>
)}
{shipping_options && (
<ul>
{shipping_options.map(
(shipping_option) => (
<li key={shipping_option.id}>
{shipping_option.name}
</li>
)
)}
</ul>
)}
</div>
)
}
export default ShippingOptions
```
#### Hook Parameters
<ParameterTypes parameters={[{"name":"cartId","type":"`string`","description":"The cart's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
#### Query Returned Data
<ParameterTypes parameters={[{"name":"shipping_options","type":"[PricedShippingOption](../../../medusa/types/medusa.PricedShippingOption.mdx)[]","description":"An array of shipping options details.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/medusa-react/overview#expanding-fields"/>
File diff suppressed because one or more lines are too long
@@ -0,0 +1,49 @@
---
displayed_sidebar: medusaReactSidebar
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Admin
## Namespaces
- [Auth](Admin/medusa_react.Hooks.Admin.Auth.mdx)
- [Batch Jobs](Admin/medusa_react.Hooks.Admin.Batch_Jobs.mdx)
- [Claims](Admin/medusa_react.Hooks.Admin.Claims.mdx)
- [Currencies](Admin/medusa_react.Hooks.Admin.Currencies.mdx)
- [Custom](Admin/medusa_react.Hooks.Admin.Custom.mdx)
- [Customer Groups](Admin/medusa_react.Hooks.Admin.Customer_Groups.mdx)
- [Customers](Admin/medusa_react.Hooks.Admin.Customers.mdx)
- [Discounts](Admin/medusa_react.Hooks.Admin.Discounts.mdx)
- [Draft Orders](Admin/medusa_react.Hooks.Admin.Draft_Orders.mdx)
- [Gift Cards](Admin/medusa_react.Hooks.Admin.Gift_Cards.mdx)
- [Inventory Items](Admin/medusa_react.Hooks.Admin.Inventory_Items.mdx)
- [Invites](Admin/medusa_react.Hooks.Admin.Invites.mdx)
- [Notes](Admin/medusa_react.Hooks.Admin.Notes.mdx)
- [Notifications](Admin/medusa_react.Hooks.Admin.Notifications.mdx)
- [Order Edits](Admin/medusa_react.Hooks.Admin.Order_Edits.mdx)
- [Orders](Admin/medusa_react.Hooks.Admin.Orders.mdx)
- [Payment Collections](Admin/medusa_react.Hooks.Admin.Payment_Collections.mdx)
- [Payments](Admin/medusa_react.Hooks.Admin.Payments.mdx)
- [Price Lists](Admin/medusa_react.Hooks.Admin.Price_Lists.mdx)
- [Product Categories](Admin/medusa_react.Hooks.Admin.Product_Categories.mdx)
- [Product Collections](Admin/medusa_react.Hooks.Admin.Product_Collections.mdx)
- [Product Tags](Admin/medusa_react.Hooks.Admin.Product_Tags.mdx)
- [Product Types](Admin/medusa_react.Hooks.Admin.Product_Types.mdx)
- [Product Variants](Admin/medusa_react.Hooks.Admin.Product_Variants.mdx)
- [Products](Admin/medusa_react.Hooks.Admin.Products.mdx)
- [Publishable API Keys](Admin/medusa_react.Hooks.Admin.Publishable_API_Keys.mdx)
- [Regions](Admin/medusa_react.Hooks.Admin.Regions.mdx)
- [Reservations](Admin/medusa_react.Hooks.Admin.Reservations.mdx)
- [Return Reasons](Admin/medusa_react.Hooks.Admin.Return_Reasons.mdx)
- [Returns](Admin/medusa_react.Hooks.Admin.Returns.mdx)
- [Sales Channels](Admin/medusa_react.Hooks.Admin.Sales_Channels.mdx)
- [Shipping Options](Admin/medusa_react.Hooks.Admin.Shipping_Options.mdx)
- [Shipping Profiles](Admin/medusa_react.Hooks.Admin.Shipping_Profiles.mdx)
- [Stock Locations](Admin/medusa_react.Hooks.Admin.Stock_Locations.mdx)
- [Stores](Admin/medusa_react.Hooks.Admin.Stores.mdx)
- [Swaps](Admin/medusa_react.Hooks.Admin.Swaps.mdx)
- [Tax Rates](Admin/medusa_react.Hooks.Admin.Tax_Rates.mdx)
- [Uploads](Admin/medusa_react.Hooks.Admin.Uploads.mdx)
- [Users](Admin/medusa_react.Hooks.Admin.Users.mdx)
@@ -0,0 +1,27 @@
---
displayed_sidebar: medusaReactSidebar
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# Store
## Namespaces
- [Carts](Store/medusa_react.Hooks.Store.Carts.mdx)
- [Customers](Store/medusa_react.Hooks.Store.Customers.mdx)
- [Gift Cards](Store/medusa_react.Hooks.Store.Gift_Cards.mdx)
- [Line Items](Store/medusa_react.Hooks.Store.Line_Items.mdx)
- [Order Edits](Store/medusa_react.Hooks.Store.Order_Edits.mdx)
- [Orders](Store/medusa_react.Hooks.Store.Orders.mdx)
- [Payment Collections](Store/medusa_react.Hooks.Store.Payment_Collections.mdx)
- [Product Categories](Store/medusa_react.Hooks.Store.Product_Categories.mdx)
- [Product Collections](Store/medusa_react.Hooks.Store.Product_Collections.mdx)
- [Product Tags](Store/medusa_react.Hooks.Store.Product_Tags.mdx)
- [Product Types](Store/medusa_react.Hooks.Store.Product_Types.mdx)
- [Products](Store/medusa_react.Hooks.Store.Products.mdx)
- [Regions](Store/medusa_react.Hooks.Store.Regions.mdx)
- [Return Reasons](Store/medusa_react.Hooks.Store.Return_Reasons.mdx)
- [Returns](Store/medusa_react.Hooks.Store.Returns.mdx)
- [Shipping Options](Store/medusa_react.Hooks.Store.Shipping_Options.mdx)
- [Swaps](Store/medusa_react.Hooks.Store.Swaps.mdx)