@pradip1995/segment-animation-order 0.2.2 → 0.2.4
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pradip1995/segment-animation-order",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Motion/Lumière order confirmed, failed, and details pages",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -16,10 +16,6 @@
|
|
|
16
16
|
".": "./src/index.ts",
|
|
17
17
|
"./manifest": "./src/manifest.ts"
|
|
18
18
|
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"typecheck": "tsc --noEmit",
|
|
21
|
-
"lint": "tsc --noEmit"
|
|
22
|
-
},
|
|
23
19
|
"peerDependencies": {
|
|
24
20
|
"@medusajs/types": ">=2",
|
|
25
21
|
"@pradip1995/commerce-core": "^4.0.0",
|
|
@@ -40,5 +36,9 @@
|
|
|
40
36
|
"next": ">=15",
|
|
41
37
|
"react": "19.0.3",
|
|
42
38
|
"typescript": "^5.7.2"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"lint": "tsc --noEmit"
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
}
|
package/src/animation-order.css
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
--anim-order-ink: #0a0a0a;
|
|
5
5
|
--anim-order-muted: #737373;
|
|
6
6
|
--anim-order-line: #e8e8e8;
|
|
7
|
-
--anim-order-accent: #
|
|
7
|
+
--anim-order-accent: #111111;
|
|
8
8
|
position: relative;
|
|
9
9
|
isolation: isolate;
|
|
10
10
|
width: 100%;
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
inset: 0;
|
|
21
21
|
z-index: 0;
|
|
22
22
|
background:
|
|
23
|
-
radial-gradient(ellipse 80% 55% at 50% -10%, rgba(
|
|
23
|
+
radial-gradient(ellipse 80% 55% at 50% -10%, rgba(17, 17, 17, 0.08), transparent 60%),
|
|
24
24
|
linear-gradient(180deg, #fafafa 0%, #ffffff 42%, #ffffff 100%);
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -293,7 +293,7 @@
|
|
|
293
293
|
/* ── Order details ─────────────────────────────────────────── */
|
|
294
294
|
|
|
295
295
|
.anim-order--details {
|
|
296
|
-
--anim-order-accent: #
|
|
296
|
+
--anim-order-accent: #111111;
|
|
297
297
|
--anim-order-ink: #1c1412;
|
|
298
298
|
--anim-order-muted: #7a6e68;
|
|
299
299
|
--anim-order-line: #ebe4df;
|
|
@@ -301,7 +301,7 @@
|
|
|
301
301
|
|
|
302
302
|
.anim-order--details .anim-order__atmosphere {
|
|
303
303
|
background:
|
|
304
|
-
radial-gradient(ellipse 80% 55% at 50% -10%, rgba(
|
|
304
|
+
radial-gradient(ellipse 80% 55% at 50% -10%, rgba(17, 17, 17, 0.08), transparent 60%),
|
|
305
305
|
linear-gradient(180deg, #fffaf7 0%, #ffffff 45%, #ffffff 100%);
|
|
306
306
|
}
|
|
307
307
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use server"
|
|
2
2
|
|
|
3
|
-
import { cancelOrder
|
|
3
|
+
import { cancelOrder } from "@pradip1995/commerce-core/data/orders"
|
|
4
4
|
import { cookies } from "next/headers"
|
|
5
5
|
|
|
6
6
|
type Result = { success: boolean; error: string | null }
|
|
@@ -21,19 +21,84 @@ export async function cancelOrderAction(orderId: string): Promise<Result> {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
async function readInvoiceError(response: Response): Promise<string> {
|
|
25
|
+
const fallback = `Failed to download invoice: ${response.status} ${response.statusText}`
|
|
26
|
+
try {
|
|
27
|
+
const contentType = response.headers.get("content-type") || ""
|
|
28
|
+
if (contentType.includes("application/json")) {
|
|
29
|
+
const body = (await response.json()) as {
|
|
30
|
+
message?: string
|
|
31
|
+
error?: string
|
|
32
|
+
}
|
|
33
|
+
if (body.message) return body.message
|
|
34
|
+
if (body.error) return body.error
|
|
35
|
+
} else {
|
|
36
|
+
const text = (await response.text()).trim()
|
|
37
|
+
if (text) return text.slice(0, 240)
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
/* ignore parse errors */
|
|
41
|
+
}
|
|
42
|
+
return fallback
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Download invoice PDF. Calls the invoice plugin directly so we can surface
|
|
47
|
+
* the real API error (e.g. order not eligible) instead of a bare 400.
|
|
48
|
+
*/
|
|
24
49
|
export async function downloadInvoiceAction(
|
|
25
50
|
orderId: string
|
|
26
51
|
): Promise<{ success: boolean; data?: string; error?: string }> {
|
|
27
52
|
if (!orderId) return { success: false, error: "Order ID is required" }
|
|
53
|
+
|
|
28
54
|
try {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
55
|
+
const cookieStore = await cookies()
|
|
56
|
+
const token = cookieStore.get("_medusa_jwt")?.value
|
|
57
|
+
const guestToken = !token
|
|
58
|
+
? cookieStore.get("_medusa_guest_jwt")?.value ||
|
|
59
|
+
cookieStore.get("_medusa_guest_token")?.value
|
|
60
|
+
: null
|
|
61
|
+
|
|
62
|
+
const headers: HeadersInit = {
|
|
63
|
+
"x-publishable-api-key": process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY || "",
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let url = `/store/invoice/download/${orderId}`
|
|
67
|
+
if (token) {
|
|
68
|
+
headers.Cookie = `_medusa_jwt=${token}`
|
|
69
|
+
headers.Authorization = `Bearer ${token}`
|
|
70
|
+
} else if (guestToken) {
|
|
71
|
+
url = `/store/guest/invoice/download/${orderId}`
|
|
72
|
+
headers.Cookie = `_medusa_guest_jwt=${guestToken}`
|
|
73
|
+
headers.Authorization = `Bearer ${guestToken}`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const backendUrl =
|
|
77
|
+
process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL || "http://localhost:9000"
|
|
78
|
+
const response = await fetch(`${backendUrl}${url}`, {
|
|
79
|
+
method: "GET",
|
|
80
|
+
headers,
|
|
81
|
+
cache: "no-store",
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
return { success: false, error: await readInvoiceError(response) }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const contentType = response.headers.get("content-type") || ""
|
|
89
|
+
if (!contentType.includes("application/pdf")) {
|
|
90
|
+
return { success: false, error: await readInvoiceError(response) }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const arrayBuffer = await response.arrayBuffer()
|
|
94
|
+
if (arrayBuffer.byteLength === 0) {
|
|
95
|
+
return { success: false, error: "Generated PDF is empty" }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
success: true,
|
|
100
|
+
data: Buffer.from(arrayBuffer).toString("base64"),
|
|
35
101
|
}
|
|
36
|
-
return { success: true, data: result.data }
|
|
37
102
|
} catch (err) {
|
|
38
103
|
return {
|
|
39
104
|
success: false,
|
package/src/order-actions.tsx
CHANGED
|
@@ -70,7 +70,13 @@ function canReorder(order: HttpTypes.StoreOrder): boolean {
|
|
|
70
70
|
|
|
71
71
|
function canDownloadInvoice(order: HttpTypes.StoreOrder): boolean {
|
|
72
72
|
const status = (order.status || "").toLowerCase()
|
|
73
|
-
|
|
73
|
+
if (status === "canceled" || status === "cancelled") return false
|
|
74
|
+
// Invoice only after the order is delivered or marked completed.
|
|
75
|
+
if (status === "completed" || status === "complete") return true
|
|
76
|
+
const fulfillment = (order.fulfillment_status || "").toLowerCase()
|
|
77
|
+
return ["delivered", "partially_delivered", "completed", "complete"].includes(
|
|
78
|
+
fulfillment
|
|
79
|
+
)
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
function triggerPdfDownload(base64: string, filename: string) {
|