Skip to content

Commit cd26459

Browse files
authored
Merge branch 'medusajs:develop' into develop
2 parents 0610715 + 6a958d2 commit cd26459

17 files changed

Lines changed: 239 additions & 39 deletions

File tree

.changeset/beige-llamas-drive.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@medusajs/core-flows": patch
3+
"@medusajs/types": patch
4+
"@medusajs/medusa": patch
5+
---
6+
7+
feat(core-flows,medusa,types): add no_notification to markOrderFulfillmentAsDeliveredWorkflow

.changeset/forty-states-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/notification-sendgrid": patch
3+
---
4+
5+
feat(notification-sendgrid): add support for personalizations via provider_data

.github/workflows/review-prs.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ name: PR Review
22

33
on:
44
pull_request_target:
5-
types: [opened, reopened, synchronize, edited]
5+
types: [opened, reopened, synchronize, edited, ready_for_review]
66
issue_comment:
77
types: [created]
88
workflow_dispatch:
99
inputs:
1010
skip_reviewed:
11-
description: 'Skip PRs that already have initial-approval or requires-more labels'
11+
description: "Skip PRs that already have initial-approval or requires-more labels"
1212
required: false
1313
default: true
1414
type: boolean
@@ -49,8 +49,8 @@ jobs:
4949
fail-fast: false
5050
uses: ./.github/workflows/review-pr-action.yml
5151
with:
52-
pr_number: '${{ matrix.pr.number }}'
53-
trigger_reason: 'manual workflow dispatch'
52+
pr_number: "${{ matrix.pr.number }}"
53+
trigger_reason: "manual workflow dispatch"
5454
secrets:
5555
MEDUSA_APP_ID: ${{ secrets.MEDUSA_APP_ID }}
5656
MEDUSA_APP_PRIVATE_KEY: ${{ secrets.MEDUSA_APP_PRIVATE_KEY }}
@@ -109,6 +109,7 @@ jobs:
109109
reopened) echo "trigger_reason=PR reopened" >> $GITHUB_OUTPUT ;;
110110
synchronize) echo "trigger_reason=new commit pushed" >> $GITHUB_OUTPUT ;;
111111
edited) echo "trigger_reason=PR description updated" >> $GITHUB_OUTPUT ;;
112+
ready_for_review) echo "trigger_reason=PR marked as ready for review" >> $GITHUB_OUTPUT ;;
112113
*) echo "trigger_reason=${{ github.event.action }}" >> $GITHUB_OUTPUT ;;
113114
esac
114115

