@pradip1995/segment-login-template 0.5.26 → 0.5.28
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 +58 -54
- package/src/account-addresses.tsx +307 -287
- package/src/account-guest-orders.tsx +98 -98
- package/src/account-orders.tsx +260 -260
- package/src/account-overview.tsx +133 -133
- package/src/account-payment-methods.tsx +328 -328
- package/src/account-profile-logic.ts +282 -282
- package/src/account-profile.tsx +111 -111
- package/src/account-theme.ts +91 -91
- package/src/account-utils.ts +20 -20
- package/src/address-actions.ts +74 -0
- package/src/auth-server.ts +442 -442
- package/src/card-expiry.test.ts +71 -0
- package/src/card-expiry.ts +29 -0
- package/src/commerce-auth-otp-modal.css +125 -125
- package/src/commerce-auth-otp-modal.tsx +121 -121
- package/src/default-address.test.ts +143 -0
- package/src/default-address.ts +51 -0
- package/src/forgot-password-form.tsx +109 -109
- package/src/google-auth-section.tsx +22 -22
- package/src/google-sign-in-section.tsx +67 -67
- package/src/guest-order-modal.tsx +215 -215
- package/src/index.ts +7 -7
- package/src/is-next-redirect.ts +60 -60
- package/src/login-brand-panel.tsx +159 -158
- package/src/login-form.tsx +469 -469
- package/src/manifest.ts +11 -11
- package/src/order-history-status.test.ts +224 -224
- package/src/order-history-status.ts +244 -244
- package/src/otp-component.ts +14 -14
- package/src/otp-input.tsx +46 -46
- package/src/otp-unified-form.tsx +333 -333
- package/src/otp-verification-modal.tsx +112 -112
- package/src/payment-methods-actions.ts +243 -243
- package/src/profile-email-field.tsx +116 -116
- package/src/profile-email.test.ts +182 -182
- package/src/profile-email.ts +54 -54
- package/src/profile-phone-field.tsx +119 -119
- package/src/register-form.tsx +339 -339
- package/src/reorder-checkout-address.ts +103 -101
- package/src/reset-password-form.tsx +103 -103
- package/src/reset-password-page.tsx +12 -12
- package/src/segment.tsx +272 -272
package/src/account-orders.tsx
CHANGED
|
@@ -1,260 +1,260 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { useEffect, useMemo, useState, type MouseEvent } from "react"
|
|
4
|
-
import { usePathname, useRouter } from "next/navigation"
|
|
5
|
-
import type { HttpTypes } from "@medusajs/types"
|
|
6
|
-
import { addToCart } from "@pradip1995/commerce-core/client/actions/cart"
|
|
7
|
-
import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
|
|
8
|
-
import { formatPrice } from "@pradip1995/segment-primitives/format-price"
|
|
9
|
-
import { presentOrderLines } from "@pradip1995/segment-primitives/order-lines"
|
|
10
|
-
import { applyReorderCheckoutAddress, clearCartLineItems } from "./reorder-checkout-address"
|
|
11
|
-
import { acct } from "./account-theme"
|
|
12
|
-
import {
|
|
13
|
-
resolveOrderHistoryStatus,
|
|
14
|
-
type OrderHistoryStatusInput,
|
|
15
|
-
type OrderHistoryStatusTone,
|
|
16
|
-
} from "./order-history-status"
|
|
17
|
-
|
|
18
|
-
function isCancelled(order: HttpTypes.StoreOrder) {
|
|
19
|
-
const status = (order.status || "").toLowerCase()
|
|
20
|
-
return status === "canceled" || status === "cancelled"
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function canReorder(order: HttpTypes.StoreOrder) {
|
|
24
|
-
if (isCancelled(order)) return false
|
|
25
|
-
const fulfillment = (order.fulfillment_status || "").toLowerCase()
|
|
26
|
-
return ["delivered", "partially_delivered"].includes(fulfillment)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function historyStatus(order: HttpTypes.StoreOrder) {
|
|
30
|
-
return resolveOrderHistoryStatus(order as OrderHistoryStatusInput)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function statusStyle(tone: OrderHistoryStatusTone) {
|
|
34
|
-
if (tone === "cancel") {
|
|
35
|
-
return "bg-[#FFF1F2] text-[#BE123C] border-[#BE123C]/20"
|
|
36
|
-
}
|
|
37
|
-
if (tone === "return") {
|
|
38
|
-
return "bg-[#FFF7ED] text-[#C2410C] border-[#C2410C]/20"
|
|
39
|
-
}
|
|
40
|
-
if (tone === "done") {
|
|
41
|
-
return "bg-[#E6F4F0] text-[#008A5D] border-[#008A5D]/20"
|
|
42
|
-
}
|
|
43
|
-
if (tone === "shipped") {
|
|
44
|
-
return "bg-[#EBF5FF] text-[#0068D2] border-[#0068D2]/20"
|
|
45
|
-
}
|
|
46
|
-
return "bg-surface-muted text-muted border-cart-border"
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const DEFAULT_PAGE_SIZE = 3
|
|
50
|
-
|
|
51
|
-
function paginationItems(current: number, total: number) {
|
|
52
|
-
if (total <= 7) return Array.from({ length: total }, (_, index) => index + 1)
|
|
53
|
-
const items: (number | "ellipsis")[] = [1]
|
|
54
|
-
const start = Math.max(2, current - 1)
|
|
55
|
-
const end = Math.min(total - 1, current + 1)
|
|
56
|
-
if (start > 2) items.push("ellipsis")
|
|
57
|
-
for (let page = start; page <= end; page += 1) items.push(page)
|
|
58
|
-
if (end < total - 1) items.push("ellipsis")
|
|
59
|
-
items.push(total)
|
|
60
|
-
return items
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export default function AccountOrders({
|
|
64
|
-
orders,
|
|
65
|
-
pageSize = DEFAULT_PAGE_SIZE,
|
|
66
|
-
}: {
|
|
67
|
-
orders?: HttpTypes.StoreOrder[] | { orders?: HttpTypes.StoreOrder[] } | null
|
|
68
|
-
pageSize?: number
|
|
69
|
-
}) {
|
|
70
|
-
const [query, setQuery] = useState("")
|
|
71
|
-
const [page, setPage] = useState(1)
|
|
72
|
-
const [reorderingId, setReorderingId] = useState<string | null>(null)
|
|
73
|
-
const router = useRouter()
|
|
74
|
-
const pathname = usePathname() || ""
|
|
75
|
-
const countryCode = pathname.split("/").filter(Boolean)[0] || "in"
|
|
76
|
-
|
|
77
|
-
const safeOrders: HttpTypes.StoreOrder[] = useMemo(() => {
|
|
78
|
-
if (Array.isArray(orders)) return orders
|
|
79
|
-
if (Array.isArray((orders as { orders?: HttpTypes.StoreOrder[] })?.orders)) {
|
|
80
|
-
return (orders as { orders: HttpTypes.StoreOrder[] }).orders
|
|
81
|
-
}
|
|
82
|
-
return []
|
|
83
|
-
}, [orders])
|
|
84
|
-
|
|
85
|
-
const filtered = useMemo(() => {
|
|
86
|
-
const q = query.trim().toLowerCase()
|
|
87
|
-
if (!q) return safeOrders
|
|
88
|
-
return safeOrders.filter((order) => {
|
|
89
|
-
const id = String(order.display_id ?? order.id)
|
|
90
|
-
const status = historyStatus(order).label
|
|
91
|
-
return id.includes(q) || status.toLowerCase().includes(q)
|
|
92
|
-
})
|
|
93
|
-
}, [safeOrders, query])
|
|
94
|
-
|
|
95
|
-
const perPage = Math.max(1, pageSize)
|
|
96
|
-
const totalPages = Math.max(1, Math.ceil(filtered.length / perPage))
|
|
97
|
-
const currentPage = Math.min(page, totalPages)
|
|
98
|
-
const paged = useMemo(
|
|
99
|
-
() => filtered.slice((currentPage - 1) * perPage, currentPage * perPage),
|
|
100
|
-
[filtered, currentPage, perPage]
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
useEffect(() => {
|
|
104
|
-
setPage(1)
|
|
105
|
-
}, [query, perPage])
|
|
106
|
-
|
|
107
|
-
useEffect(() => {
|
|
108
|
-
if (page > totalPages) setPage(totalPages)
|
|
109
|
-
}, [page, totalPages])
|
|
110
|
-
|
|
111
|
-
async function handleReorder(event: MouseEvent, order: HttpTypes.StoreOrder) {
|
|
112
|
-
event.preventDefault()
|
|
113
|
-
event.stopPropagation()
|
|
114
|
-
if (!canReorder(order) || reorderingId) return
|
|
115
|
-
setReorderingId(order.id)
|
|
116
|
-
try {
|
|
117
|
-
const reorderItems = presentOrderLines(order).reorderItems
|
|
118
|
-
await clearCartLineItems()
|
|
119
|
-
for (const item of reorderItems) {
|
|
120
|
-
if (!item.variant_id) continue
|
|
121
|
-
await addToCart({
|
|
122
|
-
variantId: item.variant_id,
|
|
123
|
-
quantity: item.quantity || 1,
|
|
124
|
-
countryCode,
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
await applyReorderCheckoutAddress(order)
|
|
128
|
-
router.push(`/${countryCode}/checkout`)
|
|
129
|
-
} catch {
|
|
130
|
-
setReorderingId(null)
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return (
|
|
135
|
-
<div className="space-y-6">
|
|
136
|
-
<div className="pb-6 border-b border-cart-border">
|
|
137
|
-
<h2 className={acct.title}>Order history</h2>
|
|
138
|
-
<p className={`text-sm ${acct.muted} mt-2`}>
|
|
139
|
-
View and track your past orders.
|
|
140
|
-
</p>
|
|
141
|
-
</div>
|
|
142
|
-
|
|
143
|
-
<input
|
|
144
|
-
type="search"
|
|
145
|
-
value={query}
|
|
146
|
-
onChange={(e) => setQuery(e.target.value)}
|
|
147
|
-
placeholder="Search by order number or status"
|
|
148
|
-
className={acct.input}
|
|
149
|
-
/>
|
|
150
|
-
|
|
151
|
-
{filtered.length === 0 ? (
|
|
152
|
-
<div className={`${acct.cardMuted} p-8 text-center`}>
|
|
153
|
-
<p className={`${acct.muted} text-sm mb-4`}>
|
|
154
|
-
{safeOrders.length === 0
|
|
155
|
-
? "No orders yet."
|
|
156
|
-
: "No orders match your search."}
|
|
157
|
-
</p>
|
|
158
|
-
{safeOrders.length === 0 && (
|
|
159
|
-
<LocalizedLink href="/store" className={acct.btnPrimary}>
|
|
160
|
-
Start shopping
|
|
161
|
-
</LocalizedLink>
|
|
162
|
-
)}
|
|
163
|
-
</div>
|
|
164
|
-
) : (
|
|
165
|
-
<ul className="space-y-4">
|
|
166
|
-
{paged.map((order) => {
|
|
167
|
-
const resolved = historyStatus(order)
|
|
168
|
-
const showReorder = canReorder(order)
|
|
169
|
-
const presentation = presentOrderLines(order)
|
|
170
|
-
return (
|
|
171
|
-
<li key={order.id}>
|
|
172
|
-
<div
|
|
173
|
-
className={`${acct.card} p-5 flex flex-wrap items-center justify-between gap-4`}
|
|
174
|
-
>
|
|
175
|
-
<LocalizedLink
|
|
176
|
-
href={`/orders/${order.id}`}
|
|
177
|
-
className="space-y-2 min-w-0 flex-1 hover:opacity-90 transition-opacity"
|
|
178
|
-
>
|
|
179
|
-
<div className="flex flex-wrap items-center gap-2">
|
|
180
|
-
<p className={`font-bold ${acct.heading}`}>
|
|
181
|
-
Order #{order.display_id}
|
|
182
|
-
</p>
|
|
183
|
-
<span className={`${acct.badge} capitalize ${statusStyle(resolved.tone)}`}>
|
|
184
|
-
{resolved.label}
|
|
185
|
-
</span>
|
|
186
|
-
</div>
|
|
187
|
-
<p className={`text-xs ${acct.muted}`}>
|
|
188
|
-
{order.created_at &&
|
|
189
|
-
new Date(order.created_at).toLocaleDateString("en-IN", {
|
|
190
|
-
dateStyle: "medium",
|
|
191
|
-
})}
|
|
192
|
-
{" · "}
|
|
193
|
-
{presentation.purchasedItems.length} item
|
|
194
|
-
{presentation.purchasedItems.length === 1 ? "" : "s"}
|
|
195
|
-
</p>
|
|
196
|
-
<p className={`text-base font-bold ${acct.accent}`}>
|
|
197
|
-
{formatPrice(presentation.paidTotal, order.currency_code)}
|
|
198
|
-
</p>
|
|
199
|
-
</LocalizedLink>
|
|
200
|
-
{showReorder ? (
|
|
201
|
-
<button
|
|
202
|
-
type="button"
|
|
203
|
-
className={acct.btnPrimary}
|
|
204
|
-
disabled={reorderingId === order.id}
|
|
205
|
-
onClick={(event) => handleReorder(event, order)}
|
|
206
|
-
>
|
|
207
|
-
{reorderingId === order.id ? "Adding…" : "Reorder"}
|
|
208
|
-
</button>
|
|
209
|
-
) : null}
|
|
210
|
-
</div>
|
|
211
|
-
</li>
|
|
212
|
-
)
|
|
213
|
-
})}
|
|
214
|
-
</ul>
|
|
215
|
-
)}
|
|
216
|
-
|
|
217
|
-
{filtered.length > perPage ? (
|
|
218
|
-
<nav className="account-orders__pager" aria-label="Order pagination">
|
|
219
|
-
<button
|
|
220
|
-
type="button"
|
|
221
|
-
className="account-orders__page"
|
|
222
|
-
disabled={currentPage <= 1}
|
|
223
|
-
onClick={() => setPage((p) => Math.max(1, p - 1))}
|
|
224
|
-
>
|
|
225
|
-
Prev
|
|
226
|
-
</button>
|
|
227
|
-
{paginationItems(currentPage, totalPages).map((item, index) =>
|
|
228
|
-
item === "ellipsis" ? (
|
|
229
|
-
<span key={`ellipsis-${index}`} className="account-orders__ellipsis">
|
|
230
|
-
…
|
|
231
|
-
</span>
|
|
232
|
-
) : (
|
|
233
|
-
<button
|
|
234
|
-
key={item}
|
|
235
|
-
type="button"
|
|
236
|
-
className={
|
|
237
|
-
item === currentPage
|
|
238
|
-
? "account-orders__page is-active"
|
|
239
|
-
: "account-orders__page"
|
|
240
|
-
}
|
|
241
|
-
aria-current={item === currentPage ? "page" : undefined}
|
|
242
|
-
onClick={() => setPage(item)}
|
|
243
|
-
>
|
|
244
|
-
{item}
|
|
245
|
-
</button>
|
|
246
|
-
)
|
|
247
|
-
)}
|
|
248
|
-
<button
|
|
249
|
-
type="button"
|
|
250
|
-
className="account-orders__page"
|
|
251
|
-
disabled={currentPage >= totalPages}
|
|
252
|
-
onClick={() => setPage((p) => Math.min(totalPages, p + 1))}
|
|
253
|
-
>
|
|
254
|
-
Next
|
|
255
|
-
</button>
|
|
256
|
-
</nav>
|
|
257
|
-
) : null}
|
|
258
|
-
</div>
|
|
259
|
-
)
|
|
260
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useMemo, useState, type MouseEvent } from "react"
|
|
4
|
+
import { usePathname, useRouter } from "next/navigation"
|
|
5
|
+
import type { HttpTypes } from "@medusajs/types"
|
|
6
|
+
import { addToCart } from "@pradip1995/commerce-core/client/actions/cart"
|
|
7
|
+
import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
|
|
8
|
+
import { formatPrice } from "@pradip1995/segment-primitives/format-price"
|
|
9
|
+
import { presentOrderLines } from "@pradip1995/segment-primitives/order-lines"
|
|
10
|
+
import { applyReorderCheckoutAddress, clearCartLineItems } from "./reorder-checkout-address"
|
|
11
|
+
import { acct } from "./account-theme"
|
|
12
|
+
import {
|
|
13
|
+
resolveOrderHistoryStatus,
|
|
14
|
+
type OrderHistoryStatusInput,
|
|
15
|
+
type OrderHistoryStatusTone,
|
|
16
|
+
} from "./order-history-status"
|
|
17
|
+
|
|
18
|
+
function isCancelled(order: HttpTypes.StoreOrder) {
|
|
19
|
+
const status = (order.status || "").toLowerCase()
|
|
20
|
+
return status === "canceled" || status === "cancelled"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function canReorder(order: HttpTypes.StoreOrder) {
|
|
24
|
+
if (isCancelled(order)) return false
|
|
25
|
+
const fulfillment = (order.fulfillment_status || "").toLowerCase()
|
|
26
|
+
return ["delivered", "partially_delivered"].includes(fulfillment)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function historyStatus(order: HttpTypes.StoreOrder) {
|
|
30
|
+
return resolveOrderHistoryStatus(order as OrderHistoryStatusInput)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function statusStyle(tone: OrderHistoryStatusTone) {
|
|
34
|
+
if (tone === "cancel") {
|
|
35
|
+
return "bg-[#FFF1F2] text-[#BE123C] border-[#BE123C]/20"
|
|
36
|
+
}
|
|
37
|
+
if (tone === "return") {
|
|
38
|
+
return "bg-[#FFF7ED] text-[#C2410C] border-[#C2410C]/20"
|
|
39
|
+
}
|
|
40
|
+
if (tone === "done") {
|
|
41
|
+
return "bg-[#E6F4F0] text-[#008A5D] border-[#008A5D]/20"
|
|
42
|
+
}
|
|
43
|
+
if (tone === "shipped") {
|
|
44
|
+
return "bg-[#EBF5FF] text-[#0068D2] border-[#0068D2]/20"
|
|
45
|
+
}
|
|
46
|
+
return "bg-surface-muted text-muted border-cart-border"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const DEFAULT_PAGE_SIZE = 3
|
|
50
|
+
|
|
51
|
+
function paginationItems(current: number, total: number) {
|
|
52
|
+
if (total <= 7) return Array.from({ length: total }, (_, index) => index + 1)
|
|
53
|
+
const items: (number | "ellipsis")[] = [1]
|
|
54
|
+
const start = Math.max(2, current - 1)
|
|
55
|
+
const end = Math.min(total - 1, current + 1)
|
|
56
|
+
if (start > 2) items.push("ellipsis")
|
|
57
|
+
for (let page = start; page <= end; page += 1) items.push(page)
|
|
58
|
+
if (end < total - 1) items.push("ellipsis")
|
|
59
|
+
items.push(total)
|
|
60
|
+
return items
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default function AccountOrders({
|
|
64
|
+
orders,
|
|
65
|
+
pageSize = DEFAULT_PAGE_SIZE,
|
|
66
|
+
}: {
|
|
67
|
+
orders?: HttpTypes.StoreOrder[] | { orders?: HttpTypes.StoreOrder[] } | null
|
|
68
|
+
pageSize?: number
|
|
69
|
+
}) {
|
|
70
|
+
const [query, setQuery] = useState("")
|
|
71
|
+
const [page, setPage] = useState(1)
|
|
72
|
+
const [reorderingId, setReorderingId] = useState<string | null>(null)
|
|
73
|
+
const router = useRouter()
|
|
74
|
+
const pathname = usePathname() || ""
|
|
75
|
+
const countryCode = pathname.split("/").filter(Boolean)[0] || "in"
|
|
76
|
+
|
|
77
|
+
const safeOrders: HttpTypes.StoreOrder[] = useMemo(() => {
|
|
78
|
+
if (Array.isArray(orders)) return orders
|
|
79
|
+
if (Array.isArray((orders as { orders?: HttpTypes.StoreOrder[] })?.orders)) {
|
|
80
|
+
return (orders as { orders: HttpTypes.StoreOrder[] }).orders
|
|
81
|
+
}
|
|
82
|
+
return []
|
|
83
|
+
}, [orders])
|
|
84
|
+
|
|
85
|
+
const filtered = useMemo(() => {
|
|
86
|
+
const q = query.trim().toLowerCase()
|
|
87
|
+
if (!q) return safeOrders
|
|
88
|
+
return safeOrders.filter((order) => {
|
|
89
|
+
const id = String(order.display_id ?? order.id)
|
|
90
|
+
const status = historyStatus(order).label
|
|
91
|
+
return id.includes(q) || status.toLowerCase().includes(q)
|
|
92
|
+
})
|
|
93
|
+
}, [safeOrders, query])
|
|
94
|
+
|
|
95
|
+
const perPage = Math.max(1, pageSize)
|
|
96
|
+
const totalPages = Math.max(1, Math.ceil(filtered.length / perPage))
|
|
97
|
+
const currentPage = Math.min(page, totalPages)
|
|
98
|
+
const paged = useMemo(
|
|
99
|
+
() => filtered.slice((currentPage - 1) * perPage, currentPage * perPage),
|
|
100
|
+
[filtered, currentPage, perPage]
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
setPage(1)
|
|
105
|
+
}, [query, perPage])
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (page > totalPages) setPage(totalPages)
|
|
109
|
+
}, [page, totalPages])
|
|
110
|
+
|
|
111
|
+
async function handleReorder(event: MouseEvent, order: HttpTypes.StoreOrder) {
|
|
112
|
+
event.preventDefault()
|
|
113
|
+
event.stopPropagation()
|
|
114
|
+
if (!canReorder(order) || reorderingId) return
|
|
115
|
+
setReorderingId(order.id)
|
|
116
|
+
try {
|
|
117
|
+
const reorderItems = presentOrderLines(order).reorderItems
|
|
118
|
+
await clearCartLineItems()
|
|
119
|
+
for (const item of reorderItems) {
|
|
120
|
+
if (!item.variant_id) continue
|
|
121
|
+
await addToCart({
|
|
122
|
+
variantId: item.variant_id,
|
|
123
|
+
quantity: item.quantity || 1,
|
|
124
|
+
countryCode,
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
await applyReorderCheckoutAddress(order)
|
|
128
|
+
router.push(`/${countryCode}/checkout`)
|
|
129
|
+
} catch {
|
|
130
|
+
setReorderingId(null)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<div className="space-y-6">
|
|
136
|
+
<div className="pb-6 border-b border-cart-border">
|
|
137
|
+
<h2 className={acct.title}>Order history</h2>
|
|
138
|
+
<p className={`text-sm ${acct.muted} mt-2`}>
|
|
139
|
+
View and track your past orders.
|
|
140
|
+
</p>
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
<input
|
|
144
|
+
type="search"
|
|
145
|
+
value={query}
|
|
146
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
147
|
+
placeholder="Search by order number or status"
|
|
148
|
+
className={acct.input}
|
|
149
|
+
/>
|
|
150
|
+
|
|
151
|
+
{filtered.length === 0 ? (
|
|
152
|
+
<div className={`${acct.cardMuted} p-8 text-center`}>
|
|
153
|
+
<p className={`${acct.muted} text-sm mb-4`}>
|
|
154
|
+
{safeOrders.length === 0
|
|
155
|
+
? "No orders yet."
|
|
156
|
+
: "No orders match your search."}
|
|
157
|
+
</p>
|
|
158
|
+
{safeOrders.length === 0 && (
|
|
159
|
+
<LocalizedLink href="/store" className={acct.btnPrimary}>
|
|
160
|
+
Start shopping
|
|
161
|
+
</LocalizedLink>
|
|
162
|
+
)}
|
|
163
|
+
</div>
|
|
164
|
+
) : (
|
|
165
|
+
<ul className="space-y-4">
|
|
166
|
+
{paged.map((order) => {
|
|
167
|
+
const resolved = historyStatus(order)
|
|
168
|
+
const showReorder = canReorder(order)
|
|
169
|
+
const presentation = presentOrderLines(order)
|
|
170
|
+
return (
|
|
171
|
+
<li key={order.id}>
|
|
172
|
+
<div
|
|
173
|
+
className={`${acct.card} p-5 flex flex-wrap items-center justify-between gap-4`}
|
|
174
|
+
>
|
|
175
|
+
<LocalizedLink
|
|
176
|
+
href={`/orders/${order.id}`}
|
|
177
|
+
className="space-y-2 min-w-0 flex-1 hover:opacity-90 transition-opacity"
|
|
178
|
+
>
|
|
179
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
180
|
+
<p className={`font-bold ${acct.heading}`}>
|
|
181
|
+
Order #{order.display_id}
|
|
182
|
+
</p>
|
|
183
|
+
<span className={`${acct.badge} capitalize ${statusStyle(resolved.tone)}`}>
|
|
184
|
+
{resolved.label}
|
|
185
|
+
</span>
|
|
186
|
+
</div>
|
|
187
|
+
<p className={`text-xs ${acct.muted}`}>
|
|
188
|
+
{order.created_at &&
|
|
189
|
+
new Date(order.created_at).toLocaleDateString("en-IN", {
|
|
190
|
+
dateStyle: "medium",
|
|
191
|
+
})}
|
|
192
|
+
{" · "}
|
|
193
|
+
{presentation.purchasedItems.length} item
|
|
194
|
+
{presentation.purchasedItems.length === 1 ? "" : "s"}
|
|
195
|
+
</p>
|
|
196
|
+
<p className={`text-base font-bold ${acct.accent}`}>
|
|
197
|
+
{formatPrice(presentation.paidTotal, order.currency_code)}
|
|
198
|
+
</p>
|
|
199
|
+
</LocalizedLink>
|
|
200
|
+
{showReorder ? (
|
|
201
|
+
<button
|
|
202
|
+
type="button"
|
|
203
|
+
className={acct.btnPrimary}
|
|
204
|
+
disabled={reorderingId === order.id}
|
|
205
|
+
onClick={(event) => handleReorder(event, order)}
|
|
206
|
+
>
|
|
207
|
+
{reorderingId === order.id ? "Adding…" : "Reorder"}
|
|
208
|
+
</button>
|
|
209
|
+
) : null}
|
|
210
|
+
</div>
|
|
211
|
+
</li>
|
|
212
|
+
)
|
|
213
|
+
})}
|
|
214
|
+
</ul>
|
|
215
|
+
)}
|
|
216
|
+
|
|
217
|
+
{filtered.length > perPage ? (
|
|
218
|
+
<nav className="account-orders__pager" aria-label="Order pagination">
|
|
219
|
+
<button
|
|
220
|
+
type="button"
|
|
221
|
+
className="account-orders__page"
|
|
222
|
+
disabled={currentPage <= 1}
|
|
223
|
+
onClick={() => setPage((p) => Math.max(1, p - 1))}
|
|
224
|
+
>
|
|
225
|
+
Prev
|
|
226
|
+
</button>
|
|
227
|
+
{paginationItems(currentPage, totalPages).map((item, index) =>
|
|
228
|
+
item === "ellipsis" ? (
|
|
229
|
+
<span key={`ellipsis-${index}`} className="account-orders__ellipsis">
|
|
230
|
+
…
|
|
231
|
+
</span>
|
|
232
|
+
) : (
|
|
233
|
+
<button
|
|
234
|
+
key={item}
|
|
235
|
+
type="button"
|
|
236
|
+
className={
|
|
237
|
+
item === currentPage
|
|
238
|
+
? "account-orders__page is-active"
|
|
239
|
+
: "account-orders__page"
|
|
240
|
+
}
|
|
241
|
+
aria-current={item === currentPage ? "page" : undefined}
|
|
242
|
+
onClick={() => setPage(item)}
|
|
243
|
+
>
|
|
244
|
+
{item}
|
|
245
|
+
</button>
|
|
246
|
+
)
|
|
247
|
+
)}
|
|
248
|
+
<button
|
|
249
|
+
type="button"
|
|
250
|
+
className="account-orders__page"
|
|
251
|
+
disabled={currentPage >= totalPages}
|
|
252
|
+
onClick={() => setPage((p) => Math.min(totalPages, p + 1))}
|
|
253
|
+
>
|
|
254
|
+
Next
|
|
255
|
+
</button>
|
|
256
|
+
</nav>
|
|
257
|
+
) : null}
|
|
258
|
+
</div>
|
|
259
|
+
)
|
|
260
|
+
}
|