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
@@ -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)
}
})
}
}