diff --git a/packages/admin-next/dashboard/src/hooks/api/index.ts b/packages/admin-next/dashboard/src/hooks/api/index.ts index 1c90b4192b..4d0cda2c9c 100644 --- a/packages/admin-next/dashboard/src/hooks/api/index.ts +++ b/packages/admin-next/dashboard/src/hooks/api/index.ts @@ -19,6 +19,7 @@ export * from "./product-types" export * from "./product-variants" export * from "./products" export * from "./promotions" +export * from "./refund-reasons" export * from "./regions" export * from "./reservations" export * from "./sales-channels" diff --git a/packages/admin-next/dashboard/src/hooks/api/refund-reasons.tsx b/packages/admin-next/dashboard/src/hooks/api/refund-reasons.tsx new file mode 100644 index 0000000000..6dd8992066 --- /dev/null +++ b/packages/admin-next/dashboard/src/hooks/api/refund-reasons.tsx @@ -0,0 +1,28 @@ +import { HttpTypes } from "@medusajs/types" +import { QueryKey, useQuery, UseQueryOptions } from "@tanstack/react-query" +import { sdk } from "../../lib/client" +import { queryKeysFactory } from "../../lib/query-key-factory" + +const REFUND_REASON_QUERY_KEY = "refund-reason" as const +export const paymentQueryKeys = queryKeysFactory(REFUND_REASON_QUERY_KEY) + +export const useRefundReasons = ( + query?: HttpTypes.RefundReasonFilters, + options?: Omit< + UseQueryOptions< + HttpTypes.RefundReasonsResponse, + Error, + HttpTypes.RefundReasonsResponse, + QueryKey + >, + "queryKey" | "queryFn" + > +) => { + const { data, ...rest } = useQuery({ + queryFn: () => sdk.admin.refundReason.list(query), + queryKey: [], + ...options, + }) + + return { ...data, ...rest } +} diff --git a/packages/admin-next/dashboard/src/i18n/translations/en.json b/packages/admin-next/dashboard/src/i18n/translations/en.json index c92b3c1dd0..6d3cebdbfd 100644 --- a/packages/admin-next/dashboard/src/i18n/translations/en.json +++ b/packages/admin-next/dashboard/src/i18n/translations/en.json @@ -2336,6 +2336,7 @@ "totalRedemptions": "Total Redemptions", "countries": "Countries", "paymentProviders": "Payment Providers", + "refundReason": "Refund Reason", "fulfillmentProviders": "Fulfillment Providers", "fulfillmentProvider": "Fulfillment Provider", "providers": "Providers", diff --git a/packages/admin-next/dashboard/src/routes/orders/order-create-refund/components/create-refund-form/create-refund-form.tsx b/packages/admin-next/dashboard/src/routes/orders/order-create-refund/components/create-refund-form/create-refund-form.tsx index 5c4415c0ab..e35165a173 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-create-refund/components/create-refund-form/create-refund-form.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-create-refund/components/create-refund-form/create-refund-form.tsx @@ -1,10 +1,12 @@ import { zodResolver } from "@hookform/resolvers/zod" import { HttpTypes } from "@medusajs/types" -import { Button, CurrencyInput, toast } from "@medusajs/ui" +import { Button, CurrencyInput, Textarea, toast } from "@medusajs/ui" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" import * as zod from "zod" +import { upperCaseFirst } from "../../../../../../../../core/utils/src/common/upper-case-first" import { Form } from "../../../../../components/common/form" +import { Combobox } from "../../../../../components/inputs/combobox" import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { useRefundPayment } from "../../../../../hooks/api" import { getCurrencySymbol } from "../../../../../lib/data/currencies" @@ -12,13 +14,19 @@ import { formatCurrency } from "../../../../../lib/format-currency" type CreateRefundFormProps = { payment: HttpTypes.AdminPayment + refundReasons: HttpTypes.AdminRefundReason[] } const CreateRefundSchema = zod.object({ amount: zod.number(), + refund_reason_id: zod.string().nullish(), + note: zod.string().optional(), }) -export const CreateRefundForm = ({ payment }: CreateRefundFormProps) => { +export const CreateRefundForm = ({ + payment, + refundReasons, +}: CreateRefundFormProps) => { const { t } = useTranslation() const { handleSuccess } = useRouteModal() const paymentAmount = payment.amount as unknown as number @@ -26,6 +34,7 @@ export const CreateRefundForm = ({ payment }: CreateRefundFormProps) => { const form = useForm>({ defaultValues: { amount: paymentAmount, + note: "", }, resolver: zodResolver(CreateRefundSchema), }) @@ -36,6 +45,8 @@ export const CreateRefundForm = ({ payment }: CreateRefundFormProps) => { await mutateAsync( { amount: data.amount, + refund_reason_id: data.refund_reason_id, + note: data.note, }, { onSuccess: () => { @@ -109,6 +120,48 @@ export const CreateRefundForm = ({ payment }: CreateRefundFormProps) => { ) }} /> + + {/* TODO: Bring this back when we have a refund reason management UI */} + {/* { + return ( + + {t("fields.refundReason")} + + + ({ + label: upperCaseFirst(pp.label), + value: pp.id, + }))} + /> + + + + ) + }} + /> */} + + { + return ( + + {t("fields.note")} + + +