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:
@@ -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 group’s 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 Group’s
|
||||
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 Group’s
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
|
||||
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 customer’s 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>
|
||||
|
||||
Reference in New Issue
Block a user