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 authored and GitHub committed 2024-01-05 17:03:38 +02:00
1 parent 6fc6a9de6a
commit 7d650771d1
2811 files changed
+231856 -455063

No files matched your search

@@ -295,7 +295,7 @@ For example, this creates a batch job of the type `publish-products`:
<Tabs groupId="request-types" isCodeTabs={true}>
<TabItem value="client" label="Medusa JS Client" default>
```jsx
```ts
medusa.admin.batchJobs.create({
type: "publish-products",
context: { },
@@ -306,10 +306,38 @@ For example, this creates a batch job of the type `publish-products`:
})
```
</TabItem>
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { useAdminCreateBatchJob } from "medusa-react"
const CreateBatchJob = () => {
const createBatchJob = useAdminCreateBatchJob()
// ...
const handleCreateBatchJob = () => {
createBatchJob.mutate({
type: "publish-products",
context: {},
dry_run: true
}, {
onSuccess: ({ batch_job }) => {
console.log(batch_job)
}
})
}
// ...
}
export default CreateBatchJob
```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```jsx
```ts
fetch(`<BACKEND_URL>/admin/batch-jobs`, {
method: "POST",
credentials: "include",
@@ -356,17 +384,41 @@ You can retrieve the batch job afterward to get its status and view details abou
<Tabs groupId="request-type" isCodeTabs={true}>
<TabItem value="client" label="Medusa JS Client" default>
```jsx
```ts
medusa.admin.batchJobs.retrieve(batchJobId)
.then(( batch_job ) => {
console.log(batch_job.status, batch_job.result)
})
```
</TabItem>
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { useAdminBatchJob } from "medusa-react"
type Props = {
batchJobId: string
}
const BatchJob = ({ batchJobId }: Props) => {
const { batch_job, isLoading } = useAdminBatchJob(batchJobId)
return (
<div>
{isLoading && <span>Loading...</span>}
{batch_job && <span>{batch_job.created_by}</span>}
</div>
)
}
export default BatchJob
```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```jsx
```ts
fetch(`<BACKEND_URL>/admin/batch-jobs/${batchJobId}`, {
credentials: "include",
})
@@ -411,17 +463,45 @@ To process the batch job, send a request to [confirm the batch job](https://docs
<Tabs groupId="request-type" isCodeTabs={true}>
<TabItem value="client" label="Medusa JS Client" default>
```jsx
```ts
medusa.admin.batchJobs.confirm(batchJobId)
.then(( batch_job ) => {
console.log(batch_job.status)
})
```
</TabItem>
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { useAdminConfirmBatchJob } from "medusa-react"
type Props = {
batchJobId: string
}
const BatchJob = ({ batchJobId }: Props) => {
const confirmBatchJob = useAdminConfirmBatchJob(batchJobId)
// ...
const handleConfirm = () => {
confirmBatchJob.mutate(undefined, {
onSuccess: ({ batch_job }) => {
console.log(batch_job)
}
})
}
// ...
}
export default BatchJob
```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```jsx
```ts
fetch(`<BACKEND_URL>/admin/batch-jobs/${batchJobId}/confirm`, {
method: "POST",
credentials: "include",
@@ -179,6 +179,10 @@ You can create a publishable API key by sending a request to the [Create Publish
const handleCreate = (title: string) => {
createKey.mutate({
title,
}, {
onSuccess: ({ publishable_api_key }) => {
console.log(publishable_api_key.id)
}
})
}
@@ -249,9 +253,15 @@ You can update a publishable API key’s details by sending a request to the [Up
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { useAdminUpdatePublishableApiKey } from "medusa-react"
import { useAdminUpdatePublishableApiKey } from "medusa-react"
const UpdatePublishableApiKey = () => {
type Props = {
publishableApiKeyId: string
}
const PublishableApiKey = ({
publishableApiKeyId
}: Props) => {
const updateKey = useAdminUpdatePublishableApiKey(
publishableApiKeyId
)
@@ -260,13 +270,17 @@ You can update a publishable API key’s details by sending a request to the [Up
const handleUpdate = (title: string) => {
updateKey.mutate({
title,
}, {
onSuccess: ({ publishable_api_key }) => {
console.log(publishable_api_key.id)
}
})
}
// ...
}
export default UpdatePublishableApiKey
export default PublishableApiKey
```
</TabItem>
@@ -334,14 +348,24 @@ You can revoke a publishable API key by sending a request to the [Revoke Publish
```tsx
import { useAdminRevokePublishableApiKey } from "medusa-react"
const PublishableApiKey = () => {
type Props = {
publishableApiKeyId: string
}
const PublishableApiKey = ({
publishableApiKeyId
}: Props) => {
const revokeKey = useAdminRevokePublishableApiKey(
publishableApiKeyId
)
// ...
const handleRevoke = () => {
revokeKey.mutate()
revokeKey.mutate(void 0, {
onSuccess: ({ publishable_api_key }) => {
console.log(publishable_api_key.revoked_at)
}
})
}
// ...
@@ -404,14 +428,24 @@ You can delete a publishable API key by sending a request to the [Delete Publish
```tsx
import { useAdminDeletePublishableApiKey } from "medusa-react"
const PublishableApiKey = () => {
type Props = {
publishableApiKeyId: string
}
const PublishableApiKey = ({
publishableApiKeyId
}: Props) => {
const deleteKey = useAdminDeletePublishableApiKey(
publishableApiKeyId
)
// ...
const handleDelete = () => {
deleteKey.mutate()
deleteKey.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
@@ -480,12 +514,17 @@ You can retrieve the list of sales channels associated with a publishable API ke
<TabItem value="medusa-react" label="Medusa React">
```tsx
import { SalesChannel } from "@medusajs/medusa"
import {
useAdminPublishableApiKeySalesChannels,
} from "medusa-react"
const SalesChannels = () => {
type Props = {
publishableApiKeyId: string
}
const SalesChannels = ({
publishableApiKeyId
}: Props) => {
const { sales_channels, isLoading } =
useAdminPublishableApiKeySalesChannels(
publishableApiKeyId
@@ -499,7 +538,7 @@ You can retrieve the list of sales channels associated with a publishable API ke
)}
{sales_channels && sales_channels.length > 0 && (
<ul>
{sales_channels.map((salesChannel: SalesChannel) => (
{sales_channels.map((salesChannel) => (
<li key={salesChannel.id}>{salesChannel.name}</li>
))}
</ul>
@@ -575,7 +614,13 @@ You can add a sales channel to a publishable API key by sending a request to the
useAdminAddPublishableKeySalesChannelsBatch,
} from "medusa-react"
const PublishableApiKey = () => {
type Props = {
publishableApiKeyId: string
}
const PublishableApiKey = ({
publishableApiKeyId
}: Props) => {
const addSalesChannels =
useAdminAddPublishableKeySalesChannelsBatch(
publishableApiKeyId
@@ -589,6 +634,10 @@ You can add a sales channel to a publishable API key by sending a request to the
id: salesChannelId,
},
],
}, {
onSuccess: ({ publishable_api_key }) => {
console.log(publishable_api_key.id)
}
})
}
@@ -685,13 +734,19 @@ You can delete a sales channel from a publishable API key by sending a request t
useAdminRemovePublishableKeySalesChannelsBatch,
} from "medusa-react"
const PublishableApiKey = () => {
type Props = {
publishableApiKeyId: string
}
const PublishableApiKey = ({
publishableApiKeyId
}: Props) => {
const deleteSalesChannels =
useAdminRemovePublishableKeySalesChannelsBatch(
publishableApiKeyId
)
// ...
const handleDelete = (salesChannelId: string) => {
deleteSalesChannels.mutate({
sales_channel_ids: [
@@ -699,12 +754,16 @@ You can delete a sales channel from a publishable API key by sending a request t
id: salesChannelId,
},
],
}, {
onSuccess: ({ publishable_api_key }) => {
console.log(publishable_api_key.id)
}
})
}
// ...
}
export default PublishableApiKey
```