feat(dashboard): create shipment flow (#7898)

**What**
- add "Mark shipped" to Fulfillment section

---

CLOSES CORE-2427
This commit is contained in:
Frane Polić
2024-07-02 16:50:15 +02:00
committed by GitHub
parent e3a0df3ba0
commit 87375db9ef
12 changed files with 277 additions and 12 deletions

View File

@@ -2,9 +2,10 @@ import { useMutation, UseMutationOptions } from "@tanstack/react-query"
import { queryKeysFactory } from "../../lib/query-key-factory"
import { client } from "../../lib/client"
import { client, sdk } from "../../lib/client"
import { queryClient } from "../../lib/query-client"
import { ordersQueryKeys } from "./orders"
import { HttpTypes } from "@medusajs/types"
const FULFILLMENTS_QUERY_KEY = "fulfillments" as const
export const fulfillmentsQueryKeys = queryKeysFactory(FULFILLMENTS_QUERY_KEY)
@@ -41,3 +42,24 @@ export const useCancelFulfillment = (
...options,
})
}
export const useCreateShipment = (
fulfillmentId: string,
options?: UseMutationOptions<
{ order: HttpTypes.AdminOrder },
Error,
HttpTypes.AdminCreateFulfillmentShipment
>
) => {
return useMutation({
mutationFn: (payload: HttpTypes.AdminCreateFulfillmentShipment) =>
sdk.admin.fulfillment.createShipment(fulfillmentId, payload),
onSuccess: (data: any, variables: any, context: any) => {
queryClient.invalidateQueries({
queryKey: ordersQueryKeys.details(),
})
options?.onSuccess?.(data, variables, context)
},
...options,
})
}