forked from medusajs/medusa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): order fulfillment UI (medusajs#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 <[email protected]>
- Loading branch information
1 parent
c9bffdf
commit 521b4e7
Showing
29 changed files
with
713 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@medusajs/link-modules": patch | ||
"@medusajs/core-flows": patch | ||
"@medusajs/types": patch | ||
"@medusajs/utils": patch | ||
"@medusajs/medusa": patch | ||
--- | ||
|
||
feat: add Order<>Fulfillment link |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/admin-next/dashboard/src/hooks/api/fulfillment.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/admin-next/dashboard/src/lib/client/fulfillments.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { CreateFulfillmentDTO } from "@medusajs/types" | ||
|
||
import { FulfillmentRes } from "../../types/api-responses" | ||
import { postRequest } from "./common" | ||
|
||
async function createFulfillment(payload: CreateFulfillmentDTO) { | ||
return postRequest<FulfillmentRes>(`/admin/fulfillments`, payload) | ||
} | ||
|
||
async function cancelFulfillment(id: string) { | ||
return postRequest<FulfillmentRes>(`/admin/fulfillments/${id}/cancel`) | ||
} | ||
|
||
export const fulfillments = { | ||
create: createFulfillment, | ||
cancel: cancelFulfillment, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { OrderLineItemDTO } from "@medusajs/types" | ||
|
||
export const getFulfillableQuantity = (item: OrderLineItemDTO) => { | ||
return item.quantity - item.detail.fulfilled_quantity | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...tes/orders/order-create-fulfillment/components/order-create-fulfillment-form/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { z } from "zod" | ||
|
||
export const CreateFulfillmentSchema = z.object({ | ||
quantity: z.record(z.string(), z.number()), | ||
|
||
location_id: z.string(), | ||
send_notification: z.boolean().optional(), | ||
}) |
1 change: 1 addition & 0 deletions
1
...-routes/orders/order-create-fulfillment/components/order-create-fulfillment-form/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./order-create-fulfillment-form" |
Oops, something went wrong.