Skip to main content
Skip to main content

Return Reasons

Queries and Mutations listed here are used to send requests to the Admin Return Reason API Routes.

All hooks listed require authentication.

Return reasons are key-value pairs that are used to specify why an order return is being created. Admins can manage available return reasons, and they can be used by both admins and customers when creating a return.

Related Guide: How to manage return reasons.

Mutations

useAdminCreateReturnReason

This hook creates a return reason.

Example

import React from "react"
import { useAdminCreateReturnReason } from "medusa-react"

const CreateReturnReason = () => {
const createReturnReason = useAdminCreateReturnReason()
// ...

const handleCreate = (
label: string,
value: string
) => {
createReturnReason.mutate({
label,
value,
}, {
onSuccess: ({ return_reason }) => {
console.log(return_reason.id)
}
})
}

// ...
}

export default CreateReturnReason

Mutation Function Parameters

AdminPostReturnReasonsReqAdminPostReturnReasonsReqRequired
The details of the return reason to create.

Mutation Function Returned Data

AdminReturnReasonsResAdminReturnReasonsResRequired
The return reason's details.

useAdminUpdateReturnReason

This hook updates a return reason's details.

Example

import React from "react"
import { useAdminUpdateReturnReason } from "medusa-react"

type Props = {
returnReasonId: string
}

const ReturnReason = ({ returnReasonId }: Props) => {
const updateReturnReason = useAdminUpdateReturnReason(
returnReasonId
)
// ...

const handleUpdate = (
label: string
) => {
updateReturnReason.mutate({
label,
}, {
onSuccess: ({ return_reason }) => {
console.log(return_reason.label)
}
})
}

// ...
}

export default ReturnReason

Hook Parameters

idstringRequired
The return reason's ID.

Mutation Function Parameters

AdminPostReturnReasonsReasonReqAdminPostReturnReasonsReasonReqRequired
The details to update of the return reason.

Mutation Function Returned Data

AdminReturnReasonsResAdminReturnReasonsResRequired
The return reason's details.

useAdminDeleteReturnReason

This hook deletes a return reason.

Example

import React from "react"
import { useAdminDeleteReturnReason } from "medusa-react"

type Props = {
returnReasonId: string
}

const ReturnReason = ({ returnReasonId }: Props) => {
const deleteReturnReason = useAdminDeleteReturnReason(
returnReasonId
)
// ...

const handleDelete = () => {
deleteReturnReason.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}

// ...
}

export default ReturnReason

Hook Parameters

idstringRequired
The return reason's ID.

Mutation Function Returned Data

DeleteResponseDeleteResponseRequired
The response returned for a DELETE request.

Queries

useAdminReturnReasons

This hook retrieves a list of return reasons.

Example

import React from "react"
import { useAdminReturnReasons } from "medusa-react"

const ReturnReasons = () => {
const { return_reasons, isLoading } = useAdminReturnReasons()

return (
<div>
{isLoading && <span>Loading...</span>}
{return_reasons && !return_reasons.length && (
<span>No Return Reasons</span>
)}
{return_reasons && return_reasons.length > 0 && (
<ul>
{return_reasons.map((reason) => (
<li key={reason.id}>
{reason.label}: {reason.value}
</li>
))}
</ul>
)}
</div>
)
}

export default ReturnReasons

Query Returned Data

return_reasonsReturnReason[]Required
The list of return reasons.

useAdminReturnReason

This hook retrieves a return reason's details.

Example

import React from "react"
import { useAdminReturnReason } from "medusa-react"

type Props = {
returnReasonId: string
}

const ReturnReason = ({ returnReasonId }: Props) => {
const { return_reason, isLoading } = useAdminReturnReason(
returnReasonId
)

return (
<div>
{isLoading && <span>Loading...</span>}
{return_reason && <span>{return_reason.label}</span>}
</div>
)
}

export default ReturnReason

Hook Parameters

idstringRequired
The return reason's ID.

Query Returned Data

return_reasonReturnReasonRequired
The return reason's details.
Was this section helpful?