From e1f3160145169d613cc2007eb077ced631833285 Mon Sep 17 00:00:00 2001 From: barsa Date: Wed, 5 Nov 2025 16:52:03 +0900 Subject: [PATCH] Enhance order display item sorting in buildOrderDisplayItems function - Introduced sorting logic to prioritize monthly subscriptions over one-time items in the order display. - Refactored item mapping to store display items in a variable for improved readability and maintainability. - Ensured that items with the same charge kind maintain their original order during sorting. --- .../src/features/orders/utils/order-display.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/portal/src/features/orders/utils/order-display.ts b/apps/portal/src/features/orders/utils/order-display.ts index 906023a9..cd8244f6 100644 --- a/apps/portal/src/features/orders/utils/order-display.ts +++ b/apps/portal/src/features/orders/utils/order-display.ts @@ -200,7 +200,7 @@ export function buildOrderDisplayItems( } // Don't group items - show each one separately - return items.map((item, index) => { + const displayItems = items.map((item, index) => { const charges = aggregateCharges({ indices: [index], items: [item] }); const isBundled = Boolean(item.isBundledAddon); @@ -217,6 +217,20 @@ export function buildOrderDisplayItems( isBundle: isBundled, }; }); + + // Sort: monthly subscriptions first, then one-time items + return displayItems.sort((a, b) => { + // Get the primary charge kind for each item + const aChargeKind = a.charges[0]?.kind ?? "other"; + const bChargeKind = b.charges[0]?.kind ?? "other"; + + // Sort by charge kind (monthly first, then one-time) + const orderDiff = CHARGE_ORDER[aChargeKind] - CHARGE_ORDER[bChargeKind]; + if (orderDiff !== 0) return orderDiff; + + // If same charge kind, maintain original order + return 0; + }); } export function summarizeOrderDisplayItems(