packages/admin/dashboard/src/hooks/api/orders.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,12 @@ export const useMarkOrderFulfillmentAsDelivered = (
296296
options?: UseMutationOptions<
297297
{ order: HttpTypes.AdminOrder },
298298
FetchError,
299-
void
299+
HttpTypes.AdminMarkOrderFulfillmentAsDelivered
300300
>
301301
) => {
302302
return useMutation({
303-
mutationFn: () => sdk.admin.order.markAsDelivered(orderId, fulfillmentId),
303+
mutationFn: (payload: HttpTypes.AdminMarkOrderFulfillmentAsDelivered) =>
304+
sdk.admin.order.markAsDelivered(orderId, fulfillmentId, payload),
304305
onSuccess: (data: any, variables: any, context: any) => {
305306
queryClient.invalidateQueries({
306307
queryKey: ordersQueryKeys.all,

packages/admin/dashboard/src/routes/orders/order-detail/components/order-fulfillment-section/order-fulfillment-section.tsx

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ import {
1111
Container,
1212
Copy,
1313
Heading,
14+
Label,
15+
Prompt,
1416
StatusBadge,
17+
Switch,
1518
Text,
1619
Tooltip,
1720
toast,
1821
usePrompt,
1922
} from "@medusajs/ui"
2023
import { format } from "date-fns"
24+
import { useState } from "react"
2125
import { useTranslation } from "react-i18next"
2226
import { Link, useNavigate } from "react-router-dom"
2327
import { ActionMenu } from "../../../../../components/common/action-menu"
@@ -264,17 +268,24 @@ const Fulfillment = ({
264268
const showDeliveryButton =
265269
!fulfillment.canceled_at && !fulfillment.delivered_at
266270

267-
const handleMarkAsDelivered = async () => {
268-
const res = await prompt({
269-
title: t("general.areYouSure"),
270-
description: t("orders.fulfillment.markAsDeliveredWarning"),
271-
confirmText: t("actions.continue"),
272-
cancelText: t("actions.cancel"),
273-
variant: "confirmation",
274-
})
271+
const [sendNotification, setSendNotification] = useState(
272+
!order.no_notification
273+
)
274+
const [showDeliveredPrompt, setShowDeliveredPrompt] = useState(false)
275275

276-
if (res) {
277-
await markAsDelivered(undefined, {
276+
const handleMarkAsDelivered = () => {
277+
setShowDeliveredPrompt(true)
278+
}
279+
280+
const handleCancelDeliveredPrompt = () => {
281+
setShowDeliveredPrompt(false)
282+
}
283+
284+
const handleConfirmDelivered = async () => {
285+
setShowDeliveredPrompt(false)
286+
await markAsDelivered(
287+
{ no_notification: !sendNotification },
288+
{
278289
onSuccess: () => {
279290
toast.success(
280291
t(
@@ -287,8 +298,8 @@ const Fulfillment = ({
287298
onError: (e) => {
288299
toast.error(e.message)
289300
},
290-
})
291-
}
301+
}
302+
)
292303
}
293304

294305
const handleCancel = async () => {
@@ -484,6 +495,40 @@ const Fulfillment = ({
484495
)}
485496
</div>
486497
)}
498+
499+
<Prompt open={showDeliveredPrompt} variant="confirmation">
500+
<Prompt.Content>
501+
<Prompt.Header>
502+
<Prompt.Title>{t("general.areYouSure")}</Prompt.Title>
503+
<Prompt.Description>
504+
{t("orders.fulfillment.markAsDeliveredWarning")}
505+
</Prompt.Description>
506+
</Prompt.Header>
507+
<div className="border-ui-border-base mt-6 flex items-center justify-between border-y border-dotted p-6">
508+
<Label
509+
htmlFor={`send-notification-${fulfillment.id}`}
510+
className="txt-compact-small text-ui-fg-subtle"
511+
>
512+
{t("orders.returns.sendNotification")}
513+
</Label>
514+
<Switch
515+
id={`send-notification-${fulfillment.id}`}
516+
dir="ltr"
517+
className="rtl:rotate-180"
518+
checked={sendNotification}
519+
onCheckedChange={setSendNotification}
520+
/>
521+
</div>
522+
<Prompt.Footer>
523+
<Prompt.Cancel onClick={handleCancelDeliveredPrompt}>
524+
{t("actions.cancel")}
525+
</Prompt.Cancel>
526+
<Prompt.Action onClick={handleConfirmDelivered}>
527+
{t("actions.continue")}
528+
</Prompt.Action>
529+
</Prompt.Footer>
530+
</Prompt.Content>
531+
</Prompt>
487532
</Container>
488533
)
489534
}

packages/core/core-flows/src/order/workflows/mark-order-fulfillment-as-delivered.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ function prepareRegisterDeliveryData({
169169
const iitem = iitems.find(
170170
(i) => i.inventory.id === fitem.inventory_item_id
171171
)
172-
if(iitem)
173-
quantity = MathBN.div(quantity, iitem.required_quantity)
172+
if (iitem) quantity = MathBN.div(quantity, iitem.required_quantity)
174173
}
175174

176175
return {
@@ -193,6 +192,12 @@ export type MarkOrderFulfillmentAsDeliveredWorkflowInput = {
193192
* The ID of the fulfillment to mark as delivered.
194193
*/
195194
fulfillmentId: string
195+
/**
196+
* Whether to notify the customer about the delivery.
197+
*
198+
* @since 2.13.7
199+
*/
200+
no_notification?: boolean
196201
}
197202

198203
export const markOrderFulfillmentAsDeliveredWorkflowId =
@@ -277,7 +282,10 @@ export const markOrderFulfillmentAsDeliveredWorkflow = createWorkflow(
277282

278283
emitEventStep({
279284
eventName: FulfillmentWorkflowEvents.DELIVERY_CREATED,
280-
data: { id: deliveredFulfillment.id },
285+
data: {
286+
id: deliveredFulfillment.id,
287+
no_notification: input.no_notification,
288+
},
281289
})
282290

283291
return new WorkflowResponse(void 0)

packages/core/js-sdk/src/admin/order.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ export class Order {
475475
*
476476
* @param id - The order's ID.
477477
* @param fulfillmentId - The fulfillment's ID.
478+
* @param body - The delivery options.
478479
* @param query - Configure the fields to retrieve in the order.
479480
* @param headers - Headers to pass in the request
480481
* @returns The order's details.
@@ -491,6 +492,7 @@ export class Order {
491492
async markAsDelivered(
492493
id: string,
493494
fulfillmentId: string,
495+
body?: HttpTypes.AdminMarkOrderFulfillmentAsDelivered,
494496
query?: SelectParams,
495497
headers?: ClientHeaders
496498
) {
@@ -499,6 +501,7 @@ export class Order {
499501
{
500502
method: "POST",
501503
headers,
504+
body,
502505
query,
503506
}
504507
)

packages/core/types/src/http/order/admin/payloads.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ export interface AdminCreateOrderShipment {
100100
metadata?: Record<string, unknown> | null
101101
}
102102

103+
/**
104+
* The data needed to mark a fulfillment as delivered.
105+
*
106+
* @since 2.13.7
107+
*/
108+
export interface AdminMarkOrderFulfillmentAsDelivered {
109+
/**
110+
* Whether to notify the customer about the delivery.
111+
*/
112+
no_notification?: boolean
113+
}
114+
103115
export interface AdminCancelOrderFulfillment {
104116
/**
105117
* Whether to notify the customer about this change.

packages/medusa/src/api/admin/orders/[id]/fulfillments/[fulfillment_id]/mark-as-delivered/route.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ import {
77
} from "@medusajs/framework/http"
88

99
export const POST = async (
10-
req: AuthenticatedMedusaRequest<{}, HttpTypes.AdminGetOrderParams>,
10+
req: AuthenticatedMedusaRequest<
11+
HttpTypes.AdminMarkOrderFulfillmentAsDelivered,
12+
HttpTypes.AdminGetOrderParams
13+
>,
1114
res: MedusaResponse<HttpTypes.AdminOrderResponse>
1215
) => {
1316
const { id: orderId, fulfillment_id: fulfillmentId } = req.params
1417

1518
await markOrderFulfillmentAsDeliveredWorkflow(req.scope).run({
16-
input: { orderId, fulfillmentId },
19+
input: {
20+
orderId,
21+
fulfillmentId,
22+
no_notification: req.validatedBody.no_notification,
23+
},
1724
})
1825

1926
const order = await refetchEntity({

packages/medusa/src/api/admin/orders/middlewares.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
AdminGetOrdersOrderItemsParams,
1414
AdminGetOrdersOrderParams,
1515
AdminGetOrdersParams,
16+
AdminMarkOrderFulfillmentAsDelivered,
1617
AdminOrderCancelFulfillment,
1718
AdminOrderChangesParams,
1819
AdminOrderCreateFulfillment,
@@ -256,6 +257,7 @@ export const adminOrderRoutesMiddlewares: MiddlewareRoute[] = [
256257
AdminGetOrdersOrderParams,
257258
QueryConfig.retrieveTransformQueryConfig
258259
),
260+
validateAndTransformBody(AdminMarkOrderFulfillmentAsDelivered),
259261
],
260262
policies: [
261263
{

0 commit comments

Comments
 (0)