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:
@@ -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 order’s 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 swap’s 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>
|
||||
|
||||
Reference in New Issue
Block a user