feat(dashboard): select refund reason in refund form (#13587)

CLOSES CORE-1211

This PR quickly allows the user to select a refund a reason when creating a refund

<img width="1106" height="1618" alt="CleanShot 2025-09-23 at 14 36 39@2x" src="https://github.com/user-attachments/assets/7cb9a53e-82ca-44d3-8267-874153f8d9ac" />


<img width="1870" height="1082" alt="CleanShot 2025-09-23 at 14 36 26@2x" src="https://github.com/user-attachments/assets/ea8d39b2-07e6-4295-ae52-da16b5d0d265" />
This commit is contained in:
William Bouchard
2025-09-24 08:06:42 -04:00
committed by GitHub
parent 294c37564c
commit edf29b3bd2
2 changed files with 44 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/dashboard": patch
---
feat(dashboard): select refund reason in refund form

View File

@@ -17,7 +17,7 @@ import * as zod from "zod"
import { Form } from "../../../../../components/common/form"
import { RouteDrawer, useRouteModal } from "../../../../../components/modals"
import { KeyboundForm } from "../../../../../components/utilities/keybound-form"
import { useRefundPayment } from "../../../../../hooks/api"
import { useRefundPayment, useRefundReasons } from "../../../../../hooks/api"
import { currencies } from "../../../../../lib/data/currencies"
import { formatCurrency } from "../../../../../lib/format-currency"
import { formatProvider } from "../../../../../lib/format-provider"
@@ -35,11 +35,13 @@ const CreateRefundSchema = zod.object({
float: zod.number().or(zod.null()),
}),
note: zod.string().optional(),
refund_reason_id: zod.string().optional(),
})
export const CreateRefundForm = ({ order }: CreateRefundFormProps) => {
const { t } = useTranslation()
const { handleSuccess } = useRouteModal()
const { refund_reasons } = useRefundReasons()
const [searchParams] = useSearchParams()
const [paymentId, setPaymentId] = useState<string | undefined>(
@@ -62,6 +64,7 @@ export const CreateRefundForm = ({ order }: CreateRefundFormProps) => {
float: paymentAmount,
},
note: "",
refund_reason_id: "",
},
resolver: zodResolver(CreateRefundSchema),
})
@@ -90,6 +93,7 @@ export const CreateRefundForm = ({ order }: CreateRefundFormProps) => {
{
amount: data.amount.float!,
note: data.note,
refund_reason_id: data.refund_reason_id,
},
{
onSuccess: () => {
@@ -208,6 +212,40 @@ export const CreateRefundForm = ({ order }: CreateRefundFormProps) => {
}}
/>
<Form.Field
control={form.control}
name="refund_reason_id"
render={({ field }) => {
return (
<Form.Item>
<Form.Label>{t("fields.refundReason")}</Form.Label>
<Form.Control>
<Select
dir={direction}
value={field.value}
onValueChange={field.onChange}
>
<Select.Trigger>
<Select.Value />
</Select.Trigger>
<Select.Content>
{refund_reasons?.map((reason) => (
<Select.Item key={reason.id} value={reason.id}>
{reason.label}
</Select.Item>
))}
</Select.Content>
</Select>
</Form.Control>
<Form.ErrorMessage />
</Form.Item>
)
}}
/>
<Form.Field
control={form.control}
name={`note`}