@pradip1995/segment-jewelry-account-pages 0.1.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.
@@ -0,0 +1,215 @@
1
+ "use client"
2
+
3
+ import Image from "next/image"
4
+ import type { HttpTypes } from "@medusajs/types"
5
+ import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
6
+ import { formatPrice } from "@pradip1995/segment-primitives/format-price"
7
+
8
+ function getStatusDetails(status?: string, fulfillment?: string) {
9
+ const s = (fulfillment || status || "").toLowerCase()
10
+ if (s.includes("cancel")) {
11
+ return {
12
+ label: "Cancelled",
13
+ iconClass: "modern-order-row__status-icon--cancel",
14
+ Icon: function CancelIcon() {
15
+ return (
16
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" width="14" height="14">
17
+ <path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
18
+ </svg>
19
+ )
20
+ },
21
+ }
22
+ }
23
+ if (s.includes("ship")) {
24
+ return {
25
+ label: "Shipped",
26
+ iconClass: "modern-order-row__status-icon--shipped",
27
+ Icon: function ShippedIcon() {
28
+ return (
29
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" width="16" height="16">
30
+ <path strokeLinecap="round" strokeLinejoin="round" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
31
+ </svg>
32
+ )
33
+ },
34
+ }
35
+ }
36
+ if (s === "delivered" || s === "complete" || s === "completed" || s.includes("fulfill")) {
37
+ return {
38
+ label: s === "delivered" ? "Delivered" : "Order Confirmed",
39
+ iconClass: "modern-order-row__status-icon--done",
40
+ Icon: function CheckIcon() {
41
+ return (
42
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" width="15" height="15">
43
+ <path strokeLinecap="round" strokeLinejoin="round" d="M5 13l4 4L19 7" />
44
+ </svg>
45
+ )
46
+ },
47
+ }
48
+ }
49
+ return {
50
+ label: "Processing",
51
+ iconClass: "modern-order-row__status-icon--done",
52
+ Icon: function ProcessingIcon() {
53
+ return (
54
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" width="15" height="15">
55
+ <circle cx="12" cy="12" r="9" />
56
+ <path strokeLinecap="round" strokeLinejoin="round" d="M12 7v5l3 3" />
57
+ </svg>
58
+ )
59
+ },
60
+ }
61
+ }
62
+
63
+ function orderItemImage(item: HttpTypes.StoreOrderLineItem): string {
64
+ const fromItem = item.thumbnail?.trim()
65
+ if (fromItem) return fromItem
66
+ const product = (item as { product?: { thumbnail?: string | null } }).product
67
+ if (product?.thumbnail?.trim()) return product.thumbnail.trim()
68
+ const variantProduct = item.variant?.product as { thumbnail?: string | null } | undefined
69
+ return variantProduct?.thumbnail?.trim() || ""
70
+ }
71
+
72
+ function itemTitle(item: HttpTypes.StoreOrderLineItem): string {
73
+ return item.product_title || item.title || "Product"
74
+ }
75
+
76
+ function itemTotal(item: HttpTypes.StoreOrderLineItem): number {
77
+ if (typeof item.total === "number") return item.total
78
+ return (item.unit_price || 0) * (item.quantity || 0)
79
+ }
80
+
81
+ export default function ModernAccountOrderCard({
82
+ order,
83
+ compact = false,
84
+ }: {
85
+ order: HttpTypes.StoreOrder
86
+ compact?: boolean
87
+ }) {
88
+ const currency = order.currency_code
89
+ const statusInfo = getStatusDetails(order.status, order.fulfillment_status)
90
+ const items = order.items || []
91
+
92
+ const dateStr = order.created_at
93
+ ? new Date(order.created_at).toLocaleDateString("en-US", {
94
+ weekday: "short",
95
+ month: "short",
96
+ day: "2-digit",
97
+ year: "numeric",
98
+ })
99
+ : "—"
100
+
101
+ if (compact) {
102
+ return (
103
+ <LocalizedLink href={`/orders/${order.id}`} className="modern-order-row">
104
+ <div className="modern-order-row__col">
105
+ <p className="modern-order-row__label">Date placed</p>
106
+ <p className="modern-order-row__val">{dateStr}</p>
107
+ </div>
108
+
109
+ <div className="modern-order-row__col">
110
+ <p className="modern-order-row__label">Order number</p>
111
+ <p className="modern-order-row__val modern-order-row__val--id">
112
+ #{order.display_id ?? order.id}
113
+ </p>
114
+ </div>
115
+
116
+ <div className="modern-order-row__col">
117
+ <p className="modern-order-row__label">Total amount</p>
118
+ <p className="modern-order-row__val modern-order-row__val--price">
119
+ {formatPrice(order.total, currency)}
120
+ </p>
121
+ </div>
122
+
123
+ <div className="modern-order-row__col">
124
+ <p className="modern-order-row__label">Status</p>
125
+ <div className="modern-order-row__status">
126
+ <div className={`modern-order-row__status-icon ${statusInfo.iconClass}`}>
127
+ <statusInfo.Icon />
128
+ </div>
129
+ <span className="modern-order-row__status-text">{statusInfo.label}</span>
130
+ </div>
131
+ </div>
132
+
133
+ <div className="modern-order-row__chevron">
134
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" width="18" height="18">
135
+ <path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" />
136
+ </svg>
137
+ </div>
138
+ </LocalizedLink>
139
+ )
140
+ }
141
+
142
+ return (
143
+ <div className="modern-order-card">
144
+ <div className="modern-order-card__head">
145
+ <div className="modern-order-card__head-meta">
146
+ <div>
147
+ <span className="modern-order-card__label">Order Number</span>
148
+ <p className="modern-order-card__id">#{order.display_id ?? order.id}</p>
149
+ </div>
150
+ <div>
151
+ <span className="modern-order-card__label">Date Placed</span>
152
+ <p className="modern-order-card__date">{dateStr}</p>
153
+ </div>
154
+ </div>
155
+
156
+ <div className="modern-order-row__status">
157
+ <div className={`modern-order-row__status-icon ${statusInfo.iconClass}`}>
158
+ <statusInfo.Icon />
159
+ </div>
160
+ <span className="modern-order-row__status-text">{statusInfo.label}</span>
161
+ </div>
162
+ </div>
163
+
164
+ {items.length > 0 ? (
165
+ <ul className="modern-order-card__items">
166
+ {items.map((item) => {
167
+ const image = orderItemImage(item)
168
+ return (
169
+ <li key={item.id} className="modern-order-card__item">
170
+ <div className="modern-order-card__item-photo">
171
+ {image ? (
172
+ <Image
173
+ src={image}
174
+ alt={itemTitle(item)}
175
+ fill
176
+ sizes="72px"
177
+ className="modern-order-card__item-img"
178
+ unoptimized
179
+ />
180
+ ) : (
181
+ <div className="modern-order-card__item-placeholder">
182
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" width="20" height="20">
183
+ <path strokeLinecap="round" strokeLinejoin="round" d="M12 21a9 9 0 100-18 9 9 0 000 18z" />
184
+ </svg>
185
+ </div>
186
+ )}
187
+ </div>
188
+ <div className="modern-order-card__item-info">
189
+ <p className="modern-order-card__item-name">{itemTitle(item)}</p>
190
+ {item.variant_title && item.variant_title.toLowerCase() !== "default" ? (
191
+ <p className="modern-order-card__item-meta">{item.variant_title}</p>
192
+ ) : null}
193
+ <p className="modern-order-card__item-meta">Qty: {item.quantity}</p>
194
+ </div>
195
+ <p className="modern-order-card__item-price">
196
+ {formatPrice(itemTotal(item), currency)}
197
+ </p>
198
+ </li>
199
+ )
200
+ })}
201
+ </ul>
202
+ ) : null}
203
+
204
+ <div className="modern-order-card__foot">
205
+ <div>
206
+ <span className="modern-order-card__label">Total Amount</span>
207
+ <p className="modern-order-card__total-val">{formatPrice(order.total, currency)}</p>
208
+ </div>
209
+ <LocalizedLink href={`/orders/${order.id}`} className="modern-btn modern-btn--outline">
210
+ View Order Details →
211
+ </LocalizedLink>
212
+ </div>
213
+ </div>
214
+ )
215
+ }
@@ -0,0 +1,82 @@
1
+ "use client"
2
+
3
+ import { useMemo, useState } from "react"
4
+ import type { HttpTypes } from "@medusajs/types"
5
+ import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
6
+ import ModernAccountOrderCard from "./modern-account-order-card"
7
+
8
+ export default function ModernAccountOrders({
9
+ orders,
10
+ }: {
11
+ orders?: HttpTypes.StoreOrder[] | { orders?: HttpTypes.StoreOrder[] } | null
12
+ }) {
13
+ const [query, setQuery] = useState("")
14
+
15
+ const safeOrders: HttpTypes.StoreOrder[] = useMemo(() => {
16
+ if (Array.isArray(orders)) return orders
17
+ if (Array.isArray((orders as { orders?: HttpTypes.StoreOrder[] })?.orders)) {
18
+ return (orders as { orders: HttpTypes.StoreOrder[] }).orders
19
+ }
20
+ return []
21
+ }, [orders])
22
+
23
+ const filtered = useMemo(() => {
24
+ const q = query.trim().toLowerCase()
25
+ if (!q) return safeOrders
26
+ return safeOrders.filter((order) => {
27
+ const id = String(order.display_id ?? order.id)
28
+ const status = String(order.status ?? "").replace(/_/g, " ")
29
+ const fulfillment = String(order.fulfillment_status ?? "").replace(/_/g, " ")
30
+ return (
31
+ id.includes(q) ||
32
+ status.toLowerCase().includes(q) ||
33
+ fulfillment.toLowerCase().includes(q)
34
+ )
35
+ })
36
+ }, [safeOrders, query])
37
+
38
+ return (
39
+ <div className="modern-account-page">
40
+ <div className="modern-account-intro">
41
+ <h2 className="modern-account-intro__title">Order History</h2>
42
+ <p className="modern-account-intro__desc">View and track all your past purchase orders.</p>
43
+ </div>
44
+
45
+ <div style={{ position: "relative" }}>
46
+ <input
47
+ type="search"
48
+ value={query}
49
+ onChange={(e) => setQuery(e.target.value)}
50
+ placeholder="Search by order ID or status..."
51
+ className="modern-search-input"
52
+ />
53
+ </div>
54
+
55
+ {filtered.length === 0 ? (
56
+ <div className="modern-account-empty">
57
+ <div className="modern-account-empty__icon">
58
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" width="22" height="22">
59
+ <path strokeLinecap="round" strokeLinejoin="round" d="M16 11V7a4 4 0 00-8 0v4M5 9h14l1 12H4L5 9z" />
60
+ </svg>
61
+ </div>
62
+ <p>
63
+ {safeOrders.length === 0
64
+ ? "No orders found in your account history."
65
+ : "No orders match your search."}
66
+ </p>
67
+ {safeOrders.length === 0 ? (
68
+ <LocalizedLink href="/store" className="modern-btn modern-btn--primary">
69
+ Explore Collection
70
+ </LocalizedLink>
71
+ ) : null}
72
+ </div>
73
+ ) : (
74
+ <div style={{ display: "flex", flexDirection: "column", gap: "1rem" }}>
75
+ {filtered.map((order) => (
76
+ <ModernAccountOrderCard key={order.id} order={order} />
77
+ ))}
78
+ </div>
79
+ )}
80
+ </div>
81
+ )
82
+ }
@@ -0,0 +1,138 @@
1
+ "use client"
2
+
3
+ import type { HttpTypes } from "@medusajs/types"
4
+ import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
5
+ import { getProfileCompletion } from "./jewelry-account-utils"
6
+ import ModernAccountOrderCard from "./modern-account-order-card"
7
+
8
+ export default function ModernAccountOverview({
9
+ customer,
10
+ orders,
11
+ }: {
12
+ customer: HttpTypes.StoreCustomer
13
+ orders?: HttpTypes.StoreOrder[] | { orders?: HttpTypes.StoreOrder[] } | null
14
+ countryCode: string
15
+ }) {
16
+ const completion = getProfileCompletion(customer)
17
+ const addressCount = customer.addresses?.length ?? 0
18
+ const safeOrders: HttpTypes.StoreOrder[] = Array.isArray(orders)
19
+ ? orders
20
+ : Array.isArray((orders as { orders?: HttpTypes.StoreOrder[] })?.orders)
21
+ ? ((orders as { orders: HttpTypes.StoreOrder[] }).orders)
22
+ : []
23
+
24
+ return (
25
+ <div className="modern-account-page">
26
+ {/* Welcome Banner */}
27
+ <div className="modern-account-welcome">
28
+ <div>
29
+ <h2 className="modern-account-welcome__title">
30
+ Welcome, {customer.first_name || "Customer"}
31
+ </h2>
32
+ <p className="modern-account-welcome__meta">
33
+ Signed in as{" "}
34
+ <span className="modern-account-welcome__email">{customer.email}</span>
35
+ </p>
36
+ </div>
37
+ <LocalizedLink
38
+ href="/account/profile"
39
+ className="modern-btn modern-btn--outline"
40
+ style={{ background: "#ffffff", borderColor: "#ffffff", color: "#3e3053" }}
41
+ >
42
+ Account Details
43
+ </LocalizedLink>
44
+ </div>
45
+
46
+ {/* Quick Stats Grid */}
47
+ <div className="modern-account-stats-grid">
48
+ <LocalizedLink href="/account/profile" className="modern-account-stat-card">
49
+ <div className="modern-account-stat-card__head">
50
+ <span className="modern-account-stat-card__label">Profile Completion</span>
51
+ <div className="modern-account-stat-card__icon">
52
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8">
53
+ <path strokeLinecap="round" strokeLinejoin="round" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
54
+ </svg>
55
+ </div>
56
+ </div>
57
+ <span className="modern-account-stat-card__val">{completion}%</span>
58
+ <div className="modern-account-progress-bar">
59
+ <div
60
+ className="modern-account-progress-fill"
61
+ style={{ width: `${completion}%` }}
62
+ />
63
+ </div>
64
+ <span className="modern-account-stat-card__sub">
65
+ {completion === 100 ? "Fully completed profile" : "Complete details for faster checkout"}
66
+ </span>
67
+ </LocalizedLink>
68
+
69
+ <LocalizedLink href="/account/addresses" className="modern-account-stat-card">
70
+ <div className="modern-account-stat-card__head">
71
+ <span className="modern-account-stat-card__label">Saved Addresses</span>
72
+ <div className="modern-account-stat-card__icon">
73
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8">
74
+ <path strokeLinecap="round" strokeLinejoin="round" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
75
+ <path strokeLinecap="round" strokeLinejoin="round" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
76
+ </svg>
77
+ </div>
78
+ </div>
79
+ <span className="modern-account-stat-card__val">{addressCount}</span>
80
+ <span className="modern-account-stat-card__sub">
81
+ {addressCount === 1 ? "1 delivery address" : `${addressCount} delivery addresses`}
82
+ </span>
83
+ </LocalizedLink>
84
+
85
+ <LocalizedLink href="/account/orders" className="modern-account-stat-card">
86
+ <div className="modern-account-stat-card__head">
87
+ <span className="modern-account-stat-card__label">Total Orders</span>
88
+ <div className="modern-account-stat-card__icon">
89
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8">
90
+ <path strokeLinecap="round" strokeLinejoin="round" d="M16 11V7a4 4 0 00-8 0v4M5 9h14l1 12H4L5 9z" />
91
+ </svg>
92
+ </div>
93
+ </div>
94
+ <span className="modern-account-stat-card__val">{safeOrders.length}</span>
95
+ <span className="modern-account-stat-card__sub">
96
+ {safeOrders.length === 0 ? "No orders placed yet" : `${safeOrders.length} orders in account history`}
97
+ </span>
98
+ </LocalizedLink>
99
+ </div>
100
+
101
+ {/* Recent Orders Section */}
102
+ <div className="modern-account-card">
103
+ <div className="modern-account-sec-head" style={{ marginBottom: "1.25rem" }}>
104
+ <h3 className="modern-account-sec-title">Recent Orders</h3>
105
+ {safeOrders.length > 0 ? (
106
+ <LocalizedLink
107
+ href="/account/orders"
108
+ className="modern-btn modern-btn--ghost"
109
+ style={{ fontSize: "0.78125rem" }}
110
+ >
111
+ View All ({safeOrders.length}) →
112
+ </LocalizedLink>
113
+ ) : null}
114
+ </div>
115
+
116
+ {safeOrders.length === 0 ? (
117
+ <div className="modern-account-empty">
118
+ <div className="modern-account-empty__icon">
119
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" width="22" height="22">
120
+ <path strokeLinecap="round" strokeLinejoin="round" d="M16 11V7a4 4 0 00-8 0v4M5 9h14l1 12H4L5 9z" />
121
+ </svg>
122
+ </div>
123
+ <p>You haven't placed any orders yet.</p>
124
+ <LocalizedLink href="/store" className="modern-btn modern-btn--primary">
125
+ Explore Collection
126
+ </LocalizedLink>
127
+ </div>
128
+ ) : (
129
+ <div style={{ display: "flex", flexDirection: "column", gap: "1rem" }}>
130
+ {safeOrders.slice(0, 3).map((order) => (
131
+ <ModernAccountOrderCard key={order.id} order={order} compact={true} />
132
+ ))}
133
+ </div>
134
+ )}
135
+ </div>
136
+ </div>
137
+ )
138
+ }