diff --git a/.changeset/blue-donuts-begin.md b/.changeset/blue-donuts-begin.md new file mode 100644 index 0000000000..d132b36f8e --- /dev/null +++ b/.changeset/blue-donuts-begin.md @@ -0,0 +1,7 @@ +--- +"@medusajs/draft-order": patch +"@medusajs/types": patch +"@medusajs/medusa": patch +--- + +fix(draft-order,medusa,types): draft order promotion UI polish diff --git a/packages/core/types/src/http/order/common.ts b/packages/core/types/src/http/order/common.ts index 2ca4de467a..eb98c93d7b 100644 --- a/packages/core/types/src/http/order/common.ts +++ b/packages/core/types/src/http/order/common.ts @@ -1078,6 +1078,11 @@ export interface BaseOrderChange { * The order change action details. */ export interface BaseOrderChangeAction { + /** + * The ordering of the order change action + */ + ordering: number + /** * The ID of the order change action */ diff --git a/packages/core/types/src/http/promotion/admin/queries.ts b/packages/core/types/src/http/promotion/admin/queries.ts index c7fb969e45..6bea404e61 100644 --- a/packages/core/types/src/http/promotion/admin/queries.ts +++ b/packages/core/types/src/http/promotion/admin/queries.ts @@ -19,6 +19,10 @@ export interface AdminGetPromotionsParams * Filter by promotion code. */ code?: string | string[] | OperatorMap + /** + * Filter by promotion ID. + */ + id?: string[] | string | OperatorMap /** * Filter by campaign ID to retrieve promotions by campaign. */ @@ -51,7 +55,9 @@ export interface AdminGetPromotionsParams /** * Filter by the promotion's application method type. */ - application_method_type?: ApplicationMethodTypeValues | ApplicationMethodTypeValues[] + application_method_type?: + | ApplicationMethodTypeValues + | ApplicationMethodTypeValues[] /** * An array of filters to apply on the entity, where each item in the array is joined with an "and" condition. */ diff --git a/packages/core/types/src/order/mutations.ts b/packages/core/types/src/order/mutations.ts index 09db8d40cf..e5eeee63db 100644 --- a/packages/core/types/src/order/mutations.ts +++ b/packages/core/types/src/order/mutations.ts @@ -34,52 +34,52 @@ export interface UpsertOrderAddressDTO { /** * The company name. */ - company?: string + company?: string | null /** * The first name of the customer. */ - first_name?: string + first_name?: string | null /** * The last name of the customer. */ - last_name?: string + last_name?: string | null /** * The address 1 of the address. */ - address_1?: string + address_1?: string | null /** * The address 2 of the address. */ - address_2?: string + address_2?: string | null /** * The city of the address. */ - city?: string + city?: string | null /** * The country code of the address. */ - country_code?: string + country_code?: string | null /** * The lower-case [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) province of the address. */ - province?: string + province?: string | null /** * The postal code of the address. */ - postal_code?: string + postal_code?: string | null /** * The phone of the address. */ - phone?: string + phone?: string | null /** * Holds custom data in key-value pairs. diff --git a/packages/medusa/src/api/admin/promotions/validators.ts b/packages/medusa/src/api/admin/promotions/validators.ts index 3f7f488635..effd1283e4 100644 --- a/packages/medusa/src/api/admin/promotions/validators.ts +++ b/packages/medusa/src/api/admin/promotions/validators.ts @@ -26,6 +26,9 @@ export const AdminGetPromotionsParamsFields = z.object({ code: z .union([z.string(), z.array(z.string()), createOperatorMap()]) .optional(), + id: z + .union([z.string(), z.array(z.string()), createOperatorMap()]) + .optional(), campaign_id: z.union([z.string(), z.array(z.string())]).optional(), application_method: z .object({ diff --git a/packages/medusa/src/api/utils/common-validators/common.ts b/packages/medusa/src/api/utils/common-validators/common.ts index f0be066db4..2a781fff73 100644 --- a/packages/medusa/src/api/utils/common-validators/common.ts +++ b/packages/medusa/src/api/utils/common-validators/common.ts @@ -2,17 +2,17 @@ import { z } from "zod" export const AddressPayload = z .object({ - first_name: z.string().optional(), - last_name: z.string().optional(), - phone: z.string().optional(), - company: z.string().optional(), - address_1: z.string().optional(), - address_2: z.string().optional(), - city: z.string().optional(), - country_code: z.string().optional(), - province: z.string().optional(), - postal_code: z.string().optional(), - metadata: z.record(z.unknown()).optional(), + first_name: z.string().nullish(), + last_name: z.string().nullish(), + phone: z.string().nullish(), + company: z.string().nullish(), + address_1: z.string().nullish(), + address_2: z.string().nullish(), + city: z.string().nullish(), + country_code: z.string().nullish(), + province: z.string().nullish(), + postal_code: z.string().nullish(), + metadata: z.record(z.unknown()).nullish(), }) .strict() diff --git a/packages/plugins/draft-order/src/admin/components/draft-orders/activity-section.tsx b/packages/plugins/draft-order/src/admin/components/draft-orders/activity-section.tsx index 2692eb1193..e883c6c897 100644 --- a/packages/plugins/draft-order/src/admin/components/draft-orders/activity-section.tsx +++ b/packages/plugins/draft-order/src/admin/components/draft-orders/activity-section.tsx @@ -26,7 +26,7 @@ export const ActivitySection = ({ order, changes }: ActivitySectionProps) => { ) return ( - +
Activity
@@ -83,9 +83,9 @@ const CollapsibleActivityItemList = ({ {!open && (
-
+
- + {`Show ${items.length} more ${ items.length === 1 ? "activity" : "activities" @@ -130,22 +130,22 @@ const ActivityItem = ({ item, isFirst = false }: ActivityItemProps) => { return (
-
-
-
-
+
+
+
+
{!isFirst && (
-
+
)}
-
+
{item.label} @@ -159,10 +159,10 @@ const ActivityItem = ({ item, isFirst = false }: ActivityItemProps) => {
{item.content && renderContent(item.content)} {item.userId && ( -
+
{isUserLoaded ? ( -
+
By { ) : (
By - - + +
)}
@@ -215,7 +215,14 @@ function getEditActivityItems( promotionsRemoved: 0, } - for (const action of change.actions) { + const orderedActions = change.actions.sort((a, b) => { + return a.ordering - b.ordering + }) + + const addedPromotionMap = new Map() + const removedPromotionMap = new Map() + + for (const action of orderedActions) { if (!action.details) { continue } @@ -234,13 +241,22 @@ function getEditActivityItems( case "SHIPPING_REMOVE": counts.shippingMethodsRemoved += 1 break - case "PROMOTION_ADD": - counts.promotionsAdded += 1 + case "PROMOTION_ADD": { + addedPromotionMap.set(action.reference_id!, true) break - case "PROMOTION_REMOVE": - counts.promotionsRemoved += 1 + } + case "PROMOTION_REMOVE": { + if (addedPromotionMap.has(action.reference_id!)) { + addedPromotionMap.delete(action.reference_id!) + } else { + removedPromotionMap.set(action.reference_id!, true) + } break + } } + + counts.promotionsAdded = addedPromotionMap.size + counts.promotionsRemoved = removedPromotionMap.size } const createActivityItem = ( diff --git a/packages/plugins/draft-order/src/admin/lib/schemas/address.ts b/packages/plugins/draft-order/src/admin/lib/schemas/address.ts index dab5117b6c..bdc272921e 100644 --- a/packages/plugins/draft-order/src/admin/lib/schemas/address.ts +++ b/packages/plugins/draft-order/src/admin/lib/schemas/address.ts @@ -5,10 +5,10 @@ export const addressSchema = z.object({ first_name: z.string().min(1), last_name: z.string().min(1), address_1: z.string().min(1), - address_2: z.string().optional(), - company: z.string().optional(), + address_2: z.string().nullish(), + company: z.string().nullish(), city: z.string().min(1), - province: z.string().optional(), + province: z.string().nullish(), postal_code: z.string().min(1), - phone: z.string().optional(), + phone: z.string().nullish(), }) diff --git a/packages/plugins/draft-order/src/admin/routes/draft-orders/[id]/@items/page.tsx b/packages/plugins/draft-order/src/admin/routes/draft-orders/[id]/@items/page.tsx index 30bc3710e3..1f47971700 100644 --- a/packages/plugins/draft-order/src/admin/routes/draft-orders/[id]/@items/page.tsx +++ b/packages/plugins/draft-order/src/admin/routes/draft-orders/[id]/@items/page.tsx @@ -216,7 +216,7 @@ const ItemsForm = ({ preview, currencyCode }: ItemsFormProps) => { - Edit the items in the draft order. + Edit the items in the draft order
@@ -261,7 +261,7 @@ const ItemsForm = ({ preview, currencyCode }: ItemsFormProps) => {
-
+
Item @@ -282,7 +282,7 @@ const ItemsForm = ({ preview, currencyCode }: ItemsFormProps) => {
{itemCount <= 0 ? ( -
+
There are no items in this order @@ -300,7 +300,7 @@ const ItemsForm = ({ preview, currencyCode }: ItemsFormProps) => { /> )) ) : ( -
+
No items found @@ -348,7 +348,7 @@ const ItemsForm = ({ preview, currencyCode }: ItemsFormProps) => { -
+
-
+
-
+
@@ -1136,7 +1136,7 @@ const CustomItemForm = ({ orderId, currencyCode }: CustomItemFormProps) => {
-
+