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
@@ -475,10 +475,17 @@ To create a line item of a product and add it to a cart, you can use the followi
const createLineItem = useCreateLineItem(cart_id)
const handleAddItem = () => {
const handleAddItem = (
variantId: string,
quantity: amount
) => {
createLineItem.mutate({
variant_id,
variant_id: variantId,
quantity,
}, {
onSuccess: ({ cart }) => {
console.log(cart.items)
}
})
}
@@ -549,10 +556,17 @@ To update a line item's quantity in the cart, you can use the following code sni
const updateLineItem = useUpdateLineItem(cart_id)
const handleUpdateItem = () => {
const handleUpdateItem = (
lineItemId: string,
quantity: number
) => {
updateLineItem.mutate({
lineId,
quantity: 3,
lineId: lineItemId,
quantity,
}, {
onSuccess: ({ cart }) => {
console.log(cart.items)
}
})
}
@@ -614,9 +628,15 @@ To delete a line item from the cart, you can use the following code snippet:
const deleteLineItem = useDeleteLineItem(cart_id)
const handleDeleteItem = () => {
const handleDeleteItem = (
lineItemId: string
) => {
deleteLineItem.mutate({
lineId,
lineId: lineItemId,
}, {
onSuccess: ({ cart }) => {
console.log(cart.items)
}
})
}
@@ -253,22 +253,30 @@ Once the customer chooses one of the available shipping options, send a `POST` r
```tsx
import { useAddShippingMethodToCart } from "medusa-react"
// ...
const ShippingOptions = ({ cartId }: Props) => {
// ...
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const addShippingMethod = useAddShippingMethodToCart(cartId)
const handleAddShippingMethod = (option_id: string) => {
const handleAddShippingMethod = (
optionId: string
) => {
addShippingMethod.mutate({
option_id,
option_id: optionId,
}, {
onSuccess: ({ cart }) => {
console.log(cart.shipping_methods)
}
})
}
// ...
}
export default ShippingOptions
export default Cart
```
</TabItem>
@@ -72,19 +72,13 @@ You can create a customer group by sending a request to the Create Customer Grou
const createCustomerGroup = useAdminCreateCustomerGroup()
// ...
const handleCreate = () => {
const handleCreate = (name: string) => {
createCustomerGroup.mutate({
name,
})
}
// ...
return (
<form>
{/* Render form */}
</form>
)
}
export default CreateCustomerGroup
@@ -147,7 +141,6 @@ You can get a list of all customer groups by sending a request to the List Custo
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { CustomerGroup } from "@medusajs/medusa"
import { useAdminCustomerGroups } from "medusa-react"
const CustomerGroups = () => {
@@ -165,7 +158,7 @@ You can get a list of all customer groups by sending a request to the List Custo
{customer_groups && customer_groups.length > 0 && (
<ul>
{customer_groups.map(
(customerGroup: CustomerGroup) => (
(customerGroup) => (
<li key={customerGroup.id}>
{customerGroup.name}
</li>
@@ -301,28 +294,26 @@ You can update a customer groups data by sending a request to the Update Cust
```tsx
import { useAdminUpdateCustomerGroup } from "medusa-react"
const UpdateCustomerGroup = () => {
type Props = {
customerGroupId: string
}
const CustomerGroup = ({ customerGroupId }: Props) => {
const updateCustomerGroup = useAdminUpdateCustomerGroup(
customerGroupId
)
// ..
const handleUpdate = () => {
const handleUpdate = (name: string) => {
updateCustomerGroup.mutate({
name,
})
}
// ...
return (
<form>
{/* Render form */}
</form>
)
}
export default UpdateCustomerGroup
export default CustomerGroup
```
</TabItem>
@@ -391,7 +382,11 @@ You can delete a customer group by sending a request to the Delete a Customer Gr
```tsx
import { useAdminDeleteCustomerGroup } from "medusa-react"
const CustomerGroup = () => {
type Props = {
customerGroupId: string
}
const CustomerGroup = ({ customerGroupId }: Props) => {
const deleteCustomerGroup = useAdminDeleteCustomerGroup(
customerGroupId
)
@@ -468,13 +463,13 @@ You can add a customer to a group by sending a request to the Customer Groups
import {
useAdminAddCustomersToCustomerGroup,
} from "medusa-react"
const CustomerGroup = () => {
const CustomerGroup = (customerGroupId: string) => {
const addCustomers = useAdminAddCustomersToCustomerGroup(
customerGroupId
)
// ...
const handleAddCustomers= (customerId: string) => {
addCustomers.mutate({
customer_ids: [
@@ -484,10 +479,10 @@ You can add a customer to a group by sending a request to the Customer Groups
],
})
}
// ...
}
export default CustomerGroup
```
@@ -559,10 +554,13 @@ You can retrieve a list of all customers in a customer group using the List Cust
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { Customer } from "@medusajs/medusa"
import { useAdminCustomerGroupCustomers } from "medusa-react"
const CustomerGroup = () => {
type Props = {
customerGroupId: string
}
const CustomerGroup = ({ customerGroupId }: Props) => {
const {
customers,
isLoading,
@@ -578,7 +576,7 @@ You can retrieve a list of all customers in a customer group using the List Cust
)}
{customers && customers.length > 0 && (
<ul>
{customers.map((customer: Customer) => (
{customers.map((customer) => (
<li key={customer.id}>{customer.first_name}</li>
))}
</ul>
@@ -651,23 +649,26 @@ You can remove customers from a customer group by sending a request to the Remov
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { Customer } from "@medusajs/medusa"
import {
useAdminRemoveCustomersFromCustomerGroup,
} from "medusa-react"
const CustomerGroup = () => {
type Props = {
customerGroupId: string
}
const CustomerGroup = ({ customerGroupId }: Props) => {
const removeCustomers =
useAdminRemoveCustomersFromCustomerGroup(
customerGroupId
)
// ...
const handleRemoveCustomer = (customer_id: string) => {
const handleRemoveCustomer = (customerId: string) => {
removeCustomers.mutate({
customer_ids: [
{
id: customer_id,
id: customerId,
},
],
})
@@ -68,7 +68,6 @@ You can show a list of customers by sending a request to the [List Customers API
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { Customer } from "@medusajs/medusa"
import { useAdminCustomers } from "medusa-react"
const Customers = () => {
@@ -82,7 +81,7 @@ You can show a list of customers by sending a request to the [List Customers API
)}
{customers && customers.length > 0 && (
<ul>
{customers.map((customer: Customer) => (
{customers.map((customer) => (
<li key={customer.id}>{customer.first_name}</li>
))}
</ul>
@@ -162,27 +161,26 @@ You can create a customer account by sending a request to the [Create a Customer
```tsx
import { useAdminCreateCustomer } from "medusa-react"
type CustomerData = {
first_name: string
last_name: string
email: string
password: string
}
const CreateCustomer = () => {
const createCustomer = useAdminCreateCustomer()
// ...
const handleCreate = () => {
// ...
createCustomer.mutate({
first_name,
last_name,
email,
password,
const handleCreate = (customerData: CustomerData) => {
createCustomer.mutate(customerData, {
onSuccess: ({ customer }) => {
console.log(customer.id)
}
})
}
// ...
return (
<form>
{/* Render form */}
</form>
)
}
export default CreateCustomer
@@ -265,31 +263,30 @@ You can edit a customers information by sending a request to the [Update a Cu
```tsx
import { useAdminUpdateCustomer } from "medusa-react"
const UpdateCustomer = () => {
const updateCustomer = useAdminUpdateCustomer(customerId)
// ...
const handleUpdate = () => {
// ...
updateCustomer.mutate({
email,
password,
first_name,
last_name,
})
}
// ...
return (
<form>
{/* Render form */}
</form>
)
type CustomerData = {
first_name: string
last_name: string
email: string
password: string
}
export default UpdateCustomer
type Props = {
customerId: string
}
const Customer = ({ customerId }: Props) => {
const updateCustomer = useAdminUpdateCustomer(customerId)
// ...
const handleUpdate = (customerData: CustomerData) => {
updateCustomer.mutate(customerData)
}
// ...
}
export default Customer
```
</TabItem>
@@ -85,23 +85,23 @@ You can register a new customer by sending a request to the [Create a Customer A
const createCustomer = useCreateCustomer()
// ...
const handleCreate = () => {
const handleCreate = (
customerData: {
first_name: string
last_name: string
email: string
password: string
}
) => {
// ...
createCustomer.mutate({
first_name,
last_name,
email,
password,
createCustomer.mutate(customerData, {
onSuccess: ({ customer }) => {
console.log(customer.id)
}
})
}
// ...
return (
<form>
{/* Render form */}
</form>
)
}
export default RegisterCustomer
@@ -370,28 +370,32 @@ You can edit a customers info using the [Update Customer API Route](https://d
```tsx
import { useUpdateMe } from "medusa-react"
const UpdateCustomer = () => {
type Props = {
customerId: string
}
const Customer = ({ customerId }: Props) => {
const updateCustomer = useUpdateMe()
// ...
const handleUpdate = () => {
const handleUpdate = (
firstName: string
) => {
// ...
updateCustomer.mutate({
id: customer_id,
first_name,
id: customerId,
first_name: firstName,
}, {
onSuccess: ({ customer }) => {
console.log(customer.first_name)
}
})
}
// ...
return (
<form>
{/* Render form */}
</form>
)
}
export default UpdateCustomer
export default Customer
```
</TabItem>
@@ -612,19 +616,18 @@ You can retrieve a customers orders by sending a request to the [List Orders
```tsx
import { useCustomerOrders } from "medusa-react"
import { Order } from "@medusajs/medusa"
const Orders = () => {
// refetch a function that can be used to
// re-retrieve orders after the customer logs in
const { orders, isLoading, refetch } = useCustomerOrders()
const { orders, isLoading } = useCustomerOrders()
return (
<div>
{isLoading && <span>Loading orders...</span>}
{orders?.length && (
<ul>
{orders.map((order: Order) => (
{orders.map((order) => (
<li key={order.id}>{order.display_id}</li>
))}
</ul>
@@ -104,15 +104,18 @@ You can create a discount by sending a request to the [Create Discount API Route
AllocationType,
DiscountRuleType,
} from "@medusajs/medusa"
const CreateDiscount = () => {
const createDiscount = useAdminCreateDiscount()
// ...
const handleCreate = () => {
const handleCreate = (
currencyCode: string,
regionId: string
) => {
// ...
createDiscount.mutate({
code,
code: currencyCode,
rule: {
type: DiscountRuleType.FIXED,
value: 10,
@@ -125,10 +128,10 @@ You can create a discount by sending a request to the [Create Discount API Route
is_disabled: false,
})
}
// ...
}
export default CreateDiscount
```
@@ -224,21 +227,24 @@ For example, you can update the discounts description and status by sending t
```tsx
import { useAdminUpdateDiscount } from "medusa-react"
const UpdateDiscount = () => {
const updateDiscount = useAdminUpdateDiscount(discount_id)
type Props = {
discountId: string
}
const Discount = ({ discountId }: Props) => {
const updateDiscount = useAdminUpdateDiscount(discountId)
// ...
const handleUpdate = () => {
// ...
const handleUpdate = (isDisabled: boolean) => {
updateDiscount.mutate({
is_disabled: true,
is_disabled: isDisabled,
})
}
// ...
}
export default UpdateDiscount
export default Discount
```
</TabItem>
@@ -317,25 +323,28 @@ You can send a request to the [Create Condition API Route](https://docs.medusajs
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { useAdminDiscountCreateCondition } from "medusa-react"
import { DiscountConditionOperator } from "@medusajs/medusa"
import { useAdminDiscountCreateCondition } from "medusa-react"
const Discount = () => {
const createCondition = useAdminDiscountCreateCondition(
discount_id
)
type Props = {
discountId: string
}
const Discount = ({ discountId }: Props) => {
const createCondition = useAdminDiscountCreateCondition(discountId)
// ...
const handleCreateCondition = (
operator: DiscountConditionOperator,
productId: string
operator: DiscountConditionOperator,
products: string[]
) => {
// ...
createCondition.mutate({
operator,
products: [
productId,
],
products
}, {
onSuccess: ({ discount }) => {
console.log(discount.id)
}
})
}
@@ -433,32 +442,29 @@ You can retrieve a condition and its resources by sending a request to the [Get
```tsx
import { useAdminGetDiscountCondition } from "medusa-react"
import { Product } from "@medusajs/medusa"
const DiscountCondition = () => {
type Props = {
discountId: string
discountConditionId: string
}
const DiscountCondition = ({
discountId,
discountConditionId
}: Props) => {
const {
discount_condition,
isLoading,
isLoading
} = useAdminGetDiscountCondition(
discount_id,
conditionId
discountId,
discountConditionId
)
// ...
return (
<div>
{isLoading && <span>Loading</span>}
{isLoading && <span>Loading...</span>}
{discount_condition && (
<>
<span>{discount_condition.id}</span>
<ul>
{discount_condition.products.map(
(product: Product) => (
<li key={product.id}>{product.title}</li>
)
)}
</ul>
</>
<span>{discount_condition.type}</span>
)}
</div>
)
@@ -533,18 +539,31 @@ For example, to update the products in a condition:
```tsx
import { useAdminDiscountUpdateCondition } from "medusa-react"
import { Product } from "@medusajs/medusa"
const DiscountCondition = () => {
const updateCondition = useAdminDiscountUpdateCondition(
discount_id,
type Props = {
discountId: string
conditionId: string
}
const DiscountCondition = ({
discountId,
conditionId
}: Props) => {
const update = useAdminDiscountUpdateCondition(
discountId,
conditionId
)
// ...
const handleUpdateCondition = (productIds: string[]) => {
updateCondition.mutate({
products: productIds,
const handleUpdate = (
products: string[]
) => {
update.mutate({
products
}, {
onSuccess: ({ discount }) => {
console.log(discount.id)
}
})
}
@@ -629,14 +648,24 @@ You can delete a condition by sending a request to the [Delete Condition API Rou
```tsx
import { useAdminDiscountRemoveCondition } from "medusa-react"
const Discount = () => {
type Props = {
discountId: string
}
const Discount = ({ discountId }: Props) => {
const deleteCondition = useAdminDiscountRemoveCondition(
discount_id
discountId
)
// ...
const handleUpdateCondition = (conditionId: string) => {
deleteCondition.mutate(conditionId)
const handleDelete = (
conditionId: string
) => {
deleteCondition.mutate(conditionId, {
onSuccess: ({ id, object, deleted }) => {
console.log(deleted)
}
})
}
// ...
@@ -373,20 +373,30 @@ You can update a gift card products details by sending a request to the [Upda
```tsx
import { useAdminUpdateProduct } from "medusa-react"
const UpdateGiftCard = () => {
const createGiftCard = useAdminUpdateProduct(giftCardId)
type Props = {
giftCardId: string
}
const GiftCard = ({
giftCardId
}: Props) => {
const updateGiftCard = useAdminUpdateProduct(giftCardId)
// ...
const handleUpdate = () => {
createGiftCard.mutate({
updateGiftCard.mutate({
description: "The best gift card",
}, {
onSuccess: ({ product }) => {
console.log(product.description)
}
})
}
// ...
}
export default UpdateGiftCard
export default GiftCard
```
</TabItem>
@@ -450,12 +460,20 @@ You can delete a gift card product by sending a request to the [Delete a Product
```tsx
import { useAdminDeleteProduct } from "medusa-react"
const GiftCard = () => {
type Props = {
giftCardId: string
}
const GiftCard = ({ giftCardId }: Props) => {
const deleteGiftCard = useAdminDeleteProduct(giftCardId)
// ...
const handleDelete = () => {
deleteGiftCard.mutate()
deleteGiftCard.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
@@ -521,7 +539,6 @@ You can retrieve all custom gift cards by sending a request to the [List Gift Ca
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { GiftCard } from "@medusajs/medusa"
import { useAdminGiftCards } from "medusa-react"
const CustomGiftCards = () => {
@@ -535,7 +552,7 @@ You can retrieve all custom gift cards by sending a request to the [List Gift Ca
)}
{gift_cards && gift_cards.length > 0 && (
<ul>
{gift_cards.map((giftCard: GiftCard) => (
{gift_cards.map((giftCard) => (
<li key={giftCard.id}>{giftCard.code}</li>
))}
</ul>
@@ -604,10 +621,17 @@ You can create a custom gift card by sending a request to the [Create a Gift Car
const createGiftCard = useAdminCreateGiftCard()
// ...
const handleCreate = (regionId: string, value: number) => {
const handleCreate = (
regionId: string,
value: number
) => {
createGiftCard.mutate({
region_id: regionId,
value,
}, {
onSuccess: ({ gift_card }) => {
console.log(gift_card.id)
}
})
}
@@ -684,7 +708,11 @@ You can update a gift card by sending a request to the [Update a Gift Card API R
```tsx
import { useAdminUpdateGiftCard } from "medusa-react"
const UpdateCustomGiftCards = () => {
type Props = {
customGiftCardId: string
}
const CustomGiftCard = ({ customGiftCardId }: Props) => {
const updateGiftCard = useAdminUpdateGiftCard(
customGiftCardId
)
@@ -699,7 +727,7 @@ You can update a gift card by sending a request to the [Update a Gift Card API R
// ...
}
export default UpdateCustomGiftCards
export default CustomGiftCard
```
</TabItem>
@@ -763,14 +791,22 @@ You can delete a custom gift card by sending a request to the [Delete a Gift Car
```tsx
import { useAdminDeleteGiftCard } from "medusa-react"
const CustomGiftCard = () => {
type Props = {
customGiftCardId: string
}
const CustomGiftCard = ({ customGiftCardId }: Props) => {
const deleteGiftCard = useAdminDeleteGiftCard(
customGiftCardId
)
// ...
const handleDelete = () => {
deleteGiftCard.mutate()
deleteGiftCard.mutate(void 0, {
onSuccess: ({ id, object, deleted}) => {
console.log(id)
}
})
}
// ...
@@ -168,8 +168,14 @@ You can retrieve the details of a gift card by sending a request to the [Get Gif
```tsx
import { useGiftCard } from "medusa-react"
const GiftCard = () => {
const { gift_card, isLoading, isError } = useGiftCard("code")
type Props = {
giftCardCode: string
}
const GiftCard = ({ giftCardCode }: Props) => {
const { gift_card, isLoading, isError } = useGiftCard(
giftCardCode
)
return (
<div>
@@ -78,7 +78,8 @@ You can list inventory items by sending a request to the [List Inventory Items A
function InventoryItems() {
const {
inventory_items,
isLoading } = useAdminInventoryItems()
isLoading
} = useAdminInventoryItems()
return (
<div>
@@ -164,9 +165,13 @@ You can create an inventory item by sending a request to the [Create Inventory I
const createInventoryItem = useAdminCreateInventoryItem()
// ...
const handleCreate = () => {
const handleCreate = (variantId: string) => {
createInventoryItem.mutate({
variant_id,
variant_id: variantId,
}, {
onSuccess: ({ inventory_item }) => {
console.log(inventory_item.id)
}
})
}
@@ -237,10 +242,15 @@ You can retrieve an inventory item by sending a request to the [Get Inventory It
```tsx
import { useAdminInventoryItem } from "medusa-react"
function InventoryItem() {
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const {
inventory_item,
isLoading } = useAdminInventoryItem(inventoryItemId)
isLoading
} = useAdminInventoryItem(inventoryItemId)
return (
<div>
@@ -309,22 +319,30 @@ You can update an inventory item by sending a request to the [Update Inventory I
```tsx
import { useAdminUpdateInventoryItem } from "medusa-react"
const UpdateInventoryItem = () => {
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const updateInventoryItem = useAdminUpdateInventoryItem(
inventoryItemId
)
// ...
const handleUpdate = () => {
const handleUpdate = (origin_country: string) => {
updateInventoryItem.mutate({
origin_country: "US",
origin_country,
}, {
onSuccess: ({ inventory_item }) => {
console.log(inventory_item.origin_country)
}
})
}
// ...
}
export default UpdateInventoryItem
export default InventoryItem
```
</TabItem>
@@ -395,13 +413,17 @@ You can list inventory levels of an inventory item by sending a request to the [
import {
useAdminInventoryItemLocationLevels,
} from "medusa-react"
function InventoryItem() {
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const {
inventory_item,
isLoading,
} = useAdminInventoryItemLocationLevels(inventoryItemId)
return (
<div>
{isLoading && <span>Loading...</span>}
@@ -415,7 +437,7 @@ You can list inventory levels of an inventory item by sending a request to the [
</div>
)
}
export default InventoryItem
```
@@ -475,23 +497,34 @@ You can create a location level by sending a request to the [Create Inventory Le
```tsx
import { useAdminCreateLocationLevel } from "medusa-react"
const CreateLocationLevel = () => {
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const createLocationLevel = useAdminCreateLocationLevel(
inventoryItemId
)
// ...
const handleCreate = () => {
const handleCreateLocationLevel = (
locationId: string,
stockedQuantity: number
) => {
createLocationLevel.mutate({
location_id,
stocked_quantity: 10,
location_id: locationId,
stocked_quantity: stockedQuantity,
}, {
onSuccess: ({ inventory_item }) => {
console.log(inventory_item.id)
}
})
}
// ...
}
export default CreateLocationLevel
export default InventoryItem
```
</TabItem>
@@ -568,23 +601,34 @@ You can update a location level by sending a request to the [Update Location Lev
```tsx
import { useAdminUpdateLocationLevel } from "medusa-react"
const UpdateLocationLevel = () => {
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const updateLocationLevel = useAdminUpdateLocationLevel(
inventoryItemId
)
// ...
const handleUpdate = () => {
const handleUpdate = (
stockLocationId: string,
stockedQuantity: number
) => {
updateLocationLevel.mutate({
stockLocationId,
stocked_quantity: 10,
stocked_quantity: stockedQuantity,
}, {
onSuccess: ({ inventory_item }) => {
console.log(inventory_item.id)
}
})
}
// ...
}
export default UpdateLocationLevel
export default InventoryItem
```
</TabItem>
@@ -653,20 +697,26 @@ You can delete a location level of an inventory item by sending a request to the
```tsx
import { useAdminDeleteLocationLevel } from "medusa-react"
const DeleteLocationLevel = () => {
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const deleteLocationLevel = useAdminDeleteLocationLevel(
inventoryItemId
)
// ...
const handleDelete = () => {
const handleDelete = (
locationId: string
) => {
deleteLocationLevel.mutate(locationId)
}
// ...
}
export default DeleteLocationLevel
export default InventoryItem
```
</TabItem>
@@ -722,7 +772,11 @@ You can delete an inventory item by sending a request to the [Delete Inventory I
```tsx
import { useAdminDeleteInventoryItem } from "medusa-react"
const DeleteInventoryItem = () => {
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const deleteInventoryItem = useAdminDeleteInventoryItem(
inventoryItemId
)
@@ -735,7 +789,7 @@ You can delete an inventory item by sending a request to the [Delete Inventory I
// ...
}
export default DeleteInventoryItem
export default InventoryItem
```
</TabItem>
@@ -267,16 +267,20 @@ You can retrieve a single item allocation by its ID using the [Get a Reservation
```tsx
import { useAdminReservation } from "medusa-react"
function Reservation() {
const {
reservation,
isLoading } = useAdminReservation(reservationId)
type Props = {
reservationId: string
}
const Reservation = ({ reservationId }: Props) => {
const { reservation, isLoading } = useAdminReservation(
reservationId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{reservation && (
<span>{reservation.quantity}</span>
<span>{reservation.inventory_item_id}</span>
)}
</div>
)
@@ -335,22 +339,30 @@ You can update an item allocation to change the location to allocate from or the
```tsx
import { useAdminUpdateReservation } from "medusa-react"
const UpdateReservation = () => {
type Props = {
reservationId: string
}
const Reservation = ({ reservationId }: Props) => {
const updateReservation = useAdminUpdateReservation(
reservationId
)
// ...
const handleCreate = () => {
const handleCreate = (quantity: number) => {
updateReservation.mutate({
quantity,
}, {
onSuccess: ({ reservation }) => {
console.log(reservation.id)
}
})
}
// ...
}
export default UpdateReservation
export default Reservation
```
</TabItem>
@@ -420,20 +432,28 @@ You can delete an item allocation by sending a request to the [Delete Reservatio
```tsx
import { useAdminDeleteReservation } from "medusa-react"
const DeleteReservation = () => {
type Props = {
reservationId: string
}
const Reservation = ({ reservationId }: Props) => {
const deleteReservation = useAdminDeleteReservation(
reservationId
)
// ...
const handleDelete = () => {
deleteReservation.mutate()
deleteReservation.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default DeleteReservation
export default Reservation
```
</TabItem>
@@ -596,7 +616,7 @@ When requesting a return, you can specify the location to return the item to by
location_id,
})
.then(({ order }) => {
console.log(order.id)
console.log(order.returns)
})
```
@@ -606,7 +626,11 @@ When requesting a return, you can specify the location to return the item to by
```tsx
import { useAdminRequestReturn } from "medusa-react"
const RequestReturn = () => {
type Props = {
orderId: string
}
const RequestReturn = ({ orderId }: Props) => {
const requestReturn = useAdminRequestReturn(orderId)
// ...
@@ -620,6 +644,10 @@ When requesting a return, you can specify the location to return the item to by
],
// ...other parameters
location_id,
}, {
onSuccess: ({ order }) => {
console.log(order.returns)
}
})
}
@@ -174,11 +174,19 @@ You can create a reservation by sending a request to the [Create Reservation API
const createReservation = useAdminCreateReservation()
// ...
const handleCreate = () => {
const handleCreate = (
locationId: string,
inventoryItemId: string,
quantity: number
) => {
createReservation.mutate({
location_id,
inventory_item_id,
location_id: locationId,
inventory_item_id: inventoryItemId,
quantity,
}, {
onSuccess: ({ reservation }) => {
console.log(reservation.id)
}
})
}
@@ -259,13 +267,19 @@ You can update a reservation by sending a request to the [Update Reservation API
```tsx
import { useAdminUpdateReservation } from "medusa-react"
const UpdateReservation = () => {
type Props = {
reservationId: string
}
const Reservation = ({ reservationId }: Props) => {
const updateReservation = useAdminUpdateReservation(
reservationId
)
// ...
const handleCreate = () => {
const handleUpdate = (
quantity: number
) => {
updateReservation.mutate({
quantity,
})
@@ -274,7 +288,7 @@ You can update a reservation by sending a request to the [Update Reservation API
// ...
}
export default UpdateReservation
export default Reservation
```
</TabItem>
@@ -344,20 +358,28 @@ You can delete a reservation by sending a request to the [Delete Reservation API
```tsx
import { useAdminDeleteReservation } from "medusa-react"
const DeleteReservation = () => {
type Props = {
reservationId: string
}
const Reservation = ({ reservationId }: Props) => {
const deleteReservation = useAdminDeleteReservation(
reservationId
)
// ...
const handleDelete = () => {
deleteReservation.mutate()
deleteReservation.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default DeleteReservation
export default Reservation
```
</TabItem>
@@ -80,7 +80,8 @@ You can list stock locations by using the [List Stock Locations API Route](https
function StockLocations() {
const {
stock_locations,
isLoading } = useAdminStockLocations()
isLoading
} = useAdminStockLocations()
return (
<div>
@@ -160,9 +161,13 @@ You can create a stock location using the [Create a Stock Location API Route](ht
const createStockLocation = useAdminCreateStockLocation()
// ...
const handleCreate = () => {
const handleCreate = (name: string) => {
createStockLocation.mutate({
name: "Main Warehouse",
name,
}, {
onSuccess: ({ stock_location }) => {
console.log(stock_location.id)
}
})
}
@@ -233,10 +238,15 @@ You can retrieve a stock location by sending a request to the [Get Stock Locatio
```tsx
import { useAdminStockLocation } from "medusa-react"
function StockLocation() {
type Props = {
stockLocationId: string
}
const StockLocation = ({ stockLocationId }: Props) => {
const {
stock_location,
isLoading } = useAdminStockLocation(stockLocationId)
isLoading
} = useAdminStockLocation(stockLocationId)
return (
<div>
@@ -303,21 +313,33 @@ You can associate a stock location with a sales channel by sending a request to
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { useAdminAddLocationToSalesChannel } from "medusa-react"
import {
useAdminAddLocationToSalesChannel
} from "medusa-react"
function StockLocation() {
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const addLocation = useAdminAddLocationToSalesChannel()
// ...
const handleAdd = () => {
const handleAddLocation = (locationId: string) => {
addLocation.mutate({
sales_channel_id,
location_id,
sales_channel_id: salesChannelId,
location_id: locationId
}, {
onSuccess: ({ sales_channel }) => {
console.log(sales_channel.locations)
}
})
}
// ...
}
export default StockLocation
export default SalesChannel
```
</TabItem>
@@ -390,23 +412,32 @@ You can remove the association between a stock location and a sales channel by s
```tsx
import {
useAdminRemoveLocationFromSalesChannel,
useAdminRemoveLocationFromSalesChannel
} from "medusa-react"
function StockLocation() {
const removeLocation =
useAdminRemoveLocationFromSalesChannel()
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const removeLocation = useAdminRemoveLocationFromSalesChannel()
// ...
const handleRemove = () => {
const handleRemoveLocation = (locationId: string) => {
removeLocation.mutate({
sales_channel_id,
location_id,
sales_channel_id: salesChannelId,
location_id: locationId
}, {
onSuccess: ({ sales_channel }) => {
console.log(sales_channel.locations)
}
})
}
// ...
}
export default StockLocation
export default SalesChannel
```
</TabItem>
@@ -484,15 +515,25 @@ You can update a stock location by sending a request to the [Update Stock Locati
```tsx
import { useAdminUpdateStockLocation } from "medusa-react"
function StockLocation() {
type Props = {
stockLocationId: string
}
const StockLocation = ({ stockLocationId }: Props) => {
const updateLocation = useAdminUpdateStockLocation(
stockLocationId
)
// ...
const handleRemove = () => {
const handleUpdate = (
name: string
) => {
updateLocation.mutate({
name: "Warehouse",
name
}, {
onSuccess: ({ stock_location }) => {
console.log(stock_location.name)
}
})
}
}
@@ -563,14 +604,22 @@ You can delete a stock location by sending a request to the [Delete Stock Locati
```tsx
import { useAdminDeleteStockLocation } from "medusa-react"
function StockLocation() {
type Props = {
stockLocationId: string
}
const StockLocation = ({ stockLocationId }: Props) => {
const deleteLocation = useAdminDeleteStockLocation(
stockLocationId
)
// ...
const handleDelete = () => {
deleteLocation.mutate()
deleteLocation.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
}
@@ -100,19 +100,23 @@ To do that, send a request to the [Create an OrderEdit API Route](https://docs.m
```tsx
import { useAdminCreateOrderEdit } from "medusa-react"
const OrderEdit = () => {
const CreateOrderEdit = () => {
const createOrderEdit = useAdminCreateOrderEdit()
const handleCreateOrderEdit = (orderId: string) => {
createOrderEdit.mutate({
order_id: orderId,
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.id)
}
})
}
// ...
}
export default OrderEdit
export default CreateOrderEdit
```
</TabItem>
@@ -195,14 +199,24 @@ To add a new item to the original order, send a request to the [Add Line Item AP
```tsx
import { useAdminOrderEditAddLineItem } from "medusa-react"
const OrderEdit = () => {
const addLineItem = useAdminOrderEditAddLineItem(orderEditId)
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const addLineItem = useAdminOrderEditAddLineItem(
orderEditId
)
const handleAddLineItem =
(quantity: number, variantId: string) => {
addLineItem.mutate({
quantity,
variant_id: variantId,
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.changes)
}
})
}
@@ -279,7 +293,10 @@ To update an item, send a request to the [Update Line Item API Route](https://do
```tsx
import { useAdminOrderEditUpdateLineItem } from "medusa-react"
const OrderEdit = () => {
const OrderEditItemChange = (
orderEditId: string,
itemId: string
) => {
const updateLineItem = useAdminOrderEditUpdateLineItem(
orderEditId,
itemId
@@ -288,13 +305,17 @@ To update an item, send a request to the [Update Line Item API Route](https://do
const handleUpdateLineItem = (quantity: number) => {
updateLineItem.mutate({
quantity,
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.items)
}
})
}
// ...
}
export default OrderEdit
export default OrderEditItemChange
```
</TabItem>
@@ -359,20 +380,32 @@ You can remove an item from the original order by sending a request to the [Remo
```tsx
import { useAdminOrderEditDeleteLineItem } from "medusa-react"
const OrderEdit = () => {
type Props = {
orderEditId: string
itemId: string
}
const OrderEditLineItem = ({
orderEditId,
itemId
}: Props) => {
const removeLineItem = useAdminOrderEditDeleteLineItem(
orderEditId,
itemId
)
const handleRemoveLineItem = () => {
removeLineItem.mutate()
removeLineItem.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.changes)
}
})
}
// ...
}
export default OrderEdit
export default OrderEditLineItem
```
</TabItem>
@@ -428,16 +461,23 @@ To revert an item change, send a request to the [Delete Item Change API Route](h
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { useAdminDeleteOrderEditItemChange } from "medusa-react"
import { useAdminDeleteOrderEdit } from "medusa-react"
const OrderEdit = () => {
const deleteItemChange = useAdminDeleteOrderEditItemChange(
orderEditId,
itemChangeId
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const deleteOrderEdit = useAdminDeleteOrderEdit(
orderEditId
)
const handleDeleteItemChange = () => {
deleteItemChange.mutate()
const handleDelete = () => {
deleteOrderEdit.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
@@ -513,14 +553,25 @@ To move an Order Edit into the request state, send a request to the [Request Con
useAdminRequestOrderEditConfirmation,
} from "medusa-react"
const OrderEdit = () => {
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const requestOrderConfirmation =
useAdminRequestOrderEditConfirmation(
orderEditId
)
const handleRequestConfirmation = () => {
requestOrderConfirmation.mutate()
requestOrderConfirmation.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(
order_edit.requested_at,
order_edit.requested_by
)
}
})
}
// ...
@@ -604,11 +655,24 @@ To confirm an Order Edit, send a request to the [Confirm Order Edit API Route](h
```tsx
import { useAdminConfirmOrderEdit } from "medusa-react"
const OrderEdit = () => {
const confirmOrderEdit = useAdminConfirmOrderEdit(orderEditId)
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const confirmOrderEdit = useAdminConfirmOrderEdit(
orderEditId
)
const handleConfirmOrderEdit = () => {
confirmOrderEdit.mutate()
confirmOrderEdit.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(
order_edit.confirmed_at,
order_edit.confirmed_by
)
}
})
}
// ...
@@ -687,13 +751,22 @@ If the payment is authorized by the customer, it can be captured by sending a re
```tsx
import { useAdminPaymentsCapturePayment } from "medusa-react"
const OrderEditPayment = () => {
const capturePayment = useAdminPaymentsCapturePayment(
type Props = {
paymentId: string
}
const OrderEditPayment = ({ paymentId }: Props) => {
const capture = useAdminPaymentsCapturePayment(
paymentId
)
const handleCapturePayment = () => {
capturePayment.mutate()
// ...
const handleCapture = () => {
capture.mutate(void 0, {
onSuccess: ({ payment }) => {
console.log(payment.amount)
}
})
}
// ...
@@ -757,24 +830,39 @@ To refund the difference to the customer, send a request to the [Refund Payment
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { useAdminPaymentsRefundPayment } from "medusa-react"
import { RefundReason } from "@medusajs/medusa"
import { useAdminPaymentsRefundPayment } from "medusa-react"
const OrderEditPayment = () => {
const refundPayment = useAdminPaymentsRefundPayment(paymentId)
const handleRefundPayment =
(amount: number, reason: RefundReason) => {
refundPayment.mutate({
amount,
reason,
})
}
type Props = {
paymentId: string
}
const Payment = ({ paymentId }: Props) => {
const refund = useAdminPaymentsRefundPayment(
paymentId
)
// ...
const handleRefund = (
amount: number,
reason: RefundReason,
note: string
) => {
refund.mutate({
amount,
reason,
note
}, {
onSuccess: ({ refund }) => {
console.log(refund.amount)
}
})
}
// ...
}
export default OrderEditPayment
export default Payment
```
</TabItem>
@@ -163,19 +163,27 @@ You can create a claim by sending a request to the [Create Claim API Route](http
```tsx
import { useAdminCreateClaim } from "medusa-react"
const CreateClaim = () => {
type Props = {
orderId: string
}
const CreateClaim = ({ orderId }: Props) => {
const createClaim = useAdminCreateClaim(orderId)
// ...
const handleCreate = () => {
const handleCreate = (itemId: string) => {
createClaim.mutate({
type: "refund",
claim_items: [
{
item_id,
item_id: itemId,
quantity: 1,
},
],
}, {
onSuccess: ({ order }) => {
console.log(order.claims)
}
})
}
@@ -275,21 +283,30 @@ You can update a claim by sending a request to the [Update Claim API Route](http
```tsx
import { useAdminUpdateClaim } from "medusa-react"
const UpdateClaim = () => {
type Props = {
orderId: string
claimId: string
}
const Claim = ({ orderId, claimId }: Props) => {
const updateClaim = useAdminUpdateClaim(orderId)
// ...
const handleUpdate = () => {
updateClaim.mutate({
claim_id,
no_notification: true,
claim_id: claimId,
no_notification: false
}, {
onSuccess: ({ order }) => {
console.log(order.claims)
}
})
}
// ...
}
export default UpdateClaim
export default Claim
```
</TabItem>
@@ -365,20 +382,29 @@ You can create a fulfillment for a claim by sending a request to the [Create Cla
```tsx
import { useAdminFulfillClaim } from "medusa-react"
const FulfillClaim = () => {
type Props = {
orderId: string
claimId: string
}
const Claim = ({ orderId, claimId }: Props) => {
const fulfillClaim = useAdminFulfillClaim(orderId)
// ...
const handleFulfill = () => {
fulfillClaim.mutate({
claim_id,
claim_id: claimId,
}, {
onSuccess: ({ order }) => {
console.log(order.claims)
}
})
}
// ...
}
export default FulfillClaim
export default Claim
```
</TabItem>
@@ -436,21 +462,30 @@ You can create a shipment for a claim by sending a request to the [Create Claim
```tsx
import { useAdminCreateClaimShipment } from "medusa-react"
const CreateShipment = () => {
type Props = {
orderId: string
claimId: string
}
const Claim = ({ orderId, claimId }: Props) => {
const createShipment = useAdminCreateClaimShipment(orderId)
// ...
const handleCreate = () => {
const handleCreateShipment = (fulfillmentId: string) => {
createShipment.mutate({
claim_id,
fulfillment_id,
claim_id: claimId,
fulfillment_id: fulfillmentId,
}, {
onSuccess: ({ order }) => {
console.log(order.claims)
}
})
}
// ...
}
export default CreateShipment
export default Claim
```
</TabItem>
@@ -530,23 +565,32 @@ You can cancel a fulfillment by sending a request to the [Cancel Fulfillment API
```tsx
import { useAdminCancelClaimFulfillment } from "medusa-react"
const CancelFulfillment = () => {
type Props = {
orderId: string
claimId: string
}
const Claim = ({ orderId, claimId }: Props) => {
const cancelFulfillment = useAdminCancelClaimFulfillment(
orderId
)
// ...
const handleCancel = () => {
const handleCancel = (fulfillmentId: string) => {
cancelFulfillment.mutate({
claim_id,
fulfillment_id,
claim_id: claimId,
fulfillment_id: fulfillmentId,
}, {
onSuccess: ({ order }) => {
console.log(order.claims)
}
})
}
// ...
}
export default CancelFulfillment
export default Claim
```
</TabItem>
@@ -610,7 +654,12 @@ You can cancel a claim by sending a request to the [Cancel Claim API Route](http
```tsx
import { useAdminCancelClaim } from "medusa-react"
const CancelClaim = () => {
type Props = {
orderId: string
claimId: string
}
const Claim = ({ orderId, claimId }: Props) => {
const cancelClaim = useAdminCancelClaim(orderId)
// ...
@@ -621,7 +670,7 @@ You can cancel a claim by sending a request to the [Cancel Claim API Route](http
// ...
}
export default CancelClaim
export default Claim
```
</TabItem>
@@ -166,34 +166,28 @@ You can create a draft order by sending a request to the [Create Draft Order API
```tsx
import { useAdminCreateDraftOrder } from "medusa-react"
type DraftOrderData = {
email: string
region_id: string
items: {
quantity: number,
variant_id: string
}[]
shipping_methods: {
option_id: string
price: number
}[]
}
const CreateDraftOrder = () => {
const createDraftOrder = useAdminCreateDraftOrder()
// ...
const handleCreate = () => {
createDraftOrder.mutate({
email,
region_id,
items: [
{
// defined product
quantity: 1,
variant_id,
},
{
// custom product
quantity: 1,
unit_price: 1000,
title: "Custom Product",
},
],
shipping_methods: [
{
option_id,
// for custom shipping price
price,
},
],
const handleCreate = (data: DraftOrderData) => {
createDraftOrder.mutate(data, {
onSuccess: ({ draft_order }) => {
console.log(draft_order.id)
}
})
}
@@ -316,12 +310,16 @@ You can retrieve a draft order by sending a request to the [Get Draft Order API
```tsx
import { useAdminDraftOrder } from "medusa-react"
const DraftOrder = () => {
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const {
draft_order,
isLoading,
} = useAdminDraftOrder(draftOrderId)
return (
<div>
{isLoading && <span>Loading...</span>}
@@ -386,22 +384,30 @@ You can update a draft order by sending a request to the [Update Draft Order API
```tsx
import { useAdminUpdateDraftOrder } from "medusa-react"
const UpdateDraftOrder = () => {
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const updateDraftOrder = useAdminUpdateDraftOrder(
draftOrderId
)
// ...
const handleUpdate = () => {
const handleUpdate = (email: string) => {
updateDraftOrder.mutate({
email: "user@example.com",
email,
}, {
onSuccess: ({ draft_order }) => {
console.log(draft_order.id)
}
})
}
// ...
}
export default UpdateDraftOrder
export default DraftOrder
```
</TabItem>
@@ -471,22 +477,30 @@ You can add line items to a draft order by sending a request to the [Create Line
```tsx
import { useAdminDraftOrderAddLineItem } from "medusa-react"
const AddLineItem = () => {
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const addLineItem = useAdminDraftOrderAddLineItem(
draftOrderId
)
// ...
const handleAdd = () => {
const handleAdd = (quantity: number) => {
addLineItem.mutate({
quantity: 1,
quantity,
}, {
onSuccess: ({ draft_order }) => {
console.log(draft_order.cart)
}
})
}
// ...
}
export default AddLineItem
export default DraftOrder
```
</TabItem>
@@ -561,23 +575,30 @@ You can update a line item by sending a request to the [Update Line Item API Rou
```tsx
import { useAdminDraftOrderUpdateLineItem } from "medusa-react"
const UpdateLineItem = () => {
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const updateLineItem = useAdminDraftOrderUpdateLineItem(
draftOrderId
)
// ...
const handleUpdate = () => {
const handleUpdate = (
itemId: string,
quantity: number
) => {
updateLineItem.mutate({
item_id,
quantity: 1,
item_id: itemId,
quantity,
})
}
// ...
}
export default UpdateLineItem
export default DraftOrder
```
</TabItem>
@@ -643,20 +664,24 @@ You can delete a line item by sending a request to the [Delete Line Item API Rou
```tsx
import { useAdminDraftOrderRemoveLineItem } from "medusa-react"
const DeleteLineItem = () => {
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const deleteLineItem = useAdminDraftOrderRemoveLineItem(
draftOrderId
)
// ...
const handleDelete = () => {
const handleDelete = (itemId: string) => {
deleteLineItem.mutate(itemId)
}
// ...
}
export default DeleteLineItem
export default DraftOrder
```
</TabItem>
@@ -714,20 +739,28 @@ You can register the draft order payment by sending a request to the [Register D
```tsx
import { useAdminDraftOrderRegisterPayment } from "medusa-react"
const RegisterPayment = () => {
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const registerPayment = useAdminDraftOrderRegisterPayment(
draftOrderId
)
// ...
const handlePayment = () => {
registerPayment.mutate()
registerPayment.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.id)
}
})
}
// ...
}
export default RegisterPayment
export default DraftOrder
```
</TabItem>
@@ -781,20 +814,28 @@ You can delete a draft order by sending a request to the [Delete Draft Order API
```tsx
import { useAdminDeleteDraftOrder } from "medusa-react"
const DeleteDraftOrder = () => {
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const deleteDraftOrder = useAdminDeleteDraftOrder(
draftOrderId
)
// ...
const handleDelete = () => {
deleteDraftOrder.mutate()
deleteDraftOrder.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default DeleteDraftOrder
export default DraftOrder
```
</TabItem>
@@ -398,7 +398,11 @@ You can retrieve an order by sending a request to the [Get an Order API Route](h
```tsx
import { useAdminOrder } from "medusa-react"
const Order = () => {
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const {
order,
isLoading,
@@ -481,22 +485,31 @@ You can update any of the above details of an order by sending a request to the
```tsx
import { useAdminUpdateOrder } from "medusa-react"
const UpdateOrder = () => {
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const updateOrder = useAdminUpdateOrder(
orderId
)
// ...
const handleUpdate = () => {
const handleUpdate = (
email: string
) => {
updateOrder.mutate({
email,
}, {
onSuccess: ({ order }) => {
console.log(order.email)
}
})
}
// ...
}
export default UpdateOrder
export default Order
```
</TabItem>
@@ -564,20 +577,28 @@ You can capture an orders payment by sending a request to the [Capture Order
```tsx
import { useAdminCapturePayment } from "medusa-react"
const CapturePayment = () => {
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const capturePayment = useAdminCapturePayment(
orderId
)
// ...
const handleCapture = () => {
capturePayment.mutate()
capturePayment.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.status)
}
})
}
// ...
}
export default CapturePayment
export default Order
```
</TabItem>
@@ -634,23 +655,34 @@ To refund payment, send a request to the [Refund Payment API Route](https://docs
```tsx
import { useAdminRefundPayment } from "medusa-react"
const RefundPayment = () => {
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const refundPayment = useAdminRefundPayment(
orderId
)
// ...
const handleRefund = () => {
const handleRefund = (
amount: number,
reason: string
) => {
refundPayment.mutate({
amount,
reason,
}, {
onSuccess: ({ order }) => {
console.log(order.refunds)
}
})
}
// ...
}
export default RefundPayment
export default Order
```
</TabItem>
@@ -732,27 +764,38 @@ You can create a fulfillment by sending a request to the [Create a Fulfillment A
```tsx
import { useAdminCreateFulfillment } from "medusa-react"
const CreateFullfillment = () => {
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const createFulfillment = useAdminCreateFulfillment(
orderId
)
// ...
const handleCreate = () => {
const handleCreateFulfillment = (
itemId: string,
quantity: number
) => {
createFulfillment.mutate({
items: [
{
itemId,
item_id: itemId,
quantity,
},
],
}, {
onSuccess: ({ order }) => {
console.log(order.fulfillments)
}
})
}
// ...
}
export default CreateFullfillment
export default Order
```
</TabItem>
@@ -835,22 +878,32 @@ You can create a shipment for a fulfillment by sending a request to the [Create
```tsx
import { useAdminCreateShipment } from "medusa-react"
const CreateShipment = () => {
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const createShipment = useAdminCreateShipment(
orderId
)
// ...
const handleCreate = () => {
const handleCreate = (
fulfillmentId: string
) => {
createShipment.mutate({
fulfillment_id,
fulfillment_id: fulfillmentId,
}, {
onSuccess: ({ order }) => {
console.log(order.fulfillment_status)
}
})
}
// ...
}
export default CreateShipment
export default Order
```
</TabItem>
@@ -914,20 +967,30 @@ You can cancel a fulfillment by sending a request to the [Cancel Fulfillment API
```tsx
import { useAdminCancelFulfillment } from "medusa-react"
const CancelFulfillment = () => {
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const cancelFulfillment = useAdminCancelFulfillment(
orderId
)
// ...
const handleCancel = () => {
cancelFulfillment.mutate(fulfillment_id)
const handleCancel = (
fulfillmentId: string
) => {
cancelFulfillment.mutate(fulfillmentId, {
onSuccess: ({ order }) => {
console.log(order.fulfillments)
}
})
}
// ...
}
export default CancelFulfillment
export default Order
```
</TabItem>
@@ -983,20 +1046,28 @@ You can mark an order completed, changing its status, by sending a request to th
```tsx
import { useAdminCompleteOrder } from "medusa-react"
const CompleteOrder = () => {
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const completeOrder = useAdminCompleteOrder(
orderId
)
// ...
const handleComplete = () => {
completeOrder.mutate()
completeOrder.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.status)
}
})
}
// ...
}
export default CompleteOrder
export default Order
```
</TabItem>
@@ -1050,20 +1121,28 @@ You can cancel an order by sending a request to the [Cancel Order API Route](htt
```tsx
import { useAdminCancelOrder } from "medusa-react"
const CancelOrder = () => {
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const cancelOrder = useAdminCancelOrder(
orderId
)
// ...
const handleCancel = () => {
cancelOrder.mutate()
cancelOrder.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.status)
}
})
}
// ...
}
export default CancelOrder
export default Order
```
</TabItem>
@@ -1117,20 +1196,28 @@ You can archive an order by sending a request to the [Archive Order API Route](h
```tsx
import { useAdminArchiveOrder } from "medusa-react"
const ArchiveOrder = () => {
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const archiveOrder = useAdminArchiveOrder(
orderId
)
// ...
const handleArchive = () => {
archiveOrder.mutate()
const handleArchivingOrder = () => {
archiveOrder.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.status)
}
})
}
// ...
}
export default ArchiveOrder
export default Order
```
</TabItem>
@@ -155,10 +155,17 @@ You can create a return reason using the [Create Return Reason API Route](https:
const createReturnReason = useAdminCreateReturnReason()
// ...
const handleCreate = () => {
const handleCreate = (
label: string,
value: string
) => {
createReturnReason.mutate({
label: "Damaged",
value: "damaged",
label,
value,
}, {
onSuccess: ({ return_reason }) => {
console.log(return_reason.id)
}
})
}
@@ -236,22 +243,32 @@ You can update a return reason by sending a request to the [Update Return Reason
```tsx
import { useAdminUpdateReturnReason } from "medusa-react"
const UpdateReturnReason = () => {
type Props = {
returnReasonId: string
}
const ReturnReason = ({ returnReasonId }: Props) => {
const updateReturnReason = useAdminUpdateReturnReason(
returnReasonId
)
// ...
const handleUpdate = () => {
const handleUpdate = (
label: string
) => {
updateReturnReason.mutate({
label: "Damaged",
label,
}, {
onSuccess: ({ return_reason }) => {
console.log(return_reason.label)
}
})
}
// ...
}
export default UpdateReturnReason
export default ReturnReason
```
</TabItem>
@@ -315,20 +332,28 @@ You can delete a return reason by sending a request to the [Delete Return Reason
```tsx
import { useAdminDeleteReturnReason } from "medusa-react"
const DeleteReturnReason = () => {
type Props = {
returnReasonId: string
}
const ReturnReason = ({ returnReasonId }: Props) => {
const deleteReturnReason = useAdminDeleteReturnReason(
returnReasonId
)
// ...
const handleDelete = () => {
deleteReturnReason.mutate()
deleteReturnReason.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default DeleteReturnReason
export default ReturnReason
```
</TabItem>
@@ -492,22 +517,35 @@ You can mark a return as received by sending a request to the [Receive a Return
```tsx
import { useAdminReceiveReturn } from "medusa-react"
const ReceiveReturn = () => {
type ReceiveReturnData = {
items: {
item_id: string
quantity: number
}[]
}
type Props = {
returnId: string
}
const Return = ({ returnId }: Props) => {
const receiveReturn = useAdminReceiveReturn(
returnId
)
// ...
const handleReceive = () => {
receiveReturn.mutate({
email,
const handleReceive = (data: ReceiveReturnData) => {
receiveReturn.mutate(data, {
onSuccess: ({ return: dataReturn }) => {
console.log(dataReturn.status)
}
})
}
// ...
}
export default ReceiveReturn
export default Return
```
</TabItem>
@@ -594,20 +632,28 @@ You can cancel a return by sending a request to the [Cancel Return API Route](ht
```tsx
import { useAdminCancelReturn } from "medusa-react"
const CancelReturn = () => {
type Props = {
returnId: string
}
const Return = ({ returnId }: Props) => {
const cancelReturn = useAdminCancelReturn(
returnId
)
// ...
const handleCancel = () => {
cancelReturn.mutate()
cancelReturn.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.returns)
}
})
}
// ...
}
export default CancelReturn
export default Return
```
</TabItem>
@@ -163,20 +163,32 @@ Regardless of whether you need to refund or capture the payment, you can process
```tsx
import { useAdminProcessSwapPayment } from "medusa-react"
const ProcessPayment = () => {
type Props = {
orderId: string,
swapId: string
}
const Swap = ({
orderId,
swapId
}: Props) => {
const processPayment = useAdminProcessSwapPayment(
orderId
)
// ...
const handleProcess = () => {
processPayment.mutate(swapId)
const handleProcessPayment = () => {
processPayment.mutate(swapId, {
onSuccess: ({ order }) => {
console.log(order.swaps)
}
})
}
// ...
}
export default ProcessPayment
export default Swap
```
</TabItem>
@@ -239,7 +251,15 @@ You can create a fulfillment for a swap by sending a request to the [Create Swap
```tsx
import { useAdminFulfillSwap } from "medusa-react"
const FulfillSwap = () => {
type Props = {
orderId: string,
swapId: string
}
const Swap = ({
orderId,
swapId
}: Props) => {
const fulfillSwap = useAdminFulfillSwap(
orderId
)
@@ -248,13 +268,17 @@ You can create a fulfillment for a swap by sending a request to the [Create Swap
const handleFulfill = () => {
fulfillSwap.mutate({
swap_id: swapId,
}, {
onSuccess: ({ order }) => {
console.log(order.swaps)
}
})
}
// ...
}
export default FulfillSwap
export default Swap
```
</TabItem>
@@ -312,23 +336,37 @@ You can create a shipment for a swaps fulfillment using the [Create Swap Ship
```tsx
import { useAdminCreateSwapShipment } from "medusa-react"
const CreateShipment = () => {
type Props = {
orderId: string,
swapId: string
}
const Swap = ({
orderId,
swapId
}: Props) => {
const createShipment = useAdminCreateSwapShipment(
orderId
)
// ...
const handleCreate = () => {
const handleCreateShipment = (
fulfillmentId: string
) => {
createShipment.mutate({
swap_id,
fulfillment_id,
swap_id: swapId,
fulfillment_id: fulfillmentId,
}, {
onSuccess: ({ order }) => {
console.log(order.swaps)
}
})
}
// ...
}
export default CreateShipment
export default Swap
```
</TabItem>
@@ -408,23 +446,33 @@ You can cancel a fulfillment by sending a request to the [Cancel Swap Fulfillmen
```tsx
import { useAdminCancelSwapFulfillment } from "medusa-react"
const CancelFulfillment = () => {
type Props = {
orderId: string,
swapId: string
}
const Swap = ({
orderId,
swapId
}: Props) => {
const cancelFulfillment = useAdminCancelSwapFulfillment(
orderId
)
// ...
const handleCancel = () => {
const handleCancelFulfillment = (
fulfillmentId: string
) => {
cancelFulfillment.mutate({
swap_id,
fulfillment_id,
swap_id: swapId,
fulfillment_id: fulfillmentId,
})
}
// ...
}
export default CancelFulfillment
export default Swap
```
</TabItem>
@@ -488,20 +536,32 @@ You can cancel a swap by sending a request to the [Cancel Swap API Route](https:
```tsx
import { useAdminCancelSwap } from "medusa-react"
const CancelSwap = () => {
type Props = {
orderId: string,
swapId: string
}
const Swap = ({
orderId,
swapId
}: Props) => {
const cancelSwap = useAdminCancelSwap(
orderId
)
// ...
const handleCancel = () => {
cancelSwap.mutate(swapId)
cancelSwap.mutate(swapId, {
onSuccess: ({ order }) => {
console.log(order.swaps)
}
})
}
// ...
}
export default CancelSwap
export default Swap
```
</TabItem>
@@ -158,22 +158,32 @@ You can create the return by sending a request to the [Create Return API Route](
```tsx
import { useCreateReturn } from "medusa-react"
const CreateReturn = () => {
type CreateReturnData = {
items: {
item_id: string,
quantity: number
}[]
return_shipping: {
option_id: string
}
}
type Props = {
orderId: string
}
const CreateReturn = ({ orderId }: Props) => {
const createReturn = useCreateReturn()
// ...
const handleCreate = () => {
const handleCreate = (data: CreateReturnData) => {
createReturn.mutate({
order_id,
items: [
{
item_id,
quantity: 1,
},
],
return_shipping: {
option_id,
},
...data,
order_id: orderId
}, {
onSuccess: ({ return: returnData }) => {
console.log(returnData.id)
}
})
}
@@ -113,6 +113,10 @@ After collecting the swap details in step 1, you can create a swap in the Medusa
},
],
return_shipping_option,
}, {
onSuccess: ({ swap }) => {
console.log(swap.id)
}
})
}
@@ -205,8 +209,11 @@ During your checkout flow, you might need to retrieve the swap using the cart
```tsx
import { useCartSwap } from "medusa-react"
type Props = {
cartId: string
}
const Swap = () => {
const Swap = ({ cartId }: Props) => {
const {
swap,
isLoading,
@@ -89,10 +89,25 @@ You can retrieve a single order edit by its ID by sending a request to the [Get
```tsx
import { useOrderEdit } from "medusa-react"
const OrderEdit = () => {
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const { order_edit, isLoading } = useOrderEdit(orderEditId)
// ...
return (
<div>
{isLoading && <span>Loading...</span>}
{order_edit && (
<ul>
{order_edit.changes.map((change) => (
<li key={change.id}>{change.type}</li>
))}
</ul>
)}
</div>
)
}
export default OrderEdit
@@ -220,7 +235,13 @@ If `difference_due` is greater than 0, then additional payment from the customer
```tsx
import { useManagePaymentSession } from "medusa-react"
const OrderEditPayment = () => {
type Props = {
paymentCollectionId: string
}
const OrderEditPayment = ({
paymentCollectionId
}: Props) => {
const managePaymentSession = useManagePaymentSession(
paymentCollectionId
)
@@ -229,6 +250,10 @@ If `difference_due` is greater than 0, then additional payment from the customer
const handleAdditionalPayment = (provider_id: string) => {
managePaymentSession.mutate({
provider_id,
}, {
onSuccess: ({ payment_collection }) => {
console.log(payment_collection.payment_sessions)
}
})
}
@@ -279,8 +304,8 @@ If `difference_due` is greater than 0, then additional payment from the customer
paymentCollectionId,
paymentSessionId
)
.then(({ payment_session }) => {
console.log(payment_session.id)
.then(({ payment_collection }) => {
console.log(payment_collection.payment_sessions)
})
```
@@ -290,14 +315,24 @@ If `difference_due` is greater than 0, then additional payment from the customer
```tsx
import { useAuthorizePaymentSession } from "medusa-react"
const OrderEditPayment = () => {
type Props = {
paymentCollectionId: string
}
const OrderEditPayment = ({
paymentCollectionId
}: Props) => {
const authorizePaymentSession = useAuthorizePaymentSession(
paymentCollectionId
)
// ...
const handleAuthorizePayment = (paymentSessionId: string) => {
authorizePaymentSession.mutate(paymentSessionId)
authorizePaymentSession.mutate(paymentSessionId, {
onSuccess: ({ payment_collection }) => {
console.log(payment_collection.payment_sessions)
}
})
}
// ...
@@ -321,8 +356,8 @@ If `difference_due` is greater than 0, then additional payment from the customer
}
)
.then((response) => response.json())
.then(({ payment_session }) => {
console.log(payment_session.id)
.then(({ payment_collection }) => {
console.log(payment_collection.payment_sessions)
})
```
@@ -353,12 +388,22 @@ To confirm and complete the order edit, send a request to the [Complete Order Ed
```tsx
import { useCompleteOrderEdit } from "medusa-react"
const OrderEdit = () => {
const completeOrderEdit = useCompleteOrderEdit(orderEditId)
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const completeOrderEdit = useCompleteOrderEdit(
orderEditId
)
// ...
const handleCompleteOrderEdit = () => {
completeOrderEdit.mutate()
completeOrderEdit.mutate(void 0, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.confirmed_at)
}
})
}
// ...
@@ -422,13 +467,23 @@ If the customer wants to decline the Order Edit, you can do that by sending a re
```tsx
import { useDeclineOrderEdit } from "medusa-react"
const OrderEdit = () => {
type Props = {
orderEditId: string
}
const OrderEdit = ({ orderEditId }: Props) => {
const declineOrderEdit = useDeclineOrderEdit(orderEditId)
// ...
const handleDeclineOrderEdit = () => {
const handleDeclineOrderEdit = (
declinedReason: string
) => {
declineOrderEdit.mutate({
declined_reason: "I am not satisfied",
declined_reason: declinedReason,
}, {
onSuccess: ({ order_edit }) => {
console.log(order_edit.declined_at)
}
})
}
@@ -96,6 +96,36 @@ To allow the customer to claim an order, send a request to the Claim an Order AP
})
```
</TabItem>
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { useRequestOrderAccess } from "medusa-react"
const ClaimOrder = () => {
const claimOrder = useRequestOrderAccess()
const handleClaimOrder = (
orderIds: string[]
) => {
claimOrder.mutate({
order_ids: orderIds
}, {
onSuccess: () => {
// successful
},
onError: () => {
// an error occurred.
}
})
}
// ...
}
export default ClaimOrder
```
</TabItem>
<TabItem value="fetch" label="Fetch API">
@@ -159,15 +189,23 @@ Then, you send a request to the Verify Claim Order API Route:
import { useGrantOrderAccess } from "medusa-react"
const ClaimOrder = () => {
const grantOrderAccess = useGrantOrderAccess()
// ...
const confirmOrderRequest = useGrantOrderAccess()
const handleVerifyOrderClaim = (token: string) => {
grantOrderAccess.mutate(({
token,
}))
const handleOrderRequestConfirmation = (
token: string
) => {
confirmOrderRequest.mutate({
token
}, {
onSuccess: () => {
// successful
},
onError: () => {
// an error occurred.
}
})
}
// ...
}
@@ -54,7 +54,11 @@ You can retrieve an order by its ID using the [Get Order API Route](https://docs
```tsx
import { useOrder } from "medusa-react"
const Order = () => {
type Props = {
orderId: string
}
const Order = ({ orderId }: Props) => {
const {
order,
isLoading,
@@ -119,13 +123,21 @@ You can retrieve an order by its display ID using the [Look Up Order API Route](
```tsx
import { useOrders } from "medusa-react"
const Order = () => {
type Props = {
displayId: number
email: string
}
const Order = ({
displayId,
email
}: Props) => {
const {
order,
isLoading,
} = useOrders({
display_id: 1,
email: "user@example.com",
display_id: displayId,
email,
})
return (
@@ -191,7 +203,11 @@ You can retrieve an order by the cart ID using the [Get by Cart ID API Route](ht
```tsx
import { useCartOrder } from "medusa-react"
const Order = () => {
type Props = {
cartId: string
}
const Order = ({ cartId }: Props) => {
const {
order,
isLoading,
@@ -350,7 +350,11 @@ You can retrieve all the details of the batch job, including its status and the
```tsx
import { useAdminBatchJob } from "medusa-react"
const ImportPrices = () => {
type Props = {
batchJobId: string
}
const ImportPrices = ({ batchJobId }: Props) => {
const { batch_job, isLoading } = useAdminBatchJob(batchJobId)
// ...
@@ -440,7 +444,11 @@ To confirm a batch job send the following request:
```tsx
import { useAdminConfirmBatchJob } from "medusa-react"
const ImportPrices = () => {
type Props = {
batchJobId: string
}
const BatchJob = ({ batchJobId }: Props) => {
const confirmBatchJob = useAdminConfirmBatchJob(batchJobId)
// ...
@@ -114,36 +114,36 @@ For example, sending the following request creates a price list with two prices:
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { useAdminCreatePriceList } from "medusa-react"
import {
PriceListStatus,
PriceListType,
} from "@medusajs/medusa"
import { useAdminCreatePriceList } from "medusa-react"
type CreateData = {
name: string
description: string
type: PriceListType
status: PriceListStatus
prices: {
amount: number
variant_id: string
currency_code: string
max_quantity: number
}[]
}
const CreatePriceList = () => {
const createPriceList = useAdminCreatePriceList()
// ...
const handleCreate = () => {
createPriceList.mutate({
name: "New Price List",
description: "A new price list",
type: PriceListType.SALE,
status: PriceListStatus.ACTIVE,
prices: [
{
amount: 1000,
variant_id,
currency_code: "eur",
max_quantity: 3,
},
{
amount: 1500,
variant_id,
currency_code: "eur",
min_quantity: 4,
},
],
const handleCreate = (
data: CreateData
) => {
createPriceList.mutate(data, {
onSuccess: ({ price_list }) => {
console.log(price_list.id)
}
})
}
@@ -246,15 +246,20 @@ You can retrieve all of a price lists details using the Get a Price List API
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { CustomerGroup } from "@medusajs/medusa"
import { useAdminPriceList } from "medusa-react"
const PriceList = () => {
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const {
price_list,
isLoading,
} = useAdminPriceList(priceListId)
return (
<div>
{isLoading && <span>Loading...</span>}
@@ -262,7 +267,7 @@ You can retrieve all of a price lists details using the Get a Price List API
</div>
)
}
export default PriceList
```
@@ -314,26 +319,34 @@ For example, by sending the following request the end date of the price list wil
<TabItem value="medusa-react" label="Medusa React">
```tsx
import {
PriceListStatus,
PriceListType,
} from "@medusajs/medusa"
import { useAdminUpdatePriceList } from "medusa-react"
const CreatePriceList = () => {
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const updatePriceList = useAdminUpdatePriceList(priceListId)
// ...
const handleUpdate = () => {
const handleUpdate = (
endsAt: Date
) => {
updatePriceList.mutate({
ends_at: "2022-10-11",
ends_at: endsAt,
}, {
onSuccess: ({ price_list }) => {
console.log(price_list.ends_at)
}
})
}
// ...
}
export default CreatePriceList
export default PriceList
```
</TabItem>
@@ -411,25 +424,35 @@ For example, sending the following request adds a new price to the price list:
```tsx
import { useAdminCreatePriceListPrices } from "medusa-react"
const PriceList = () => {
const addPrice = useAdminCreatePriceListPrices(priceListId)
// ...
const handleAddPrice = () => {
addPrice.mutate({
prices: [
{
amount: 1200,
variant_id,
currency_code: "eur",
},
],
})
}
// ...
type PriceData = {
amount: number
variant_id: string
currency_code: string
}
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const addPrices = useAdminCreatePriceListPrices(priceListId)
// ...
const handleAddPrices = (prices: PriceData[]) => {
addPrices.mutate({
prices
}, {
onSuccess: ({ price_list }) => {
console.log(price_list.prices)
}
})
}
// ...
}
export default PriceList
```
@@ -508,24 +531,36 @@ You can delete all the prices of a products variants using the [Delete Produc
```tsx
import {
useAdminDeletePriceListProductPrices,
useAdminDeletePriceListProductPrices
} from "medusa-react"
const PriceList = () => {
const deletePrices = useAdminDeletePriceListProductPrices(
type Props = {
priceListId: string
productId: string
}
const PriceListProduct = ({
priceListId,
productId
}: Props) => {
const deleteProductPrices = useAdminDeletePriceListProductPrices(
priceListId,
productId
)
// ...
const handleDeletePrices = () => {
deletePrices.mutate()
const handleDeleteProductPrices = () => {
deleteProductPrices.mutate(void 0, {
onSuccess: ({ ids, deleted, object }) => {
console.log(ids)
}
})
}
// ...
}
export default PriceList
export default PriceListProduct
```
</TabItem>
@@ -582,25 +617,36 @@ You can delete all the prices of a variant using the [Delete Variant Prices API
```tsx
import {
useAdminDeletePriceListVariantPrices,
useAdminDeletePriceListVariantPrices
} from "medusa-react"
const PriceList = () => {
const deleteVariantPrices =
useAdminDeletePriceListVariantPrices(
priceListId,
variantId
)
type Props = {
priceListId: string
variantId: string
}
const PriceListVariant = ({
priceListId,
variantId
}: Props) => {
const deleteVariantPrices = useAdminDeletePriceListVariantPrices(
priceListId,
variantId
)
// ...
const handleDeletePrices = () => {
deleteVariantPrices.mutate()
const handleDeleteVariantPrices = () => {
deleteVariantPrices.mutate(void 0, {
onSuccess: ({ ids, deleted, object }) => {
console.log(ids)
}
})
}
// ...
}
export default PriceList
export default PriceListVariant
```
</TabItem>
@@ -657,12 +703,22 @@ You can delete a price list, and subsequently all prices defined in it, using th
```tsx
import { useAdminDeletePriceList } from "medusa-react"
const PriceList = () => {
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const deletePriceList = useAdminDeletePriceList(priceListId)
// ...
const handleDeletePriceList = () => {
deletePriceList.mutate()
const handleDelete = () => {
deletePriceList.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
@@ -889,7 +889,11 @@ You can do that by sending the following request to the [Upload Files API Route]
// ...
const handleFileUpload = (file: File) => {
uploadFile.mutate(file)
uploadFile.mutate(file, {
onSuccess: ({ uploads }) => {
console.log(uploads[0].key)
}
})
}
// ...
@@ -1067,7 +1071,11 @@ You can retrieve all the details of the batch job, including its status and the
```tsx
import { useAdminBatchJob } from "medusa-react"
const ImportProducts = () => {
type Props = {
batchJobId: string
}
const ImportProducts = ({ batchJobId }: Props) => {
const { batch_job, isLoading } = useAdminBatchJob(batchJobId)
// ...
@@ -1157,7 +1165,11 @@ To confirm a batch job send the following request:
```tsx
import { useAdminConfirmBatchJob } from "medusa-react"
const ImportProducts = () => {
type Props = {
batchJobId: string
}
const BatchJob = ({ batchJobId }: Props) => {
const confirmBatchJob = useAdminConfirmBatchJob(batchJobId)
// ...
@@ -69,12 +69,12 @@ You can retrieve available categories by sending a request to the [List Categori
```tsx
import { useAdminProductCategories } from "medusa-react"
import { ProductCategory } from "@medusajs/medusa"
function Categories() {
const {
product_categories,
isLoading } = useAdminProductCategories()
isLoading
} = useAdminProductCategories()
return (
<div>
@@ -85,7 +85,7 @@ You can retrieve available categories by sending a request to the [List Categori
{product_categories && product_categories.length > 0 && (
<ul>
{product_categories.map(
(category: ProductCategory) => (
(category) => (
<li key={category.id}>{category.name}</li>
)
)}
@@ -155,9 +155,15 @@ You can create a category by sending a request to the [Create a Category API Rou
const createCategory = useAdminCreateProductCategory()
// ...
const handleCreate = () => {
const handleCreate = (
name: string
) => {
createCategory.mutate({
name: "Skinny Jeans",
name,
}, {
onSuccess: ({ product_category }) => {
console.log(product_category.id)
}
})
}
@@ -233,7 +239,13 @@ You can retrieve a product category by sending a request to the [Get a Product C
```tsx
import { useAdminProductCategory } from "medusa-react"
const Category = () => {
type Props = {
productCategoryId: string
}
const Category = ({
productCategoryId
}: Props) => {
const {
product_category,
isLoading,
@@ -305,22 +317,34 @@ You can edit a product category by sending a request to the [Update a Product Ca
```tsx
import { useAdminUpdateProductCategory } from "medusa-react"
const UpdateCategory = () => {
type Props = {
productCategoryId: string
}
const Category = ({
productCategoryId
}: Props) => {
const updateCategory = useAdminUpdateProductCategory(
productCategoryId
)
// ...
const handleUpdate = () => {
const handleUpdate = (
name: string
) => {
updateCategory.mutate({
name: "Skinny Jeans",
name,
}, {
onSuccess: ({ product_category }) => {
console.log(product_category.id)
}
})
}
// ...
}
export default UpdateCategory
export default Category
```
</TabItem>
@@ -407,29 +431,34 @@ You can add more than one product to a category using the [Add Products to a Cat
```tsx
import { useAdminAddProductsToCategory } from "medusa-react"
const UpdateProductsInCategory = () => {
const addProductsToCategory = useAdminAddProductsToCategory(
type Props = {
productCategoryId: string
}
const Category = ({
productCategoryId
}: Props) => {
const addProducts = useAdminAddProductsToCategory(
productCategoryId
)
// ...
const handleAdd = () => {
addProductsToCategory.mutate({
product_ids: [
{
id: productId1,
},
{
id: productId2,
},
],
const handleAddProducts = (
productIds: ProductsData[]
) => {
addProducts.mutate({
product_ids: productIds
}, {
onSuccess: ({ product_category }) => {
console.log(product_category.products)
}
})
}
// ...
}
export default UpdateProductsInCategory
export default Category
```
</TabItem>
@@ -519,32 +548,40 @@ You can remove products from a category by sending a request to the [Delete Prod
<TabItem value="medusa-react" label="Medusa React">
```tsx
import {
useAdminDeleteProductsFromCategory,
} from "medusa-react"
import { useAdminDeleteProductsFromCategory } from "medusa-react"
const DeleteProductsFromCategory = () => {
const deleteProductsFromCategory =
useAdminDeleteProductsFromCategory(productCategoryId)
type ProductsData = {
id: string
}
type Props = {
productCategoryId: string
}
const Category = ({
productCategoryId
}: Props) => {
const deleteProducts = useAdminDeleteProductsFromCategory(
productCategoryId
)
// ...
const handleDelete = () => {
deleteProductsFromCategory.mutate({
product_ids: [
{
id: productId1,
},
{
id: productId2,
},
],
const handleDeleteProducts = (
productIds: ProductsData[]
) => {
deleteProducts.mutate({
product_ids: productIds
}, {
onSuccess: ({ product_category }) => {
console.log(product_category.products)
}
})
}
// ...
}
export default DeleteProductsFromCategory
export default Category
```
</TabItem>
@@ -626,14 +663,24 @@ You can delete a product category by sending a request to the [Delete a Product
```tsx
import { useAdminDeleteProductCategory } from "medusa-react"
const Category = () => {
type Props = {
productCategoryId: string
}
const Category = ({
productCategoryId
}: Props) => {
const deleteCategory = useAdminDeleteProductCategory(
productCategoryId
)
// ...
const handleDelete = () => {
deleteCategory.mutate()
deleteCategory.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
@@ -238,6 +238,10 @@ You can create a product by sending a request to the [Create a Product API Route
value: tagValue,
},
],
}, {
onSuccess: ({ product }) => {
console.log(product.id)
}
})
}
@@ -417,7 +421,11 @@ You can retrieve a single product as an admin by sending a request to the [Get a
```tsx
import { useAdminProduct } from "medusa-react"
const Product = () => {
type Props = {
productId: string
}
const Product = ({ productId }: Props) => {
const {
product,
isLoading,
@@ -487,22 +495,32 @@ You can update a product by sending a request to the [Update Product API Route](
```tsx
import { useAdminUpdateProduct } from "medusa-react"
const UpdateProduct = () => {
type Props = {
productId: string
}
const Product = ({ productId }: Props) => {
const updateProduct = useAdminUpdateProduct(
productId
)
// ...
const handleUpdate = () => {
const handleUpdate = (
title: string
) => {
updateProduct.mutate({
title: "Shirt",
title,
}, {
onSuccess: ({ product }) => {
console.log(product.id)
}
})
}
// ...
}
export default UpdateProduct
export default Product
```
</TabItem>
@@ -578,15 +596,27 @@ You can add a product option to a product by sending a request to the [Add Produ
```tsx
import { useAdminCreateProductOption } from "medusa-react"
const CreateProductOption = () => {
type Props = {
productId: string
}
const CreateProductOption = ({
productId
}: Props) => {
const createOption = useAdminCreateProductOption(
productId
)
// ...
const handleCreate = () => {
const handleCreate = (
title: string
) => {
createOption.mutate({
title: "Size",
title
}, {
onSuccess: ({ product }) => {
console.log(product.options)
}
})
}
@@ -657,23 +687,37 @@ You can update a product option by sending a request to the [Update Product Opti
```tsx
import { useAdminUpdateProductOption } from "medusa-react"
const UpdateProductOption = () => {
type Props = {
productId: string
optionId: string
}
const ProductOption = ({
productId,
optionId
}: Props) => {
const updateOption = useAdminUpdateProductOption(
productId
)
// ...
const handleUpdate = () => {
const handleUpdate = (
title: string
) => {
updateOption.mutate({
option_id,
title: "Size",
option_id: optionId,
title,
}, {
onSuccess: ({ product }) => {
console.log(product.options)
}
})
}
// ...
}
export default UpdateProductOption
export default ProductOption
```
</TabItem>
@@ -739,20 +783,32 @@ You can delete a product option by sending a request to the [Delete Product Opti
```tsx
import { useAdminDeleteProductOption } from "medusa-react"
const DeleteProductOption = () => {
type Props = {
productId: string
optionId: string
}
const ProductOption = ({
productId,
optionId
}: Props) => {
const deleteOption = useAdminDeleteProductOption(
productId
)
// ...
const handleDelete = () => {
deleteOption.mutate(option_id)
deleteOption.mutate(optionId, {
onSuccess: ({ option_id, object, deleted, product }) => {
console.log(product.options)
}
})
}
// ...
}
export default DeleteProductOption
export default ProductOption
```
</TabItem>
@@ -835,27 +891,35 @@ You can create a product variant by sending a request to the [Create Product Var
```tsx
import { useAdminCreateVariant } from "medusa-react"
const CreateProductVariant = () => {
type CreateVariantData = {
title: string
prices: {
amount: number
currency_code: string
}[]
options: {
option_id: string
value: string
}[]
}
type Props = {
productId: string
}
const CreateProductVariant = ({ productId }: Props) => {
const createVariant = useAdminCreateVariant(
productId
)
// ...
const handleCreate = () => {
createVariant.mutate({
title: "White Shirt",
prices: [
{
amount: 1000,
currency_code: "USD",
},
],
options: [
{
option_id,
value: "White",
},
],
const handleCreate = (
variantData: CreateVariantData
) => {
createVariant.mutate(variantData, {
onSuccess: ({ product }) => {
console.log(product.variants)
}
})
}
@@ -958,23 +1022,35 @@ You can update a product variant by sending a request to the [Update a Product V
```tsx
import { useAdminUpdateVariant } from "medusa-react"
const UpdateProductVariant = () => {
type Props = {
productId: string
variantId: string
}
const ProductVariant = ({
productId,
variantId
}: Props) => {
const updateVariant = useAdminUpdateVariant(
productId
)
// ...
const handleUpdate = () => {
const handleUpdate = (title: string) => {
updateVariant.mutate({
variant_id,
title: "White Shirt",
variant_id: variantId,
title,
}, {
onSuccess: ({ product }) => {
console.log(product.variants)
}
})
}
// ...
}
export default UpdateProductVariant
export default ProductVariant
```
</TabItem>
@@ -1040,20 +1116,32 @@ You can delete a product variant by sending a request to the [Delete a Product V
```tsx
import { useAdminDeleteVariant } from "medusa-react"
const DeleteProductVariant = () => {
type Props = {
productId: string
variantId: string
}
const ProductVariant = ({
productId,
variantId
}: Props) => {
const deleteVariant = useAdminDeleteVariant(
productId
)
// ...
const handleDelete = () => {
deleteVariant.mutate(variant_id)
deleteVariant.mutate(variantId, {
onSuccess: ({ variant_id, object, deleted, product }) => {
console.log(product.variants)
}
})
}
// ...
}
export default DeleteProductVariant
export default ProductVariant
```
</TabItem>
@@ -1114,20 +1202,28 @@ You can delete a product by sending a request to the [Delete a Product API Route
```tsx
import { useAdminDeleteProduct } from "medusa-react"
const DeleteProduct = () => {
type Props = {
productId: string
}
const Product = ({ productId }: Props) => {
const deleteProduct = useAdminDeleteProduct(
productId
)
// ...
const handleDelete = () => {
deleteProduct.mutate()
deleteProduct.mutate(void 0, {
onSuccess: ({ id, object, deleted}) => {
console.log(id)
}
})
}
// ...
}
export default DeleteProduct
export default Product
```
</TabItem>
@@ -662,7 +662,11 @@ You can retrieve the details of a single product by its ID using the [Get a Prod
```tsx
import { useProduct } from "medusa-react"
const Products = () => {
type Props = {
productId: string
}
const Product = ({ productId }: Props) => {
const { product, isLoading } = useProduct(productId)
return (
@@ -673,7 +677,7 @@ You can retrieve the details of a single product by its ID using the [Get a Prod
)
}
export default Products
export default Product
```
</TabItem>
@@ -71,7 +71,6 @@ You can list product categories by sending a request to the [List Product Catego
```tsx
import { useProductCategories } from "medusa-react"
import { ProductCategory } from "@medusajs/medusa"
function Categories() {
const {
@@ -88,7 +87,7 @@ You can list product categories by sending a request to the [List Product Catego
{product_categories && product_categories.length > 0 && (
<ul>
{product_categories.map(
(category: ProductCategory) => (
(category) => (
<li key={category.id}>{category.name}</li>
)
)}
@@ -178,8 +177,14 @@ You can retrieve a single product category by its ID using the [Get a Product Ca
```tsx
import { useProductCategory } from "medusa-react"
function Category() {
const { product_category, isLoading } = useProductCategory()
type Props = {
categoryId: string
}
const Category = ({ categoryId }: Props) => {
const { product_category, isLoading } = useProductCategory(
categoryId
)
return (
<div>
@@ -154,20 +154,24 @@ You can update a currency by sending a request to the [Update Currency API Route
```tsx
import { useAdminUpdateCurrency } from "medusa-react"
const UpdateCode = () => {
const updateCode = useAdminUpdateCurrency(code)
const Currency = (currencyCode: string) => {
const updateCurrency = useAdminUpdateCurrency(currencyCode)
// ...
const handleUpdate = () => {
updateCode.mutate({
const handleUpdate = (includes_tax: boolean) => {
updateCurrency.mutate({
includes_tax,
}, {
onSuccess: ({ currency }) => {
console.log(currency)
}
})
}
// ...
}
export default UpdateCode
export default Currency
```
</TabItem>
@@ -321,18 +325,22 @@ You can add a currency to a store using the [Add a Currency Code API Route](http
```tsx
import { useAdminAddStoreCurrency } from "medusa-react"
const AddCurrency = () => {
const addCode = useAdminAddStoreCurrency()
const Store = () => {
const addCurrency = useAdminAddStoreCurrency()
// ...
const handleAdd = () => {
addCode.mutate(code)
const handleAdd = (code: string) => {
addCurrency.mutate(code, {
onSuccess: ({ store }) => {
console.log(store.currencies)
}
})
}
// ...
}
export default AddCurrency
export default Store
```
</TabItem>
@@ -384,18 +392,22 @@ You can remove a currency from a store by sending a request to the [Delete Curre
```tsx
import { useAdminDeleteStoreCurrency } from "medusa-react"
const DeleteCurrency = () => {
const Store = () => {
const deleteCurrency = useAdminDeleteStoreCurrency()
// ...
const handleDelete = () => {
deleteCurrency.mutate(code)
const handleAdd = (code: string) => {
deleteCurrency.mutate(code, {
onSuccess: ({ store }) => {
console.log(store.currencies)
}
})
}
// ...
}
export default DeleteCurrency
export default Store
```
</TabItem>
@@ -77,7 +77,6 @@ You can retrieve regions available on your backend using the [List Regions API R
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { Region } from "@medusajs/medusa"
import { useAdminRegions } from "medusa-react"
const Regions = () => {
@@ -89,7 +88,7 @@ You can retrieve regions available on your backend using the [List Regions API R
{regions && !regions.length && <span>No Regions</span>}
{regions && regions.length > 0 && (
<ul>
{regions.map((region: Region) => (
{regions.map((region) => (
<li key={region.id}>{region.name}</li>
))}
</ul>
@@ -183,6 +182,10 @@ You can create a region by sending a request to the [Create a Region API Route](
countries: [
"DK",
],
}, {
onSuccess: ({ region }) => {
console.log(region.id)
}
})
}
@@ -291,23 +294,32 @@ Alternatively, you can update the details of a region using the [Update a Region
```tsx
import { useAdminUpdateRegion } from "medusa-react"
const UpdateRegion = () => {
type Props = {
regionId: string
}
const Region = ({
regionId
}: Props) => {
const updateRegion = useAdminUpdateRegion(regionId)
// ...
const handleUpdate = () => {
const handleUpdate = (
countries: string[]
) => {
updateRegion.mutate({
countries: [
"DK",
"DE",
],
countries,
}, {
onSuccess: ({ region }) => {
console.log(region.id)
}
})
}
// ...
}
export default UpdateRegion
export default Region
```
</TabItem>
@@ -393,7 +405,11 @@ You can add a shipping option to a region by sending a request to the [Create Sh
```tsx
import { useAdminCreateShippingOption } from "medusa-react"
const Region = () => {
type Props = {
regionId: string
}
const Region = ({ regionId }: Props) => {
const createShippingOption = useAdminCreateShippingOption()
// ...
@@ -406,6 +422,10 @@ You can add a shipping option to a region by sending a request to the [Create Sh
},
price_type: "flat_rate",
amount: 1000,
}, {
onSuccess: ({ shipping_option }) => {
console.log(shipping_option.id)
}
})
}
@@ -504,12 +524,20 @@ You can delete a region by sending a request to the [Delete a Region API Route](
```tsx
import { useAdminDeleteRegion } from "medusa-react"
const Region = () => {
type Props = {
regionId: string
}
const Region = ({ regionId }: Props) => {
const deleteRegion = useAdminDeleteRegion(regionId)
// ...
const handleDelete = () => {
deleteRegion.mutate()
deleteRegion.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
@@ -69,7 +69,6 @@ You can retrieve available regions by sending a request to the [List Regions API
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { Region } from "@medusajs/medusa"
import { useRegions } from "medusa-react"
const Regions = () => {
@@ -80,7 +79,7 @@ You can retrieve available regions by sending a request to the [List Regions API
{isLoading && <span>Loading...</span>}
{regions?.length && (
<ul>
{regions.map((region: Region) => (
{regions.map((region) => (
<li key={region.id}>
{region.name}
</li>
@@ -81,6 +81,10 @@ You can create a sales channel by sending a request to the Create a Sales Channe
createSalesChannel.mutate({
name,
description,
}, {
onSuccess: ({ sales_channel }) => {
console.log(sales_channel.id)
}
})
}
@@ -151,7 +155,6 @@ You can list all sales channels by sending a request to the List Sales Channels
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { SalesChannel } from "@medusajs/medusa"
import { useAdminSalesChannels } from "medusa-react"
const SalesChannels = () => {
@@ -165,7 +168,7 @@ You can list all sales channels by sending a request to the List Sales Channels
)}
{sales_channels && sales_channels.length > 0 && (
<ul>
{sales_channels.map((salesChannel: SalesChannel) => (
{sales_channels.map((salesChannel) => (
<li key={salesChannel.id}>{salesChannel.name}</li>
))}
</ul>
@@ -224,8 +227,12 @@ You can retrieve a sales channels details by its ID using the Get Sales Chann
```tsx
import { useAdminSalesChannel } from "medusa-react"
const SalesChannel = () => {
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const {
sales_channel,
isLoading,
@@ -292,22 +299,32 @@ You can update a Sales Channels details and attributes by sending a request t
```tsx
import { useAdminUpdateSalesChannel } from "medusa-react"
const UpdateSalesChannel = () => {
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const updateSalesChannel = useAdminUpdateSalesChannel(
salesChannelId
)
// ...
const handleUpdate = () => {
const handleUpdate = (
is_disabled: boolean
) => {
updateSalesChannel.mutate({
is_disabled: false,
is_disabled,
}, {
onSuccess: ({ sales_channel }) => {
console.log(sales_channel.is_disabled)
}
})
}
// ...
}
export default UpdateSalesChannel
export default SalesChannel
```
</TabItem>
@@ -373,14 +390,22 @@ You can delete a sales channel by sending a request to the Delete Sales Channel
```tsx
import { useAdminDeleteSalesChannel } from "medusa-react"
const SalesChannel = () => {
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const deleteSalesChannel = useAdminDeleteSalesChannel(
salesChannelId
)
// ...
const handleDelete = () => {
deleteSalesChannel.mutate()
deleteSalesChannel.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
@@ -446,7 +471,11 @@ To add a product to a sales channel, send a request to the Sales Channels Add
```tsx
import { useAdminAddProductsToSalesChannel } from "medusa-react"
const SalesChannel = () => {
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const addProducts = useAdminAddProductsToSalesChannel(
salesChannelId
)
@@ -459,6 +488,10 @@ To add a product to a sales channel, send a request to the Sales Channels Add
id: productId,
},
],
}, {
onSuccess: ({ sales_channel }) => {
console.log(sales_channel.id)
}
})
}
@@ -642,7 +675,11 @@ You can delete a product from a sales channel by sending a request to the Sales
useAdminDeleteProductsFromSalesChannel,
} from "medusa-react"
const SalesChannel = () => {
type Props = {
salesChannelId: string
}
const SalesChannel = ({ salesChannelId }: Props) => {
const deleteProducts = useAdminDeleteProductsFromSalesChannel(
salesChannelId
)
@@ -655,6 +692,10 @@ You can delete a product from a sales channel by sending a request to the Sales
id: productId,
},
],
}, {
onSuccess: ({ sales_channel }) => {
console.log(sales_channel.id)
}
})
}
@@ -291,16 +291,28 @@ You can create a tax rate by sending a request to the [Create Tax Rate API Route
```tsx
import { useAdminCreateTaxRate } from "medusa-react"
const CreateTaxRate = () => {
type Props = {
regionId: string
}
const CreateTaxRate = ({ regionId }: Props) => {
const createTaxRate = useAdminCreateTaxRate()
// ...
const handleCreate = () => {
const handleCreate = (
code: string,
name: string,
rate: number
) => {
createTaxRate.mutate({
code: "TEST",
name: "New Tax Rate",
region_id,
rate: 10,
code,
name,
region_id: regionId,
rate,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.id)
}
})
}
@@ -391,20 +403,30 @@ You can update a tax rate by sending a request to the [Update Tax Rate API Route
```tsx
import { useAdminUpdateTaxRate } from "medusa-react"
const UpdateTaxRate = () => {
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const updateTaxRate = useAdminUpdateTaxRate(taxRateId)
// ...
const handleUpdate = () => {
const handleUpdate = (
name: string
) => {
updateTaxRate.mutate({
name: "New Tax Rate",
name
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.name)
}
})
}
// ...
}
export default UpdateTaxRate
export default TaxRate
```
</TabItem>
@@ -478,22 +500,28 @@ You can add a product to a tax rate by sending a request to the [Add Products AP
```tsx
import { useAdminCreateProductTaxRates } from "medusa-react"
const AddProduct = () => {
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const addProduct = useAdminCreateProductTaxRates(taxRateId)
// ...
const handleAdd = () => {
const handleAddProduct = (productIds: string[]) => {
addProduct.mutate({
products: [
productId1,
],
products: productIds,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.products)
}
})
}
// ...
}
export default AddProduct
export default TaxRate
```
</TabItem>
@@ -567,22 +595,26 @@ You can remove a product from a tax rate by sending a request to the [Delete Pro
```tsx
import { useAdminDeleteProductTaxRates } from "medusa-react"
const RemoveProduct = () => {
const TaxRate = (
taxRateId: string
) => {
const removeProduct = useAdminDeleteProductTaxRates(taxRateId)
// ...
const handleRemove = () => {
const handleRemoveProduct = (productIds: string[]) => {
removeProduct.mutate({
products: [
productId1,
],
products: productIds,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.products)
}
})
}
// ...
}
export default RemoveProduct
export default TaxRate
```
</TabItem>
@@ -664,24 +696,30 @@ You can add a product type to a tax rate by sending a request to the [Add Produc
useAdminCreateProductTypeTaxRates,
} from "medusa-react"
const AddProductTypes = () => {
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const addProductTypes = useAdminCreateProductTypeTaxRates(
taxRateId
)
// ...
const handleAdd = () => {
const handleAddProductTypes = (productTypeIds: string[]) => {
addProductTypes.mutate({
product_types: [
productTypeId,
],
product_types: productTypeIds,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.product_types)
}
})
}
// ...
}
export default AddProductTypes
export default TaxRate
```
</TabItem>
@@ -757,24 +795,32 @@ You can remove a product type from a tax rate by sending a request to the [Delet
useAdminDeleteProductTypeTaxRates,
} from "medusa-react"
const RemoveProductTypes = () => {
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const removeProductTypes = useAdminDeleteProductTypeTaxRates(
taxRateId
)
// ...
const handleRemove = () => {
const handleRemoveProductTypes = (
productTypeIds: string[]
) => {
removeProductTypes.mutate({
product_types: [
productTypeId,
],
product_types: productTypeIds,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.product_types)
}
})
}
// ...
}
export default RemoveProductTypes
export default TaxRate
```
</TabItem>
@@ -854,24 +900,32 @@ You can add a shipping option to a tax rate by sending a request to the [Add Shi
```tsx
import { useAdminCreateShippingTaxRates } from "medusa-react"
const AddShippingOptions = () => {
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const addShippingOption = useAdminCreateShippingTaxRates(
taxRateId
)
// ...
const handleAdd = () => {
const handleAddShippingOptions = (
shippingOptionIds: string[]
) => {
addShippingOption.mutate({
shipping_options: [
shippingOptionId,
],
shipping_options: shippingOptionIds,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.shipping_options)
}
})
}
// ...
}
export default AddShippingOptions
export default TaxRate
```
</TabItem>
@@ -945,24 +999,30 @@ You can remove a shipping option from a tax rate by sending a request to the [De
```tsx
import { useAdminDeleteShippingTaxRates } from "medusa-react"
const RemoveShippingOptions = () => {
const TaxRate = (
taxRateId: string
) => {
const removeShippingOptions = useAdminDeleteShippingTaxRates(
taxRateId
)
// ...
const handleRemove = () => {
const handleRemoveShippingOptions = (
shippingOptionIds: string[]
) => {
removeShippingOptions.mutate({
shipping_options: [
shippingOptionId,
],
shipping_options: shippingOptionIds,
}, {
onSuccess: ({ tax_rate }) => {
console.log(tax_rate.shipping_options)
}
})
}
// ...
}
export default RemoveShippingOptions
export default TaxRate
```
</TabItem>
@@ -1034,18 +1094,26 @@ You can delete a tax rate by sending a request to the [Delete Tax Rate API Route
```tsx
import { useAdminDeleteTaxRate } from "medusa-react"
const DeleteTaxRate = () => {
type Props = {
taxRateId: string
}
const TaxRate = ({ taxRateId }: Props) => {
const deleteTaxRate = useAdminDeleteTaxRate(taxRateId)
// ...
const handleDelete = () => {
deleteTaxRate.mutate()
deleteTaxRate.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default DeleteTaxRate
export default TaxRate
```
</TabItem>
@@ -148,20 +148,24 @@ You can change the tax provider of a region using the [Update Region API Route](
```tsx
import { useAdminUpdateRegion } from "medusa-react"
const UpdateRegion = () => {
type Props = {
regionId: string
}
const Region = ({ regionId }: Props) => {
const updateRegion = useAdminUpdateRegion(regionId)
// ...
const handleUpdate = () => {
const handleUpdate = (taxProviderId: string) => {
updateRegion.mutate({
tax_provider_id,
tax_provider_id: taxProviderId,
})
}
// ...
}
export default UpdateRegion
export default Region
```
</TabItem>
@@ -233,24 +237,30 @@ In addition to changing the tax provider, you can use the same [Update Region AP
```tsx
import { useAdminUpdateRegion } from "medusa-react"
const UpdateRegion = () => {
type RegionData = {
tax_provider_id: string
automatic_taxes?: boolean
gift_cards_taxable?: boolean
tax_code: string
tax_rate: number
}
type Props = {
regionId: string
}
const Region = ({ regionId }: Props) => {
const updateRegion = useAdminUpdateRegion(regionId)
// ...
const handleUpdate = () => {
updateRegion.mutate({
tax_provider_id,
automatic_taxes,
gift_cards_taxable,
tax_code,
tax_rate,
})
const handleUpdate = (data: RegionData) => {
updateRegion.mutate(data)
}
// ...
}
export default UpdateRegion
export default Region
```
</TabItem>
@@ -78,7 +78,9 @@ You can list invites by sending a request to the [List Invite API Route](https:/
return (
<div>
{isLoading && <span>Loading...</span>}
{invites && !invites.length && <span>No Invites</span>}
{invites && !invites.length && (
<span>No Invites</span>
)}
{invites && invites.length > 0 && (
<ul>
{invites.map((invite) => (
@@ -242,13 +244,18 @@ You can accept an invite by sending a request to the [Accept Invite API Route](h
const acceptInvite = useAdminAcceptInvite()
// ...
const handleAccept = () => {
const handleAccept = (
token: string,
firstName: string,
lastName: string,
password: string
) => {
acceptInvite.mutate({
token,
user: {
first_name: "Brigitte",
last_name: "Collier",
password: "supersecret",
first_name: firstName,
last_name: lastName,
password,
},
})
}
@@ -335,7 +342,11 @@ You can resend an invite if its not accepted yet. To resend an invite, send a
```tsx
import { useAdminResendInvite } from "medusa-react"
const ResendInvite = () => {
type Props = {
inviteId: string
}
const ResendInvite = ({ inviteId }: Props) => {
const resendInvite = useAdminResendInvite(inviteId)
// ...
@@ -400,18 +411,26 @@ You can delete an invite by sending a request to the [Delete Invite API Route](h
```tsx
import { useAdminDeleteInvite } from "medusa-react"
const DeleteInvite = () => {
type Props = {
inviteId: string
}
const DeleteInvite = ({ inviteId }: Props) => {
const deleteInvite = useAdminDeleteInvite(inviteId)
// ...
const handleDelete = () => {
deleteInvite.mutate()
deleteInvite.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default DeleteInvite
export default Invite
```
</TabItem>
@@ -283,17 +283,24 @@ You can update a users details in their profile by sending a request to the [
```tsx
import {
useAdminDeleteSession,
useAdminUpdateUser,
} from "medusa-react"
const Profile = () => {
type Props = {
userId: string
}
const Profile = ({ userId }: Props) => {
const updateUser = useAdminUpdateUser(userId)
// ...
const handleUpdate = () => {
const handleUpdate = (firstName: string) => {
updateUser.mutate({
first_name: "Marcellus",
first_name: firstName,
}, {
onSuccess: ({ user }) => {
console.log(user.first_name)
}
})
}
@@ -384,9 +391,15 @@ You can request a password reset by sending a request to the [Request Password R
const requestPasswordReset = useAdminSendResetPasswordToken()
// ...
const handleResetPassword = () => {
const handleResetPassword = (
email: string
) => {
requestPasswordReset.mutate({
email: "user@example.com",
email
}, {
onSuccess: () => {
// successful
}
})
}
@@ -463,10 +476,17 @@ You can reset the password by sending a request to the [Reset Password API Route
const resetPassword = useAdminResetPassword()
// ...
const handleResetPassword = () => {
const handleResetPassword = (
token: string,
password: string
) => {
resetPassword.mutate({
token: "supersecrettoken",
password: "supersecret",
token,
password,
}, {
onSuccess: ({ user }) => {
console.log(user.id)
}
})
}
@@ -153,6 +153,10 @@ You can create a user by sending a request to the [Create User API Route](https:
createUser.mutate({
email: "user@example.com",
password: "supersecret",
}, {
onSuccess: ({ user }) => {
console.log(user.id)
}
})
}
@@ -232,20 +236,30 @@ You can update a users details by sending a request to the [Update User API R
```tsx
import { useAdminUpdateUser } from "medusa-react"
const UpdateUser = () => {
type Props = {
userId: string
}
const User = ({ userId }: Props) => {
const updateUser = useAdminUpdateUser(userId)
// ...
const handleUpdateUser = () => {
const handleUpdateUser = (
firstName: string
) => {
updateUser.mutate({
first_name: "Marcellus",
first_name: firstName,
}, {
onSuccess: ({ user }) => {
console.log(user.first_name)
}
})
}
// ...
}
export default UpdateUser
export default User
```
</TabItem>
@@ -311,18 +325,26 @@ You can delete a user by sending a request to the [Delete User API Route](https:
```tsx
import { useAdminDeleteUser } from "medusa-react"
const DeleteUser = () => {
type Props = {
userId: string
}
const User = ({ userId }: Props) => {
const deleteUser = useAdminDeleteUser(userId)
// ...
const handleDeleteUser = () => {
deleteUser.mutate()
deleteUser.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default DeleteUser
export default User
```
</TabItem>