feat(dashboard): order fulfillment UI (#7262)
* feat: initial impl. of Unfulfilled section and create flow * feat: create fulfillment * feat: order <> fulfillment link, fulfillment section * feat: accept order_id when creating fulfillment * feat: finish create and cancel * fix: integration test * refactor: real Order<>Fulfillment link instead readonly, add link step to the workflow * fix: revert `order_id` definitions * chore: add changeset * fix: build * fix: address comments * fix: fetch inventory and location levels for fulfilled variant * fix: loading inventory details * add isList to order fulfillment link * fix: duplicate declaration * fix: type * refactor: link orders step, fix client * fix: move translations to the new file * fix: pass order id in test --------- Co-authored-by: olivermrbl <oliver@mrbltech.com>
This commit is contained in:
43
packages/admin-next/dashboard/src/hooks/api/fulfillment.tsx
Normal file
43
packages/admin-next/dashboard/src/hooks/api/fulfillment.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import { useMutation, UseMutationOptions } from "@tanstack/react-query"
|
||||
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
|
||||
import { client } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/medusa"
|
||||
import { ordersQueryKeys } from "./orders"
|
||||
|
||||
const FULFILLMENTS_QUERY_KEY = "fulfillments" as const
|
||||
export const fulfillmentsQueryKeys = queryKeysFactory(FULFILLMENTS_QUERY_KEY)
|
||||
|
||||
export const useCreateFulfillment = (
|
||||
options?: UseMutationOptions<any, Error, any>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: any) => client.fulfillments.create(payload),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: fulfillmentsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useCancelFulfillment = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<any, Error, any>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.fulfillments.cancel(id),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({ queryKey: fulfillmentsQueryKeys.lists() })
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.details(),
|
||||
})
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user