Files
medusa-store/packages/admin-next/dashboard/src/hooks/api/payment-collections.tsx
Riqwan Thamir 8bd284779e feat(dashboard,core-flows,js-sdk,types): ability to mark payment as paid (#8679)
* feat(core-flows): create or update payment collections in RMA flows

* chore: change ui to pick payment link from unpaid payment collection

* Apply suggestions from code review

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>

* chore: fix mathbn

* feat(dashboard,core-flows,js-sdk,types): ability to mark payment as paid

* chore: add captured bt

---------

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
2024-08-20 22:58:28 +02:00

90 lines
2.4 KiB
TypeScript

import { FetchError } from "@medusajs/js-sdk"
import { HttpTypes } from "@medusajs/types"
import { useMutation, UseMutationOptions } from "@tanstack/react-query"
import { sdk } from "../../lib/client"
import { queryClient } from "../../lib/query-client"
import { queryKeysFactory } from "../../lib/query-key-factory"
import { ordersQueryKeys } from "./orders"
const PAYMENT_COLLECTION_QUERY_KEY = "payment-collection" as const
export const paymentCollectionQueryKeys = queryKeysFactory(
PAYMENT_COLLECTION_QUERY_KEY
)
export const useCreatePaymentCollection = (
options?: UseMutationOptions<
HttpTypes.AdminPaymentCollectionResponse,
Error,
HttpTypes.AdminCreatePaymentCollection
>
) => {
return useMutation({
mutationFn: (payload) => sdk.admin.paymentCollection.create(payload),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.all,
})
queryClient.invalidateQueries({
queryKey: paymentCollectionQueryKeys.all,
})
options?.onSuccess?.(data, variables, context)
},
...options,
})
}
export const useMarkPaymentCollectionAsPaid = (
paymentCollectionId: string,
options?: UseMutationOptions<
HttpTypes.AdminPaymentCollectionResponse,
Error,
HttpTypes.AdminMarkPaymentCollectionAsPaid
>
) => {
return useMutation({
mutationFn: (payload) =>
sdk.admin.paymentCollection.markAsPaid(paymentCollectionId, payload),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.all,
})
queryClient.invalidateQueries({
queryKey: paymentCollectionQueryKeys.all,
})
options?.onSuccess?.(data, variables, context)
},
...options,
})
}
export const useDeletePaymentCollection = (
options?: Omit<
UseMutationOptions<
HttpTypes.AdminDeletePaymentCollectionResponse,
FetchError,
string
>,
"mutationFn"
>
) => {
return useMutation({
mutationFn: (id: string) => sdk.admin.paymentCollection.delete(id),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.all,
})
queryClient.invalidateQueries({
queryKey: paymentCollectionQueryKeys.all,
})
options?.onSuccess?.(data, variables, context)
},
...options,
})
}