@pradip1995/segment-animation-order 0.2.1
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 +44 -0
- package/src/animation-order.css +823 -0
- package/src/confirmation-back-handler.tsx +32 -0
- package/src/index.ts +2 -0
- package/src/manifest.ts +11 -0
- package/src/order-actions-server.ts +52 -0
- package/src/order-actions.tsx +341 -0
- package/src/order-details.tsx +253 -0
- package/src/order-status.tsx +252 -0
- package/src/order-tracking.tsx +412 -0
- package/src/product-details-path.ts +22 -0
- package/src/segment.tsx +79 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect } from "react"
|
|
4
|
+
import { useParams, useRouter } from "next/navigation"
|
|
5
|
+
|
|
6
|
+
const DEFAULT_REGION = "in"
|
|
7
|
+
|
|
8
|
+
export default function ConfirmationBackHandler({
|
|
9
|
+
href,
|
|
10
|
+
}: {
|
|
11
|
+
href: string
|
|
12
|
+
}) {
|
|
13
|
+
const router = useRouter()
|
|
14
|
+
const params = useParams()
|
|
15
|
+
const countryCode = String(params?.countryCode || DEFAULT_REGION).toLowerCase()
|
|
16
|
+
const localizedHref = href.startsWith("/")
|
|
17
|
+
? `/${countryCode}${href}`
|
|
18
|
+
: href
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
window.history.pushState({ orderConfirmed: true }, "", window.location.href)
|
|
22
|
+
|
|
23
|
+
const onPopState = () => {
|
|
24
|
+
router.replace(localizedHref)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
window.addEventListener("popstate", onPopState)
|
|
28
|
+
return () => window.removeEventListener("popstate", onPopState)
|
|
29
|
+
}, [router, localizedHref])
|
|
30
|
+
|
|
31
|
+
return null
|
|
32
|
+
}
|
package/src/index.ts
ADDED
package/src/manifest.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use server"
|
|
2
|
+
|
|
3
|
+
import { cancelOrder, downloadInvoice } from "@pradip1995/commerce-core/data/orders"
|
|
4
|
+
import { cookies } from "next/headers"
|
|
5
|
+
|
|
6
|
+
type Result = { success: boolean; error: string | null }
|
|
7
|
+
|
|
8
|
+
export async function cancelOrderAction(orderId: string): Promise<Result> {
|
|
9
|
+
if (!orderId) return { success: false, error: "Order ID is required" }
|
|
10
|
+
try {
|
|
11
|
+
const result = await cancelOrder(orderId)
|
|
12
|
+
return {
|
|
13
|
+
success: Boolean(result?.success),
|
|
14
|
+
error: result?.success ? null : result?.error || "Failed to cancel order",
|
|
15
|
+
}
|
|
16
|
+
} catch (err) {
|
|
17
|
+
return {
|
|
18
|
+
success: false,
|
|
19
|
+
error: err instanceof Error ? err.message : "Failed to cancel order",
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function downloadInvoiceAction(
|
|
25
|
+
orderId: string
|
|
26
|
+
): Promise<{ success: boolean; data?: string; error?: string }> {
|
|
27
|
+
if (!orderId) return { success: false, error: "Order ID is required" }
|
|
28
|
+
try {
|
|
29
|
+
const result = await downloadInvoice(orderId)
|
|
30
|
+
if (!result?.success || !result.data) {
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
error: result?.error || "Failed to download invoice",
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { success: true, data: result.data }
|
|
37
|
+
} catch (err) {
|
|
38
|
+
return {
|
|
39
|
+
success: false,
|
|
40
|
+
error: err instanceof Error ? err.message : "Failed to download invoice",
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function isLoggedInCustomerAction(): Promise<boolean> {
|
|
46
|
+
try {
|
|
47
|
+
const cookieStore = await cookies()
|
|
48
|
+
return Boolean(cookieStore.get("_medusa_jwt")?.value)
|
|
49
|
+
} catch {
|
|
50
|
+
return false
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useId, useState } from "react"
|
|
4
|
+
import { createPortal } from "react-dom"
|
|
5
|
+
import { usePathname, useRouter } from "next/navigation"
|
|
6
|
+
import type { HttpTypes } from "@medusajs/types"
|
|
7
|
+
import { addToCart } from "@pradip1995/commerce-core/client/actions/cart"
|
|
8
|
+
import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
|
|
9
|
+
import {
|
|
10
|
+
cancelOrderAction,
|
|
11
|
+
downloadInvoiceAction,
|
|
12
|
+
} from "./order-actions-server"
|
|
13
|
+
|
|
14
|
+
type LineItem = HttpTypes.StoreOrderLineItem & {
|
|
15
|
+
detail?: { fulfilled_quantity?: number; returned_quantity?: number } | null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type ActiveReturn = {
|
|
19
|
+
id: string
|
|
20
|
+
status?: string | null
|
|
21
|
+
items?: Array<{ item_id?: string; quantity?: number }>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getActiveReturns(order: HttpTypes.StoreOrder): ActiveReturn[] {
|
|
25
|
+
const returns =
|
|
26
|
+
(order as HttpTypes.StoreOrder & { returns?: ActiveReturn[] }).returns || []
|
|
27
|
+
return returns.filter(
|
|
28
|
+
(r) =>
|
|
29
|
+
r.status &&
|
|
30
|
+
!["canceled", "cancelled", "rejected"].includes(r.status.toLowerCase())
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getEligibleQty(item: LineItem, activeReturns: ActiveReturn[]): number {
|
|
35
|
+
const qty = item.quantity ?? 0
|
|
36
|
+
const returned = item.detail?.returned_quantity ?? 0
|
|
37
|
+
const requestedQty = activeReturns.reduce((sum, ret) => {
|
|
38
|
+
const line = ret.items?.find((i) => i.item_id === item.id)
|
|
39
|
+
return sum + (line?.quantity ?? 0)
|
|
40
|
+
}, 0)
|
|
41
|
+
return Math.max(0, qty - returned - requestedQty)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function canCancelOrder(order: HttpTypes.StoreOrder): boolean {
|
|
45
|
+
const status = (order.status || "").toLowerCase()
|
|
46
|
+
if (status === "canceled" || status === "cancelled") return false
|
|
47
|
+
const fulfillment = (order.fulfillment_status || "").toLowerCase()
|
|
48
|
+
return (
|
|
49
|
+
!fulfillment ||
|
|
50
|
+
fulfillment === "not_fulfilled" ||
|
|
51
|
+
fulfillment === "canceled" ||
|
|
52
|
+
fulfillment === "cancelled"
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function canReturnOrExchange(order: HttpTypes.StoreOrder): boolean {
|
|
57
|
+
const status = (order.status || "").toLowerCase()
|
|
58
|
+
if (status === "canceled" || status === "cancelled") return false
|
|
59
|
+
const fulfillment = (order.fulfillment_status || "").toLowerCase()
|
|
60
|
+
return ["delivered", "partially_delivered"].includes(fulfillment)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function canReorder(order: HttpTypes.StoreOrder): boolean {
|
|
64
|
+
const status = (order.status || "").toLowerCase()
|
|
65
|
+
if (status === "canceled" || status === "cancelled") return false
|
|
66
|
+
const fulfillment = (order.fulfillment_status || "").toLowerCase()
|
|
67
|
+
return ["delivered", "partially_delivered", "shipped"].includes(fulfillment)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function canDownloadInvoice(order: HttpTypes.StoreOrder): boolean {
|
|
71
|
+
const status = (order.status || "").toLowerCase()
|
|
72
|
+
return status !== "canceled" && status !== "cancelled"
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function triggerPdfDownload(base64: string, filename: string) {
|
|
76
|
+
const binary = atob(base64)
|
|
77
|
+
const bytes = new Uint8Array(binary.length)
|
|
78
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i)
|
|
79
|
+
const blob = new Blob([bytes], { type: "application/pdf" })
|
|
80
|
+
const url = URL.createObjectURL(blob)
|
|
81
|
+
const anchor = document.createElement("a")
|
|
82
|
+
anchor.href = url
|
|
83
|
+
anchor.download = filename
|
|
84
|
+
document.body.appendChild(anchor)
|
|
85
|
+
anchor.click()
|
|
86
|
+
anchor.remove()
|
|
87
|
+
URL.revokeObjectURL(url)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default function OrderActions({ order }: { order: HttpTypes.StoreOrder }) {
|
|
91
|
+
const [cancelOpen, setCancelOpen] = useState(false)
|
|
92
|
+
const [pending, setPending] = useState(false)
|
|
93
|
+
const [invoicePending, setInvoicePending] = useState(false)
|
|
94
|
+
const [error, setError] = useState<string | null>(null)
|
|
95
|
+
const [success, setSuccess] = useState<string | null>(null)
|
|
96
|
+
const [mounted, setMounted] = useState(false)
|
|
97
|
+
const titleId = useId()
|
|
98
|
+
|
|
99
|
+
const router = useRouter()
|
|
100
|
+
const pathname = usePathname() || ""
|
|
101
|
+
const countryCode = pathname.split("/").filter(Boolean)[0] || "in"
|
|
102
|
+
const items = (order.items || []) as LineItem[]
|
|
103
|
+
const activeReturns = getActiveReturns(order)
|
|
104
|
+
const hasOpenReturn = activeReturns.length > 0
|
|
105
|
+
const showCancel = canCancelOrder(order)
|
|
106
|
+
const showReturnExchange = canReturnOrExchange(order)
|
|
107
|
+
const showReorder = canReorder(order)
|
|
108
|
+
const showInvoice = canDownloadInvoice(order)
|
|
109
|
+
const hasEligibleItems = items.some(
|
|
110
|
+
(item) => getEligibleQty(item, activeReturns) > 0
|
|
111
|
+
)
|
|
112
|
+
const returnActionsDisabled = hasOpenReturn || !hasEligibleItems
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
setMounted(true)
|
|
116
|
+
}, [])
|
|
117
|
+
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!cancelOpen) return
|
|
120
|
+
const prev = document.body.style.overflow
|
|
121
|
+
document.body.style.overflow = "hidden"
|
|
122
|
+
const onKey = (event: KeyboardEvent) => {
|
|
123
|
+
if (event.key === "Escape" && !pending) setCancelOpen(false)
|
|
124
|
+
}
|
|
125
|
+
window.addEventListener("keydown", onKey)
|
|
126
|
+
return () => {
|
|
127
|
+
document.body.style.overflow = prev
|
|
128
|
+
window.removeEventListener("keydown", onKey)
|
|
129
|
+
}
|
|
130
|
+
}, [cancelOpen, pending])
|
|
131
|
+
|
|
132
|
+
if (!showCancel && !showReturnExchange && !showReorder && !showInvoice) {
|
|
133
|
+
return null
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function handleReorder() {
|
|
137
|
+
setPending(true)
|
|
138
|
+
setError(null)
|
|
139
|
+
try {
|
|
140
|
+
for (const item of items) {
|
|
141
|
+
if (!item.variant_id) continue
|
|
142
|
+
await addToCart({
|
|
143
|
+
variantId: item.variant_id,
|
|
144
|
+
quantity: item.quantity || 1,
|
|
145
|
+
countryCode,
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
router.push(`/${countryCode}/cart`)
|
|
149
|
+
} catch {
|
|
150
|
+
setError("Could not add these items to your bag.")
|
|
151
|
+
setPending(false)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function handleCancel() {
|
|
156
|
+
setPending(true)
|
|
157
|
+
setError(null)
|
|
158
|
+
setSuccess(null)
|
|
159
|
+
const result = await cancelOrderAction(order.id)
|
|
160
|
+
setPending(false)
|
|
161
|
+
if (!result.success) {
|
|
162
|
+
setError(result.error || "Failed to cancel order")
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
setCancelOpen(false)
|
|
166
|
+
setSuccess("Order cancelled successfully.")
|
|
167
|
+
window.location.reload()
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function handleInvoice() {
|
|
171
|
+
setInvoicePending(true)
|
|
172
|
+
setError(null)
|
|
173
|
+
setSuccess(null)
|
|
174
|
+
const result = await downloadInvoiceAction(order.id)
|
|
175
|
+
setInvoicePending(false)
|
|
176
|
+
if (!result.success || !result.data) {
|
|
177
|
+
setError(result.error || "Could not download invoice.")
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
triggerPdfDownload(
|
|
181
|
+
result.data,
|
|
182
|
+
`invoice-order-${order.display_id ?? order.id}.pdf`
|
|
183
|
+
)
|
|
184
|
+
setSuccess("Invoice downloaded.")
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<div className="anim-order__panel anim-order__panel--actions">
|
|
189
|
+
<p className="anim-order__panel-label">Order actions</p>
|
|
190
|
+
<p className="anim-order__panel-meta">
|
|
191
|
+
Cancel before shipping, download your invoice, or open a return/exchange
|
|
192
|
+
after delivery.
|
|
193
|
+
</p>
|
|
194
|
+
|
|
195
|
+
<div className="anim-order__action-row">
|
|
196
|
+
{showInvoice ? (
|
|
197
|
+
<button
|
|
198
|
+
type="button"
|
|
199
|
+
disabled={invoicePending || pending}
|
|
200
|
+
onClick={handleInvoice}
|
|
201
|
+
className="anim-order__btn anim-order__btn--outline"
|
|
202
|
+
>
|
|
203
|
+
{invoicePending ? "Preparing…" : "Download invoice"}
|
|
204
|
+
</button>
|
|
205
|
+
) : null}
|
|
206
|
+
{showCancel ? (
|
|
207
|
+
<button
|
|
208
|
+
type="button"
|
|
209
|
+
disabled={pending || invoicePending}
|
|
210
|
+
onClick={() => {
|
|
211
|
+
setCancelOpen(true)
|
|
212
|
+
setError(null)
|
|
213
|
+
setSuccess(null)
|
|
214
|
+
}}
|
|
215
|
+
className="anim-order__btn anim-order__btn--outline"
|
|
216
|
+
>
|
|
217
|
+
Cancel order
|
|
218
|
+
</button>
|
|
219
|
+
) : null}
|
|
220
|
+
{showReturnExchange ? (
|
|
221
|
+
<>
|
|
222
|
+
<LocalizedLink
|
|
223
|
+
href={`/order/return/${order.id}`}
|
|
224
|
+
aria-disabled={returnActionsDisabled}
|
|
225
|
+
tabIndex={returnActionsDisabled ? -1 : undefined}
|
|
226
|
+
className={`anim-order__btn anim-order__btn--primary${
|
|
227
|
+
returnActionsDisabled ? " is-disabled" : ""
|
|
228
|
+
}`}
|
|
229
|
+
>
|
|
230
|
+
Request return
|
|
231
|
+
</LocalizedLink>
|
|
232
|
+
<LocalizedLink
|
|
233
|
+
href={`/order/exchange/${order.id}`}
|
|
234
|
+
aria-disabled={returnActionsDisabled}
|
|
235
|
+
tabIndex={returnActionsDisabled ? -1 : undefined}
|
|
236
|
+
className={`anim-order__btn anim-order__btn--outline${
|
|
237
|
+
returnActionsDisabled ? " is-disabled" : ""
|
|
238
|
+
}`}
|
|
239
|
+
>
|
|
240
|
+
Request exchange
|
|
241
|
+
</LocalizedLink>
|
|
242
|
+
</>
|
|
243
|
+
) : null}
|
|
244
|
+
{showReorder ? (
|
|
245
|
+
<button
|
|
246
|
+
type="button"
|
|
247
|
+
disabled={pending || invoicePending}
|
|
248
|
+
onClick={handleReorder}
|
|
249
|
+
className="anim-order__btn anim-order__btn--primary"
|
|
250
|
+
>
|
|
251
|
+
{pending ? "Adding…" : "Reorder"}
|
|
252
|
+
</button>
|
|
253
|
+
) : null}
|
|
254
|
+
</div>
|
|
255
|
+
|
|
256
|
+
{showReturnExchange && returnActionsDisabled ? (
|
|
257
|
+
<p className="anim-order__hint">
|
|
258
|
+
{hasOpenReturn
|
|
259
|
+
? "A return or exchange request is already in progress for this order."
|
|
260
|
+
: "No items are available for return or exchange on this order."}
|
|
261
|
+
</p>
|
|
262
|
+
) : null}
|
|
263
|
+
|
|
264
|
+
{showReturnExchange && !returnActionsDisabled ? (
|
|
265
|
+
<p className="anim-order__hint">
|
|
266
|
+
Refunds go to your default payment method.{" "}
|
|
267
|
+
<LocalizedLink href="/account/payment-methods">
|
|
268
|
+
Manage payment methods
|
|
269
|
+
</LocalizedLink>
|
|
270
|
+
</p>
|
|
271
|
+
) : null}
|
|
272
|
+
|
|
273
|
+
{error ? <p className="anim-order__msg anim-order__msg--error">{error}</p> : null}
|
|
274
|
+
{success ? <p className="anim-order__msg anim-order__msg--ok">{success}</p> : null}
|
|
275
|
+
|
|
276
|
+
{mounted && cancelOpen
|
|
277
|
+
? createPortal(
|
|
278
|
+
<div
|
|
279
|
+
className="anim-order-modal"
|
|
280
|
+
role="dialog"
|
|
281
|
+
aria-modal="true"
|
|
282
|
+
aria-labelledby={titleId}
|
|
283
|
+
>
|
|
284
|
+
<button
|
|
285
|
+
type="button"
|
|
286
|
+
className="anim-order-modal__backdrop"
|
|
287
|
+
aria-label="Close cancel confirmation"
|
|
288
|
+
disabled={pending}
|
|
289
|
+
onClick={() => {
|
|
290
|
+
if (!pending) setCancelOpen(false)
|
|
291
|
+
}}
|
|
292
|
+
/>
|
|
293
|
+
<div className="anim-order-modal__panel">
|
|
294
|
+
<div className="anim-order-modal__head">
|
|
295
|
+
<h3 id={titleId}>Cancel this order?</h3>
|
|
296
|
+
<button
|
|
297
|
+
type="button"
|
|
298
|
+
className="anim-order-modal__close"
|
|
299
|
+
aria-label="Close"
|
|
300
|
+
disabled={pending}
|
|
301
|
+
onClick={() => setCancelOpen(false)}
|
|
302
|
+
>
|
|
303
|
+
×
|
|
304
|
+
</button>
|
|
305
|
+
</div>
|
|
306
|
+
<div className="anim-order-modal__body">
|
|
307
|
+
<p>
|
|
308
|
+
Cancel order <strong>#{order.display_id ?? order.id.slice(-6)}</strong>?
|
|
309
|
+
This cannot be undone. Any authorized payment will be voided
|
|
310
|
+
according to gateway rules.
|
|
311
|
+
</p>
|
|
312
|
+
{error ? (
|
|
313
|
+
<p className="anim-order__msg anim-order__msg--error">{error}</p>
|
|
314
|
+
) : null}
|
|
315
|
+
<div className="anim-order-modal__actions">
|
|
316
|
+
<button
|
|
317
|
+
type="button"
|
|
318
|
+
disabled={pending}
|
|
319
|
+
onClick={() => setCancelOpen(false)}
|
|
320
|
+
className="anim-order__btn anim-order__btn--outline"
|
|
321
|
+
>
|
|
322
|
+
Keep order
|
|
323
|
+
</button>
|
|
324
|
+
<button
|
|
325
|
+
type="button"
|
|
326
|
+
disabled={pending}
|
|
327
|
+
onClick={handleCancel}
|
|
328
|
+
className="anim-order__btn anim-order__btn--danger"
|
|
329
|
+
>
|
|
330
|
+
{pending ? "Cancelling…" : "Yes, cancel order"}
|
|
331
|
+
</button>
|
|
332
|
+
</div>
|
|
333
|
+
</div>
|
|
334
|
+
</div>
|
|
335
|
+
</div>,
|
|
336
|
+
document.body
|
|
337
|
+
)
|
|
338
|
+
: null}
|
|
339
|
+
</div>
|
|
340
|
+
)
|
|
341
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import Image from "next/image"
|
|
4
|
+
import { motion } from "framer-motion"
|
|
5
|
+
import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
|
|
6
|
+
import { formatPrice } from "@pradip1995/segment-primitives/format-price"
|
|
7
|
+
import type { HttpTypes } from "@medusajs/types"
|
|
8
|
+
import OrderActions from "./order-actions"
|
|
9
|
+
import OrderTracking from "./order-tracking"
|
|
10
|
+
|
|
11
|
+
function pretty(value?: string | null) {
|
|
12
|
+
if (!value) return ""
|
|
13
|
+
return value.replace(/_/g, " ")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function statusTone(value?: string | null): "ok" | "warn" | "bad" | "info" {
|
|
17
|
+
const s = (value || "").toLowerCase()
|
|
18
|
+
if (s.includes("cancel") || s.includes("fail")) return "bad"
|
|
19
|
+
if (s.includes("deliver") || s.includes("complete") || s === "captured" || s === "paid") {
|
|
20
|
+
return "ok"
|
|
21
|
+
}
|
|
22
|
+
if (s.includes("ship") || s.includes("fulfill")) return "info"
|
|
23
|
+
if (s.includes("pending") || s.includes("not_") || s.includes("await")) return "warn"
|
|
24
|
+
return "info"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default function OrderDetailsView({
|
|
28
|
+
order,
|
|
29
|
+
isLoggedIn,
|
|
30
|
+
}: {
|
|
31
|
+
order: HttpTypes.StoreOrder
|
|
32
|
+
isLoggedIn: boolean
|
|
33
|
+
}) {
|
|
34
|
+
const currency = order.currency_code || "inr"
|
|
35
|
+
const items = order.items || []
|
|
36
|
+
const shipping = order.shipping_address
|
|
37
|
+
const status = pretty(order.status)
|
|
38
|
+
const fulfillment = pretty(order.fulfillment_status)
|
|
39
|
+
const payment = pretty(order.payment_status)
|
|
40
|
+
const guestTrackHref = `/account?view=guest&email=${encodeURIComponent(order.email || "")}`
|
|
41
|
+
|
|
42
|
+
const returns =
|
|
43
|
+
(
|
|
44
|
+
order as HttpTypes.StoreOrder & {
|
|
45
|
+
returns?: Array<{
|
|
46
|
+
status?: string | null
|
|
47
|
+
exchange_id?: string | null
|
|
48
|
+
claim_id?: string | null
|
|
49
|
+
}>
|
|
50
|
+
}
|
|
51
|
+
).returns || []
|
|
52
|
+
const activeReturn = returns.find(
|
|
53
|
+
(r) =>
|
|
54
|
+
r.status &&
|
|
55
|
+
!r.exchange_id &&
|
|
56
|
+
!r.claim_id &&
|
|
57
|
+
!["canceled", "cancelled", "rejected"].includes(r.status.toLowerCase())
|
|
58
|
+
)
|
|
59
|
+
const returnStatusLabel = activeReturn?.status
|
|
60
|
+
? pretty(activeReturn.status)
|
|
61
|
+
: null
|
|
62
|
+
const paymentStatus = (order.payment_status || "").toLowerCase()
|
|
63
|
+
const refundLabel =
|
|
64
|
+
paymentStatus === "refunded"
|
|
65
|
+
? "Refunded"
|
|
66
|
+
: paymentStatus === "partially_refunded"
|
|
67
|
+
? "Partially refunded"
|
|
68
|
+
: null
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<section
|
|
72
|
+
className="anim-order anim-order--details"
|
|
73
|
+
data-testid="segment-animation-order-details"
|
|
74
|
+
>
|
|
75
|
+
<div className="anim-order__atmosphere" aria-hidden />
|
|
76
|
+
|
|
77
|
+
<div className="anim-order__inner anim-order__inner--wide">
|
|
78
|
+
<motion.header
|
|
79
|
+
className="anim-order__hero anim-order__hero--details"
|
|
80
|
+
initial={{ opacity: 0, y: 16 }}
|
|
81
|
+
animate={{ opacity: 1, y: 0 }}
|
|
82
|
+
transition={{ duration: 0.5, ease: [0.22, 1, 0.36, 1] }}
|
|
83
|
+
>
|
|
84
|
+
<p className="anim-order__eyebrow">Purchases</p>
|
|
85
|
+
<h1 className="anim-order__title">Order details</h1>
|
|
86
|
+
<p className="anim-order__subtitle">
|
|
87
|
+
Tracking, items, and actions for this purchase.
|
|
88
|
+
</p>
|
|
89
|
+
<span className="anim-order__accent-line" aria-hidden />
|
|
90
|
+
</motion.header>
|
|
91
|
+
|
|
92
|
+
<div className="anim-order__details-grid">
|
|
93
|
+
<div className="anim-order__details-main">
|
|
94
|
+
<motion.div
|
|
95
|
+
className="anim-order__panel"
|
|
96
|
+
initial={{ opacity: 0, y: 14 }}
|
|
97
|
+
animate={{ opacity: 1, y: 0 }}
|
|
98
|
+
transition={{ duration: 0.45, delay: 0.08 }}
|
|
99
|
+
>
|
|
100
|
+
<div className="anim-order__details-head">
|
|
101
|
+
<div>
|
|
102
|
+
<h2 className="anim-order__details-id">
|
|
103
|
+
Order #{order.display_id ?? order.id.slice(-6)}
|
|
104
|
+
</h2>
|
|
105
|
+
<div className="anim-order__status-row">
|
|
106
|
+
{status ? (
|
|
107
|
+
<span
|
|
108
|
+
className={`anim-order__status anim-order__status--${statusTone(order.status)}`}
|
|
109
|
+
>
|
|
110
|
+
{status}
|
|
111
|
+
</span>
|
|
112
|
+
) : null}
|
|
113
|
+
{fulfillment ? (
|
|
114
|
+
<span
|
|
115
|
+
className={`anim-order__status anim-order__status--${statusTone(order.fulfillment_status)}`}
|
|
116
|
+
>
|
|
117
|
+
{fulfillment}
|
|
118
|
+
</span>
|
|
119
|
+
) : null}
|
|
120
|
+
{payment ? (
|
|
121
|
+
<span
|
|
122
|
+
className={`anim-order__status anim-order__status--${statusTone(order.payment_status)}`}
|
|
123
|
+
>
|
|
124
|
+
Payment: {payment}
|
|
125
|
+
</span>
|
|
126
|
+
) : null}
|
|
127
|
+
{returnStatusLabel ? (
|
|
128
|
+
<span className="anim-order__status anim-order__status--warn">
|
|
129
|
+
Return {returnStatusLabel}
|
|
130
|
+
</span>
|
|
131
|
+
) : null}
|
|
132
|
+
{refundLabel ? (
|
|
133
|
+
<span className="anim-order__status anim-order__status--ok">
|
|
134
|
+
{refundLabel}
|
|
135
|
+
</span>
|
|
136
|
+
) : null}
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
{order.created_at ? (
|
|
140
|
+
<p className="anim-order__placed">
|
|
141
|
+
Placed{" "}
|
|
142
|
+
{new Date(order.created_at).toLocaleDateString("en-IN", {
|
|
143
|
+
dateStyle: "medium",
|
|
144
|
+
})}
|
|
145
|
+
</p>
|
|
146
|
+
) : null}
|
|
147
|
+
</div>
|
|
148
|
+
|
|
149
|
+
<OrderTracking order={order} />
|
|
150
|
+
|
|
151
|
+
<ul className="anim-order__items anim-order__items--details">
|
|
152
|
+
{items.map((item) => (
|
|
153
|
+
<li key={item.id} className="anim-order__item">
|
|
154
|
+
<div className="anim-order__thumb anim-order__thumb--tall">
|
|
155
|
+
{item.thumbnail ? (
|
|
156
|
+
<Image
|
|
157
|
+
src={item.thumbnail}
|
|
158
|
+
alt={item.title || "Product"}
|
|
159
|
+
fill
|
|
160
|
+
className="object-cover"
|
|
161
|
+
unoptimized
|
|
162
|
+
/>
|
|
163
|
+
) : null}
|
|
164
|
+
</div>
|
|
165
|
+
<div className="anim-order__item-meta">
|
|
166
|
+
<p className="anim-order__item-title">
|
|
167
|
+
{item.product_title || item.title}
|
|
168
|
+
</p>
|
|
169
|
+
{item.variant_title && item.variant_title !== "Default" ? (
|
|
170
|
+
<p className="anim-order__item-qty">{item.variant_title}</p>
|
|
171
|
+
) : null}
|
|
172
|
+
<p className="anim-order__item-qty">Qty: {item.quantity}</p>
|
|
173
|
+
</div>
|
|
174
|
+
<p className="anim-order__item-price">
|
|
175
|
+
{formatPrice(item.total, currency)}
|
|
176
|
+
</p>
|
|
177
|
+
</li>
|
|
178
|
+
))}
|
|
179
|
+
</ul>
|
|
180
|
+
</motion.div>
|
|
181
|
+
|
|
182
|
+
<OrderActions order={order} />
|
|
183
|
+
</div>
|
|
184
|
+
|
|
185
|
+
<aside className="anim-order__details-side">
|
|
186
|
+
{shipping ? (
|
|
187
|
+
<div className="anim-order__panel">
|
|
188
|
+
<p className="anim-order__panel-label">Shipping address</p>
|
|
189
|
+
<p className="anim-order__panel-name">
|
|
190
|
+
{[shipping.first_name, shipping.last_name].filter(Boolean).join(" ")}
|
|
191
|
+
</p>
|
|
192
|
+
<p className="anim-order__panel-meta">
|
|
193
|
+
{shipping.address_1}
|
|
194
|
+
{shipping.address_2 ? (
|
|
195
|
+
<>
|
|
196
|
+
<br />
|
|
197
|
+
{shipping.address_2}
|
|
198
|
+
</>
|
|
199
|
+
) : null}
|
|
200
|
+
<br />
|
|
201
|
+
{[shipping.city, shipping.province, shipping.postal_code]
|
|
202
|
+
.filter(Boolean)
|
|
203
|
+
.join(", ")}
|
|
204
|
+
{shipping.phone ? (
|
|
205
|
+
<>
|
|
206
|
+
<br />
|
|
207
|
+
{shipping.phone}
|
|
208
|
+
</>
|
|
209
|
+
) : null}
|
|
210
|
+
</p>
|
|
211
|
+
</div>
|
|
212
|
+
) : null}
|
|
213
|
+
|
|
214
|
+
<div className="anim-order__panel">
|
|
215
|
+
<p className="anim-order__panel-label">Order summary</p>
|
|
216
|
+
<dl className="anim-order__summary">
|
|
217
|
+
<div>
|
|
218
|
+
<dt>Subtotal</dt>
|
|
219
|
+
<dd>{formatPrice(order.subtotal, currency)}</dd>
|
|
220
|
+
</div>
|
|
221
|
+
<div>
|
|
222
|
+
<dt>Shipping</dt>
|
|
223
|
+
<dd>{formatPrice(order.shipping_total, currency)}</dd>
|
|
224
|
+
</div>
|
|
225
|
+
<div className="anim-order__summary-total">
|
|
226
|
+
<dt>Total</dt>
|
|
227
|
+
<dd>{formatPrice(order.total, currency)}</dd>
|
|
228
|
+
</div>
|
|
229
|
+
</dl>
|
|
230
|
+
</div>
|
|
231
|
+
|
|
232
|
+
<div className="anim-order__actions anim-order__actions--stack">
|
|
233
|
+
<LocalizedLink
|
|
234
|
+
href={isLoggedIn ? "/account/orders" : guestTrackHref}
|
|
235
|
+
className="anim-order__btn anim-order__btn--outline"
|
|
236
|
+
>
|
|
237
|
+
{isLoggedIn ? "Back to orders" : "Track guest order"}
|
|
238
|
+
</LocalizedLink>
|
|
239
|
+
{!isLoggedIn ? (
|
|
240
|
+
<LocalizedLink
|
|
241
|
+
href="/store"
|
|
242
|
+
className="anim-order__btn anim-order__btn--primary"
|
|
243
|
+
>
|
|
244
|
+
Continue shopping
|
|
245
|
+
</LocalizedLink>
|
|
246
|
+
) : null}
|
|
247
|
+
</div>
|
|
248
|
+
</aside>
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
</section>
|
|
252
|
+
)
|
|
253
|
+
}
|