@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.
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@pradip1995/segment-jewelry-account-pages",
3
+ "version": "0.1.1",
4
+ "license": "MIT",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "sideEffects": [
9
+ "./src/modern-account.css"
10
+ ],
11
+ "files": [
12
+ "src"
13
+ ],
14
+ "exports": {
15
+ ".": "./src/index.ts",
16
+ "./manifest": "./src/manifest.ts"
17
+ },
18
+ "peerDependencies": {
19
+ "@pradip1995/commerce-auth": "^4.0.0",
20
+ "@pradip1995/commerce-core": "^4.0.0",
21
+ "@pradip1995/plugin-sdk": "^0.2.0",
22
+ "next": ">=15",
23
+ "react": ">=19",
24
+ "react-dom": ">=19"
25
+ },
26
+ "dependencies": {
27
+ "@medusajs/types": "^2.8.0",
28
+ "@pradip1995/commerce-auth": "^4.0.0",
29
+ "@pradip1995/commerce-core": "^4.0.0",
30
+ "@pradip1995/segment-login-template": "^0.5.7",
31
+ "@pradip1995/segment-primitives": "^0.4.3",
32
+ "@pradip1995/segment-tokens": "^0.3.7"
33
+ },
34
+ "devDependencies": {
35
+ "@pradip1995/plugin-sdk": "^0.2.0",
36
+ "@types/react": "^19",
37
+ "next": ">=15",
38
+ "react": "19.0.3",
39
+ "typescript": "^5.7.2"
40
+ },
41
+ "scripts": {
42
+ "typecheck": "tsc --noEmit",
43
+ "lint": "tsc --noEmit"
44
+ }
45
+ }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ export { default } from "./segment"
2
+ export { default as manifest } from "./manifest"
3
+
4
+ export { default as ModernAccountOverview } from "./modern-account-overview"
5
+ export { default as ModernAccountProfile } from "./modern-account-profile"
6
+ export { default as ModernAccountAddresses } from "./modern-account-addresses"
7
+ export { default as ModernAccountOrders } from "./modern-account-orders"
8
+ export { default as ModernAccountPaymentMethods } from "./modern-account-payment-methods"
9
+ export { default as ModernAccountOrderCard } from "./modern-account-order-card"
@@ -0,0 +1,76 @@
1
+ "use client"
2
+
3
+ import type { HttpTypes } from "@medusajs/types"
4
+ import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
5
+ import { logoutGuest } from "@pradip1995/commerce-core/data/guest"
6
+ import ModernAccountOrderCard from "./modern-account-order-card"
7
+
8
+ export default function JewelryAccountGuestOrders({
9
+ orders,
10
+ countryCode,
11
+ }: {
12
+ orders?: HttpTypes.StoreOrder[] | { orders?: HttpTypes.StoreOrder[] } | null
13
+ countryCode: string
14
+ }) {
15
+ const safeOrders: HttpTypes.StoreOrder[] = Array.isArray(orders)
16
+ ? orders
17
+ : Array.isArray((orders as { orders?: HttpTypes.StoreOrder[] })?.orders)
18
+ ? ((orders as { orders: HttpTypes.StoreOrder[] }).orders)
19
+ : []
20
+
21
+ async function handleSignOut() {
22
+ await logoutGuest()
23
+ window.location.href = `/${countryCode}/account`
24
+ }
25
+
26
+ async function handleCheckDifferent() {
27
+ await logoutGuest()
28
+ window.location.href = `/${countryCode}/account?view=guest`
29
+ }
30
+
31
+ return (
32
+ <div className="jewelry-account-page">
33
+ <div className="jewelry-account-page__header">
34
+ <div>
35
+ <h2 className="jewelry-account-hello__title">Guest orders</h2>
36
+ <p className="jewelry-account-page__lede">
37
+ Track orders linked to your verified email.
38
+ </p>
39
+ </div>
40
+ <div className="jewelry-account-actions">
41
+ <button
42
+ type="button"
43
+ onClick={handleCheckDifferent}
44
+ className="jewelry-account-btn jewelry-account-btn--outline"
45
+ >
46
+ Check different email
47
+ </button>
48
+ <button
49
+ type="button"
50
+ onClick={handleSignOut}
51
+ className="jewelry-account-btn jewelry-account-btn--outline"
52
+ >
53
+ End guest session
54
+ </button>
55
+ </div>
56
+ </div>
57
+
58
+ {safeOrders.length === 0 ? (
59
+ <div className="jewelry-account-empty">
60
+ <p>No guest orders found for this session.</p>
61
+ <LocalizedLink href="/store" className="jewelry-account-btn jewelry-account-btn--primary">
62
+ Continue shopping
63
+ </LocalizedLink>
64
+ </div>
65
+ ) : (
66
+ <ul className="jewelry-account-list">
67
+ {safeOrders.map((order) => (
68
+ <li key={order.id}>
69
+ <ModernAccountOrderCard order={order} />
70
+ </li>
71
+ ))}
72
+ </ul>
73
+ )}
74
+ </div>
75
+ )
76
+ }
@@ -0,0 +1,19 @@
1
+ export function getProfileCompletion(customer: {
2
+ first_name?: string | null
3
+ last_name?: string | null
4
+ email?: string | null
5
+ phone?: string | null
6
+ }): number {
7
+ let score = 0
8
+ if (customer.first_name?.trim()) score += 25
9
+ if (customer.last_name?.trim()) score += 25
10
+ if (customer.email?.trim()) score += 25
11
+ if (customer.phone?.trim()) score += 25
12
+ return score
13
+ }
14
+
15
+ export function accountSectionPath(path?: string): string {
16
+ if (!path || path === "login") return "overview"
17
+ const base = path.split("/")[0]
18
+ return base || "overview"
19
+ }
@@ -0,0 +1,9 @@
1
+ import type { SegmentManifest } from "@pradip1995/plugin-sdk"
2
+
3
+ export const manifest: SegmentManifest = {
4
+ id: "segment-jewelry-account-pages",
5
+ name: "Jewelry Account Pages",
6
+ description: "Account overview, profile, addresses, orders, and payment methods for jewelry storefront",
7
+ }
8
+
9
+ export default manifest
@@ -0,0 +1,503 @@
1
+ "use client"
2
+
3
+ import { useActionState, useEffect, useState, type ReactNode } from "react"
4
+ import type { HttpTypes } from "@medusajs/types"
5
+ import {
6
+ addCustomerAddress,
7
+ deleteCustomerAddress,
8
+ setDefaultAddress,
9
+ updateCustomerAddress,
10
+ } from "@pradip1995/commerce-core/data/customer"
11
+
12
+ export default function ModernAccountAddresses({
13
+ customer,
14
+ countryCode,
15
+ }: {
16
+ customer: HttpTypes.StoreCustomer
17
+ countryCode: string
18
+ }) {
19
+ const addresses = customer.addresses ?? []
20
+ const [editingId, setEditingId] = useState<string | null>(null)
21
+ const [showAdd, setShowAdd] = useState(false)
22
+ const hasDefault = addresses.some((a) => a.is_default_shipping || a.is_default_billing)
23
+ const editingAddress = addresses.find((address) => address.id === editingId)
24
+
25
+ return (
26
+ <div className="modern-account-page">
27
+ <div style={{ marginBottom: "0.5rem" }}>
28
+ <h2
29
+ style={{
30
+ margin: 0,
31
+ fontFamily: "var(--font-heading, 'Cormorant Garamond', Georgia, serif)",
32
+ fontSize: "1.2rem",
33
+ fontWeight: 600,
34
+ letterSpacing: "0.08em",
35
+ textTransform: "uppercase",
36
+ color: "var(--lux-onyx)",
37
+ }}
38
+ >
39
+ Shipping Addresses
40
+ </h2>
41
+ </div>
42
+
43
+ {addresses.length === 0 ? (
44
+ <div className="modern-account-empty">
45
+ <div className="modern-account-empty__icon">
46
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" width="22" height="22">
47
+ <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" />
48
+ <path strokeLinecap="round" strokeLinejoin="round" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
49
+ </svg>
50
+ </div>
51
+ <p>No saved delivery addresses found.</p>
52
+ </div>
53
+ ) : null}
54
+
55
+ <div style={{ display: "flex", flexDirection: "column", gap: "1.25rem" }}>
56
+ {addresses.map((address) => {
57
+ const isDefault = address.is_default_shipping || address.is_default_billing
58
+ const name = [address.first_name, address.last_name].filter(Boolean).join(" ")
59
+ return (
60
+ <div
61
+ key={address.id}
62
+ className="modern-account-card"
63
+ style={{
64
+ padding: "1.5rem 1.75rem",
65
+ borderRadius: "0.85rem",
66
+ display: "flex",
67
+ flexDirection: "column",
68
+ gap: "1rem",
69
+ }}
70
+ >
71
+ {/* Header Row: Name & Badges */}
72
+ <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
73
+ <h3
74
+ style={{
75
+ margin: 0,
76
+ fontFamily: "var(--font-heading, 'Cormorant Garamond', Georgia, serif)",
77
+ fontSize: "1.15rem",
78
+ fontWeight: 600,
79
+ color: "var(--lux-onyx)",
80
+ }}
81
+ >
82
+ {name || "Customer"}
83
+ </h3>
84
+ <div style={{ display: "flex", gap: "0.5rem", alignItems: "center" }}>
85
+ {isDefault ? (
86
+ <span
87
+ style={{
88
+ padding: "0.2rem 0.65rem",
89
+ borderRadius: "999px",
90
+ fontSize: "0.625rem",
91
+ fontWeight: 700,
92
+ letterSpacing: "0.1em",
93
+ textTransform: "uppercase",
94
+ backgroundColor: "#3e3053",
95
+ color: "#ffffff",
96
+ }}
97
+ >
98
+ DEFAULT
99
+ </span>
100
+ ) : null}
101
+ <span
102
+ style={{
103
+ padding: "0.2rem 0.65rem",
104
+ borderRadius: "999px",
105
+ fontSize: "0.625rem",
106
+ fontWeight: 700,
107
+ letterSpacing: "0.1em",
108
+ textTransform: "uppercase",
109
+ backgroundColor: "#faf8f5",
110
+ border: "1px solid var(--lux-border)",
111
+ color: "var(--lux-onyx)",
112
+ }}
113
+ >
114
+ HOME
115
+ </span>
116
+ </div>
117
+ </div>
118
+
119
+ {/* Address Details */}
120
+ <div style={{ fontSize: "0.875rem", lineHeight: 1.6, color: "#4a4a4a" }}>
121
+ <p style={{ margin: 0 }}>{address.address_1}</p>
122
+ {address.address_2 ? <p style={{ margin: 0 }}>{address.address_2}</p> : null}
123
+ <p style={{ margin: 0 }}>
124
+ {[address.city, address.province, address.postal_code]
125
+ .filter(Boolean)
126
+ .join(", ")}
127
+ </p>
128
+ </div>
129
+
130
+ <div style={{ borderTop: "1px solid rgba(24, 20, 29, 0.08)", paddingTop: "0.85rem" }}>
131
+ {address.phone ? (
132
+ <p style={{ margin: 0, fontSize: "0.8125rem", color: "var(--lux-onyx)" }}>
133
+ <strong style={{ fontSize: "0.6875rem", letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--lux-muted)", marginRight: "0.5rem" }}>
134
+ MOBILE
135
+ </strong>
136
+ {address.phone}
137
+ </p>
138
+ ) : null}
139
+
140
+ {/* Actions Row */}
141
+ <div style={{ display: "flex", gap: "0.65rem", marginTop: "1rem", flexWrap: "wrap" }}>
142
+ <button
143
+ type="button"
144
+ onClick={() => {
145
+ setShowAdd(false)
146
+ setEditingId(address.id!)
147
+ }}
148
+ style={{
149
+ padding: "0.45rem 1.25rem",
150
+ borderRadius: "999px",
151
+ fontSize: "0.72rem",
152
+ fontWeight: 700,
153
+ letterSpacing: "0.08em",
154
+ textTransform: "uppercase",
155
+ backgroundColor: "#3e3053",
156
+ color: "#ffffff",
157
+ border: "none",
158
+ cursor: "pointer",
159
+ }}
160
+ >
161
+ EDIT
162
+ </button>
163
+
164
+ {!isDefault ? (
165
+ <MakeDefaultButton addressId={address.id!} />
166
+ ) : null}
167
+
168
+ <DeleteAddressButton addressId={address.id!} />
169
+ </div>
170
+ </div>
171
+ </div>
172
+ )
173
+ })}
174
+ </div>
175
+
176
+ {/* Add New Address Button */}
177
+ <div style={{ marginTop: "1rem" }}>
178
+ <button
179
+ type="button"
180
+ onClick={() => {
181
+ setEditingId(null)
182
+ setShowAdd(true)
183
+ }}
184
+ style={{
185
+ width: "100%",
186
+ padding: "0.85rem",
187
+ borderRadius: "0.65rem",
188
+ fontSize: "0.78125rem",
189
+ fontWeight: 700,
190
+ letterSpacing: "0.1em",
191
+ textTransform: "uppercase",
192
+ backgroundColor: "#ffffff",
193
+ color: "var(--lux-onyx)",
194
+ border: "2px solid var(--lux-onyx)",
195
+ cursor: "pointer",
196
+ display: "flex",
197
+ alignItems: "center",
198
+ justifyContent: "center",
199
+ gap: "0.5rem",
200
+ transition: "all 0.18s ease",
201
+ }}
202
+ >
203
+ <span>+</span>
204
+ <span>ADD NEW ADDRESS</span>
205
+ </button>
206
+ </div>
207
+
208
+ {showAdd ? (
209
+ <AddressModal title="Add New Address" onClose={() => setShowAdd(false)}>
210
+ <AddressForm
211
+ countryCode={countryCode}
212
+ defaultChecked={addresses.length === 0 || !hasDefault}
213
+ onDone={() => setShowAdd(false)}
214
+ onCancel={() => setShowAdd(false)}
215
+ />
216
+ </AddressModal>
217
+ ) : null}
218
+
219
+ {editingAddress ? (
220
+ <AddressModal title="Edit Address" onClose={() => setEditingId(null)}>
221
+ <AddressForm
222
+ countryCode={countryCode}
223
+ address={editingAddress}
224
+ addressId={editingAddress.id}
225
+ defaultChecked={
226
+ !!(editingAddress.is_default_shipping || editingAddress.is_default_billing)
227
+ }
228
+ onDone={() => setEditingId(null)}
229
+ onCancel={() => setEditingId(null)}
230
+ />
231
+ </AddressModal>
232
+ ) : null}
233
+ </div>
234
+ )
235
+ }
236
+
237
+ function AddressModal({
238
+ title,
239
+ onClose,
240
+ children,
241
+ }: {
242
+ title: string
243
+ onClose: () => void
244
+ children: ReactNode
245
+ }) {
246
+ useEffect(() => {
247
+ const previous = document.body.style.overflow
248
+ document.body.style.overflow = "hidden"
249
+
250
+ function onKey(event: KeyboardEvent) {
251
+ if (event.key === "Escape") onClose()
252
+ }
253
+
254
+ window.addEventListener("keydown", onKey)
255
+ return () => {
256
+ document.body.style.overflow = previous
257
+ window.removeEventListener("keydown", onKey)
258
+ }
259
+ }, [onClose])
260
+
261
+ return (
262
+ <div className="modern-modal-backdrop" role="dialog" aria-modal="true" aria-label={title}>
263
+ <div className="modern-modal-panel">
264
+ <div className="modern-modal-head">
265
+ <h3 className="modern-modal-title">{title}</h3>
266
+ <button
267
+ type="button"
268
+ className="modern-btn modern-btn--ghost"
269
+ style={{ padding: "0.2rem 0.5rem" }}
270
+ aria-label="Close"
271
+ onClick={onClose}
272
+ >
273
+ ✕
274
+ </button>
275
+ </div>
276
+ {children}
277
+ </div>
278
+ </div>
279
+ )
280
+ }
281
+
282
+ function AddressForm({
283
+ countryCode,
284
+ address,
285
+ addressId,
286
+ defaultChecked = false,
287
+ onDone,
288
+ onCancel,
289
+ }: {
290
+ countryCode: string
291
+ address?: HttpTypes.StoreCustomerAddress
292
+ addressId?: string
293
+ defaultChecked?: boolean
294
+ onDone: () => void
295
+ onCancel: () => void
296
+ }) {
297
+ const action = addressId ? updateCustomerAddress : addCustomerAddress
298
+ const [state, formAction, pending] = useActionState(
299
+ async (prev: Record<string, unknown>, formData: FormData) => {
300
+ const makeDefault = formData.get("is_default") === "on"
301
+ const result = await action(
302
+ addressId
303
+ ? { ...prev, addressId }
304
+ : {
305
+ ...prev,
306
+ isDefaultShipping: makeDefault,
307
+ isDefaultBilling: makeDefault,
308
+ },
309
+ formData
310
+ )
311
+ if (result?.success) {
312
+ if (addressId && makeDefault && !address?.is_default_shipping) {
313
+ const defaultResult = await setDefaultAddress(addressId)
314
+ if (!defaultResult?.success) {
315
+ return {
316
+ success: false,
317
+ error: defaultResult?.error || "Failed to set default address",
318
+ }
319
+ }
320
+ }
321
+ onDone()
322
+ window.location.reload()
323
+ }
324
+ return result
325
+ },
326
+ { success: false, error: null as string | null }
327
+ )
328
+
329
+ return (
330
+ <form action={formAction} className="modern-form modern-form-grid-2">
331
+ <Field label="First Name" name="first_name" defaultValue={address?.first_name || ""} />
332
+ <Field label="Last Name" name="last_name" defaultValue={address?.last_name || ""} />
333
+ <Field
334
+ label="Address Line 1"
335
+ name="address_1"
336
+ className="modern-field--full"
337
+ defaultValue={address?.address_1 || ""}
338
+ />
339
+ <Field
340
+ label="Address Line 2 (Optional)"
341
+ name="address_2"
342
+ className="modern-field--full"
343
+ defaultValue={address?.address_2 || ""}
344
+ />
345
+ <Field label="City" name="city" defaultValue={address?.city || ""} />
346
+ <Field label="State / Province" name="province" defaultValue={address?.province || ""} />
347
+ <Field label="Postal Code" name="postal_code" defaultValue={address?.postal_code || ""} />
348
+ <Field
349
+ label="Country Code"
350
+ name="country_code"
351
+ defaultValue={address?.country_code || countryCode}
352
+ />
353
+ <Field label="Phone" name="phone" type="tel" defaultValue={address?.phone || ""} />
354
+
355
+ <div className="modern-field--full">
356
+ <label style={{ display: "flex", alignItems: "center", gap: "0.5rem", fontSize: "0.8125rem", cursor: "pointer" }}>
357
+ <input
358
+ type="checkbox"
359
+ name="is_default"
360
+ defaultChecked={defaultChecked}
361
+ style={{ width: "1rem", height: "1rem", accentColor: "var(--lux-plum)" }}
362
+ />
363
+ <span>Set as default delivery address</span>
364
+ </label>
365
+ </div>
366
+
367
+ {state?.error ? (
368
+ <div className="modern-field--full" style={{ color: "#dc2626", fontSize: "0.8125rem" }}>
369
+ {String(state.error)}
370
+ </div>
371
+ ) : null}
372
+
373
+ <div className="modern-field--full" style={{ display: "flex", gap: "0.75rem", marginTop: "0.5rem" }}>
374
+ <button
375
+ type="submit"
376
+ disabled={pending}
377
+ className="modern-btn modern-btn--primary"
378
+ >
379
+ {pending ? "Saving…" : "Save Address"}
380
+ </button>
381
+ <button
382
+ type="button"
383
+ onClick={onCancel}
384
+ className="modern-btn modern-btn--outline"
385
+ >
386
+ Cancel
387
+ </button>
388
+ </div>
389
+ </form>
390
+ )
391
+ }
392
+
393
+ function MakeDefaultButton({ addressId }: { addressId: string }) {
394
+ const [pending, setPending] = useState(false)
395
+ const [error, setError] = useState<string | null>(null)
396
+
397
+ async function handleDefault() {
398
+ setPending(true)
399
+ setError(null)
400
+ try {
401
+ const result = await setDefaultAddress(addressId)
402
+ if (!result?.success) {
403
+ setError(result?.error || "Failed to set default address")
404
+ setPending(false)
405
+ return
406
+ }
407
+ window.location.reload()
408
+ } catch (err) {
409
+ setError(err instanceof Error ? err.message : "Failed to set default address")
410
+ setPending(false)
411
+ }
412
+ }
413
+
414
+ return (
415
+ <div style={{ display: "inline-block" }}>
416
+ <button
417
+ type="button"
418
+ onClick={handleDefault}
419
+ disabled={pending}
420
+ style={{
421
+ padding: "0.45rem 1.25rem",
422
+ borderRadius: "999px",
423
+ fontSize: "0.72rem",
424
+ fontWeight: 700,
425
+ letterSpacing: "0.08em",
426
+ textTransform: "uppercase",
427
+ backgroundColor: "#ffffff",
428
+ color: "var(--lux-onyx)",
429
+ border: "1px solid var(--lux-onyx)",
430
+ cursor: "pointer",
431
+ }}
432
+ >
433
+ {pending ? "SETTING…" : "SET AS DEFAULT"}
434
+ </button>
435
+ {error ? <p style={{ color: "#dc2626", fontSize: "0.75rem", margin: "0.2rem 0 0" }}>{error}</p> : null}
436
+ </div>
437
+ )
438
+ }
439
+
440
+ function DeleteAddressButton({ addressId }: { addressId: string }) {
441
+ const [pending, setPending] = useState(false)
442
+
443
+ async function handleDelete() {
444
+ if (!confirm("Are you sure you want to remove this address?")) return
445
+ setPending(true)
446
+ try {
447
+ await deleteCustomerAddress(addressId)
448
+ window.location.reload()
449
+ } finally {
450
+ setPending(false)
451
+ }
452
+ }
453
+
454
+ return (
455
+ <button
456
+ type="button"
457
+ onClick={handleDelete}
458
+ disabled={pending}
459
+ style={{
460
+ padding: "0.45rem 1.25rem",
461
+ borderRadius: "999px",
462
+ fontSize: "0.72rem",
463
+ fontWeight: 700,
464
+ letterSpacing: "0.08em",
465
+ textTransform: "uppercase",
466
+ backgroundColor: "#ffffff",
467
+ color: "#dc2626",
468
+ border: "1px solid #dc2626",
469
+ cursor: "pointer",
470
+ }}
471
+ aria-label="Remove address"
472
+ >
473
+ {pending ? "…" : "REMOVE"}
474
+ </button>
475
+ )
476
+ }
477
+
478
+ function Field({
479
+ label,
480
+ name,
481
+ type = "text",
482
+ defaultValue,
483
+ className = "",
484
+ }: {
485
+ label: string
486
+ name: string
487
+ type?: string
488
+ defaultValue?: string
489
+ className?: string
490
+ }) {
491
+ return (
492
+ <div className={`modern-field ${className}`.trim()}>
493
+ <label className="modern-field__label">{label}</label>
494
+ <input
495
+ name={name}
496
+ type={type}
497
+ defaultValue={defaultValue}
498
+ required={name !== "address_2"}
499
+ className="modern-field__input"
500
+ />
501
+ </div>
502
+ )
503
+ }