medusa-ui-common 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +93 -0
- package/src/common/components/breadcrumb/index.tsx +43 -0
- package/src/common/components/cart-totals/index.tsx +562 -0
- package/src/common/components/checkbox/index.tsx +98 -0
- package/src/common/components/delete-button/index.tsx +158 -0
- package/src/common/components/discount-code/index.tsx +220 -0
- package/src/common/components/divider/index.tsx +9 -0
- package/src/common/components/error-message/index.tsx +13 -0
- package/src/common/components/filter-checkbox-group/index.tsx +134 -0
- package/src/common/components/filter-radio-group/index.tsx +62 -0
- package/src/common/components/input/index.tsx +79 -0
- package/src/common/components/interactive-link/index.tsx +33 -0
- package/src/common/components/line-item-options/index.tsx +26 -0
- package/src/common/components/line-item-price/index.tsx +64 -0
- package/src/common/components/line-item-unit-price/index.tsx +64 -0
- package/src/common/components/localized-client-link/index.tsx +32 -0
- package/src/common/components/login-popup/index.tsx +78 -0
- package/src/common/components/modal/index.tsx +123 -0
- package/src/common/components/native-select/index.tsx +75 -0
- package/src/common/components/obfuscated-email/index.tsx +30 -0
- package/src/common/components/processing-overlay/index.tsx +83 -0
- package/src/common/components/radio/index.tsx +27 -0
- package/src/common/components/side-panel/index.tsx +65 -0
- package/src/common/components/submit-button/index.tsx +32 -0
- package/src/common/icons/arrow-left.tsx +36 -0
- package/src/common/icons/back.tsx +37 -0
- package/src/common/icons/bancontact.tsx +26 -0
- package/src/common/icons/chevron-down.tsx +30 -0
- package/src/common/icons/delivered.tsx +29 -0
- package/src/common/icons/envelope.tsx +27 -0
- package/src/common/icons/eye-off.tsx +37 -0
- package/src/common/icons/eye.tsx +37 -0
- package/src/common/icons/fast-delivery.tsx +65 -0
- package/src/common/icons/ideal.tsx +26 -0
- package/src/common/icons/lock.tsx +31 -0
- package/src/common/icons/map-pin.tsx +37 -0
- package/src/common/icons/medusa.tsx +27 -0
- package/src/common/icons/menu.tsx +45 -0
- package/src/common/icons/nextjs.tsx +27 -0
- package/src/common/icons/package.tsx +44 -0
- package/src/common/icons/paypal.tsx +30 -0
- package/src/common/icons/phone.tsx +30 -0
- package/src/common/icons/placeholder-image.tsx +44 -0
- package/src/common/icons/refresh.tsx +51 -0
- package/src/common/icons/spinner.tsx +37 -0
- package/src/common/icons/trash.tsx +51 -0
- package/src/common/icons/user.tsx +37 -0
- package/src/common/icons/x.tsx +37 -0
- package/src/constants/payments.tsx +31 -0
- package/src/context/modal-context.tsx +37 -0
- package/src/context/wishlist-context.tsx +83 -0
- package/src/index.ts +16 -0
- package/src/skeletons/components/skeleton-button/index.tsx +5 -0
- package/src/skeletons/components/skeleton-card-details/index.tsx +10 -0
- package/src/skeletons/components/skeleton-cart-item/index.tsx +35 -0
- package/src/skeletons/components/skeleton-cart-totals/index.tsx +30 -0
- package/src/skeletons/components/skeleton-code-form/index.tsx +13 -0
- package/src/skeletons/components/skeleton-line-item/index.tsx +35 -0
- package/src/skeletons/components/skeleton-order-confirmed-header/index.tsx +14 -0
- package/src/skeletons/components/skeleton-order-information/index.tsx +36 -0
- package/src/skeletons/components/skeleton-order-items/index.tsx +43 -0
- package/src/skeletons/components/skeleton-order-summary/index.tsx +15 -0
- package/src/skeletons/components/skeleton-product-preview/index.tsx +15 -0
- package/src/skeletons/templates/skeleton-cart-page/index.tsx +65 -0
- package/src/skeletons/templates/skeleton-order-confirmed/index.tsx +21 -0
- package/src/skeletons/templates/skeleton-product-grid/index.tsx +23 -0
- package/src/skeletons/templates/skeleton-related-products/index.tsx +25 -0
- package/src/types/global.ts +24 -0
- package/src/types/icon.ts +6 -0
- package/src/util/checkout-dom.ts +65 -0
- package/src/util/compare-addresses.ts +28 -0
- package/src/util/env.ts +3 -0
- package/src/util/get-percentage-diff.ts +6 -0
- package/src/util/get-product-price.ts +79 -0
- package/src/util/isEmpty.ts +11 -0
- package/src/util/money.ts +26 -0
- package/src/util/product.ts +86 -0
- package/src/util/repeat.ts +5 -0
- package/src/util/returns.ts +72 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
import { HttpTypes } from "@medusajs/types"
|
|
3
|
+
|
|
4
|
+
export type ItemWithDeliveryStatus = HttpTypes.StoreOrderLineItem & {
|
|
5
|
+
returnable_quantity: number
|
|
6
|
+
delivered_quantity: number
|
|
7
|
+
return_requested_quantity: number
|
|
8
|
+
return_received_quantity: number
|
|
9
|
+
written_off_quantity: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const calculateReturnableQuantity = (
|
|
13
|
+
item: HttpTypes.StoreOrderLineItem
|
|
14
|
+
): number => {
|
|
15
|
+
// In a real implementation, these would come from the item.detail or similar
|
|
16
|
+
// For now, we'll assume we can calculate it from available data or default to quantity
|
|
17
|
+
// Adjust this based on your actual data structure for item details
|
|
18
|
+
|
|
19
|
+
// Note: The actual data structure depends on how Medusa returns order item details
|
|
20
|
+
// Typically it's in item.detail associated with fulfillments/returns
|
|
21
|
+
|
|
22
|
+
// For the purpose of this storefront implementation (assuming standard Medusa):
|
|
23
|
+
// We strictly follow the logic: delivered - requested - received - written_off
|
|
24
|
+
|
|
25
|
+
// Checking if properties exist on item (they might be on a 'detail' object or top level depending on version)
|
|
26
|
+
const anyItem = item as any
|
|
27
|
+
|
|
28
|
+
// Defaulting to item.quantity if details missing (safe fallback for initial dev)
|
|
29
|
+
// BUT per requirements, we must implement the logic.
|
|
30
|
+
|
|
31
|
+
// If the backend provides these fields on the item directly:
|
|
32
|
+
const delivered = anyItem.delivered_quantity ?? anyItem.quantity ?? 0 // Fallback to quantity if assumed delivered
|
|
33
|
+
const requested = anyItem.return_requested_quantity ?? 0
|
|
34
|
+
const received = anyItem.return_received_quantity ?? 0
|
|
35
|
+
const writtenOff = anyItem.written_off_quantity ?? 0
|
|
36
|
+
|
|
37
|
+
// If fulfillment_status is not fulfilled/shipped/partially_shipped, returnable might be 0
|
|
38
|
+
// But strict formula:
|
|
39
|
+
const returnable = Math.max(0, delivered - requested - received - writtenOff)
|
|
40
|
+
|
|
41
|
+
return returnable
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const isItemReturnable = (item: HttpTypes.StoreOrderLineItem): boolean => {
|
|
45
|
+
return calculateReturnableQuantity(item) > 0
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const hasReturnableItems = (order: HttpTypes.StoreOrder): boolean => {
|
|
49
|
+
if (!order || !order.items) return false
|
|
50
|
+
|
|
51
|
+
// Simple check: if order is canceled, no returns
|
|
52
|
+
if (order.status === "canceled") return false
|
|
53
|
+
|
|
54
|
+
return order.items.some((item) => isItemReturnable(item))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const enhanceItemsWithReturnStatus = (
|
|
58
|
+
items: HttpTypes.StoreOrderLineItem[]
|
|
59
|
+
): ItemWithDeliveryStatus[] => {
|
|
60
|
+
return items.map((item) => {
|
|
61
|
+
const anyItem = item as any
|
|
62
|
+
return {
|
|
63
|
+
...item,
|
|
64
|
+
// Ensure these properties exist
|
|
65
|
+
delivered_quantity: anyItem.delivered_quantity ?? item.quantity, // Optimistic default
|
|
66
|
+
return_requested_quantity: anyItem.return_requested_quantity ?? 0,
|
|
67
|
+
return_received_quantity: anyItem.return_received_quantity ?? 0,
|
|
68
|
+
written_off_quantity: anyItem.written_off_quantity ?? 0,
|
|
69
|
+
returnable_quantity: calculateReturnableQuantity(item),
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
}
|