@pradip1995/segment-animation-login 0.1.2 → 0.1.3
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 +8 -8
- package/src/account-addresses.tsx +112 -20
- package/src/account-orders.tsx +1 -3
- package/src/account-overview.tsx +76 -18
- package/src/animation-account.css +94 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pradip1995/segment-animation-login",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Motion/Lumière OTP login and account shell",
|
|
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
|
"@pradip1995/commerce-auth": "^4.0.0",
|
|
25
21
|
"@pradip1995/commerce-core": "^4.0.0",
|
|
@@ -31,8 +27,8 @@
|
|
|
31
27
|
"dependencies": {
|
|
32
28
|
"@medusajs/types": "^2.8.0",
|
|
33
29
|
"@pradip1995/commerce-core": "^4.0.0",
|
|
34
|
-
"@pradip1995/segment-login-template": "^0.5.
|
|
35
|
-
"@pradip1995/segment-primitives": "^0.4.
|
|
30
|
+
"@pradip1995/segment-login-template": "^0.5.7",
|
|
31
|
+
"@pradip1995/segment-primitives": "^0.4.3",
|
|
36
32
|
"framer-motion": "^11.0.0"
|
|
37
33
|
},
|
|
38
34
|
"devDependencies": {
|
|
@@ -41,5 +37,9 @@
|
|
|
41
37
|
"next": ">=15",
|
|
42
38
|
"react": "19.0.3",
|
|
43
39
|
"typescript": "^5.7.2"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"lint": "tsc --noEmit"
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import { useActionState, useEffect, useState, type ReactNode } from "react"
|
|
3
|
+
import { useActionState, useEffect, useId, useState, type ReactNode } from "react"
|
|
4
|
+
import { createPortal } from "react-dom"
|
|
4
5
|
import type { HttpTypes } from "@medusajs/types"
|
|
5
6
|
import {
|
|
6
7
|
addCustomerAddress,
|
|
@@ -324,43 +325,134 @@ function DeleteAddressButton({
|
|
|
324
325
|
iconOnly?: boolean
|
|
325
326
|
}) {
|
|
326
327
|
const [pending, setPending] = useState(false)
|
|
328
|
+
const [open, setOpen] = useState(false)
|
|
329
|
+
const [mounted, setMounted] = useState(false)
|
|
330
|
+
const [error, setError] = useState<string | null>(null)
|
|
331
|
+
const titleId = useId()
|
|
332
|
+
|
|
333
|
+
useEffect(() => {
|
|
334
|
+
setMounted(true)
|
|
335
|
+
}, [])
|
|
336
|
+
|
|
337
|
+
useEffect(() => {
|
|
338
|
+
if (!open) return
|
|
339
|
+
const previous = document.body.style.overflow
|
|
340
|
+
document.body.style.overflow = "hidden"
|
|
341
|
+
function onKey(event: KeyboardEvent) {
|
|
342
|
+
if (event.key === "Escape" && !pending) setOpen(false)
|
|
343
|
+
}
|
|
344
|
+
window.addEventListener("keydown", onKey)
|
|
345
|
+
return () => {
|
|
346
|
+
document.body.style.overflow = previous
|
|
347
|
+
window.removeEventListener("keydown", onKey)
|
|
348
|
+
}
|
|
349
|
+
}, [open, pending])
|
|
327
350
|
|
|
328
351
|
async function handleDelete() {
|
|
329
|
-
if (!confirm("Delete this address?")) return
|
|
330
352
|
setPending(true)
|
|
353
|
+
setError(null)
|
|
331
354
|
try {
|
|
332
355
|
await deleteCustomerAddress(addressId)
|
|
356
|
+
setOpen(false)
|
|
333
357
|
window.location.reload()
|
|
334
|
-
}
|
|
358
|
+
} catch (err) {
|
|
359
|
+
setError(err instanceof Error ? err.message : "Failed to delete address")
|
|
335
360
|
setPending(false)
|
|
336
361
|
}
|
|
337
362
|
}
|
|
338
363
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
return (
|
|
364
|
+
const trigger = iconOnly ? (
|
|
365
|
+
<button
|
|
366
|
+
type="button"
|
|
367
|
+
onClick={() => {
|
|
368
|
+
setError(null)
|
|
369
|
+
setOpen(true)
|
|
370
|
+
}}
|
|
371
|
+
disabled={pending}
|
|
372
|
+
className="anim-acct__icon-btn anim-acct__icon-btn--danger"
|
|
373
|
+
aria-label={pending ? "Deleting address" : "Delete address"}
|
|
374
|
+
title="Delete"
|
|
375
|
+
>
|
|
376
|
+
<DeleteIcon />
|
|
377
|
+
</button>
|
|
378
|
+
) : (
|
|
355
379
|
<button
|
|
356
380
|
type="button"
|
|
357
|
-
onClick={
|
|
381
|
+
onClick={() => {
|
|
382
|
+
setError(null)
|
|
383
|
+
setOpen(true)
|
|
384
|
+
}}
|
|
358
385
|
disabled={pending}
|
|
359
386
|
className="anim-acct__text-action anim-acct__text-action--danger"
|
|
360
387
|
>
|
|
361
388
|
{pending ? "Deleting…" : "Delete"}
|
|
362
389
|
</button>
|
|
363
390
|
)
|
|
391
|
+
|
|
392
|
+
return (
|
|
393
|
+
<>
|
|
394
|
+
{trigger}
|
|
395
|
+
{mounted && open
|
|
396
|
+
? createPortal(
|
|
397
|
+
<div
|
|
398
|
+
className="anim-acct-modal"
|
|
399
|
+
role="dialog"
|
|
400
|
+
aria-modal="true"
|
|
401
|
+
aria-labelledby={titleId}
|
|
402
|
+
>
|
|
403
|
+
<button
|
|
404
|
+
type="button"
|
|
405
|
+
className="anim-acct-modal__backdrop"
|
|
406
|
+
aria-label="Close delete confirmation"
|
|
407
|
+
disabled={pending}
|
|
408
|
+
onClick={() => {
|
|
409
|
+
if (!pending) setOpen(false)
|
|
410
|
+
}}
|
|
411
|
+
/>
|
|
412
|
+
<div className="anim-acct-modal__panel" style={{ maxWidth: "28rem" }}>
|
|
413
|
+
<div className="anim-acct-modal__head">
|
|
414
|
+
<h3 id={titleId}>Delete this address?</h3>
|
|
415
|
+
<button
|
|
416
|
+
type="button"
|
|
417
|
+
className="anim-acct-modal__close"
|
|
418
|
+
aria-label="Close"
|
|
419
|
+
disabled={pending}
|
|
420
|
+
onClick={() => setOpen(false)}
|
|
421
|
+
>
|
|
422
|
+
×
|
|
423
|
+
</button>
|
|
424
|
+
</div>
|
|
425
|
+
<div className="anim-acct-modal__body">
|
|
426
|
+
<p>
|
|
427
|
+
This address will be removed from your account. You can always add it again later.
|
|
428
|
+
</p>
|
|
429
|
+
{error ? <p className="anim-acct-form__error">{error}</p> : null}
|
|
430
|
+
<div className="anim-acct-modal__actions">
|
|
431
|
+
<button
|
|
432
|
+
type="button"
|
|
433
|
+
disabled={pending}
|
|
434
|
+
onClick={() => setOpen(false)}
|
|
435
|
+
className="anim-acct__btn anim-acct__btn--outline"
|
|
436
|
+
>
|
|
437
|
+
Keep address
|
|
438
|
+
</button>
|
|
439
|
+
<button
|
|
440
|
+
type="button"
|
|
441
|
+
disabled={pending}
|
|
442
|
+
onClick={handleDelete}
|
|
443
|
+
className="anim-acct__btn anim-acct__btn--danger"
|
|
444
|
+
>
|
|
445
|
+
{pending ? "Deleting…" : "Yes, delete"}
|
|
446
|
+
</button>
|
|
447
|
+
</div>
|
|
448
|
+
</div>
|
|
449
|
+
</div>
|
|
450
|
+
</div>,
|
|
451
|
+
document.body
|
|
452
|
+
)
|
|
453
|
+
: null}
|
|
454
|
+
</>
|
|
455
|
+
)
|
|
364
456
|
}
|
|
365
457
|
|
|
366
458
|
function EditIcon() {
|
package/src/account-orders.tsx
CHANGED
|
@@ -7,7 +7,6 @@ import type { HttpTypes } from "@medusajs/types"
|
|
|
7
7
|
import { addToCart } from "@pradip1995/commerce-core/client/actions/cart"
|
|
8
8
|
import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
|
|
9
9
|
import { formatPrice } from "@pradip1995/segment-primitives/format-price"
|
|
10
|
-
import { presentOrderLines } from "@pradip1995/segment-primitives/order-lines"
|
|
11
10
|
|
|
12
11
|
function isCancelled(order: HttpTypes.StoreOrder) {
|
|
13
12
|
const status = (order.status || "").toLowerCase()
|
|
@@ -106,8 +105,7 @@ export default function AnimationAccountOrders({
|
|
|
106
105
|
if (!canReorder(order) || reorderingId) return
|
|
107
106
|
setReorderingId(order.id)
|
|
108
107
|
try {
|
|
109
|
-
const
|
|
110
|
-
for (const item of reorderItems) {
|
|
108
|
+
for (const item of order.items || []) {
|
|
111
109
|
if (!item.variant_id) continue
|
|
112
110
|
await addToCart({
|
|
113
111
|
variantId: item.variant_id,
|
package/src/account-overview.tsx
CHANGED
|
@@ -23,6 +23,42 @@ function safeOrdersList(
|
|
|
23
23
|
return []
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function prettyStatus(value?: string | null) {
|
|
27
|
+
if (!value) return "—"
|
|
28
|
+
return value.replace(/_/g, " ")
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isCancelled(order: HttpTypes.StoreOrder) {
|
|
32
|
+
const status = (order.status || "").toLowerCase()
|
|
33
|
+
return status === "canceled" || status === "cancelled"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function fulfillmentTone(order: HttpTypes.StoreOrder): "ok" | "warn" | "bad" | "info" {
|
|
37
|
+
if (isCancelled(order)) return "bad"
|
|
38
|
+
const s = (order.fulfillment_status || order.status || "").toLowerCase()
|
|
39
|
+
if (s === "delivered" || s === "complete" || s === "completed") return "ok"
|
|
40
|
+
if (s.includes("ship") || s.includes("fulfill")) return "info"
|
|
41
|
+
if (s.includes("not") || s.includes("pending") || s.includes("unfulfill")) return "warn"
|
|
42
|
+
return "info"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function paymentTone(status?: string | null): "ok" | "warn" | "bad" | "info" {
|
|
46
|
+
const s = (status || "").toLowerCase()
|
|
47
|
+
if (s === "captured" || s === "paid") return "ok"
|
|
48
|
+
if (s.includes("refund")) return "info"
|
|
49
|
+
if (s.includes("cancel") || s.includes("fail")) return "bad"
|
|
50
|
+
return "warn"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function itemLabel(order: HttpTypes.StoreOrder): string {
|
|
54
|
+
const items = order.items || []
|
|
55
|
+
if (items.length === 0) return "No items"
|
|
56
|
+
const first =
|
|
57
|
+
items[0]?.product_title || items[0]?.title || "Product"
|
|
58
|
+
if (items.length === 1) return first
|
|
59
|
+
return `${first} +${items.length - 1} more`
|
|
60
|
+
}
|
|
61
|
+
|
|
26
62
|
export default function AnimationAccountOverview({
|
|
27
63
|
customer,
|
|
28
64
|
orders,
|
|
@@ -91,24 +127,46 @@ export default function AnimationAccountOverview({
|
|
|
91
127
|
</LocalizedLink>
|
|
92
128
|
</div>
|
|
93
129
|
) : (
|
|
94
|
-
<ul className="anim-acct__orders">
|
|
95
|
-
{ordersList.slice(0, 5).map((order) =>
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
130
|
+
<ul className="anim-acct__orders anim-acct__orders--detailed">
|
|
131
|
+
{ordersList.slice(0, 5).map((order) => {
|
|
132
|
+
const fulfillment = prettyStatus(order.fulfillment_status || order.status)
|
|
133
|
+
const payment = prettyStatus(order.payment_status)
|
|
134
|
+
const items = order.items || []
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<li key={order.id}>
|
|
138
|
+
<LocalizedLink href={`/orders/${order.id}`} className="anim-acct__order anim-acct__order--detailed">
|
|
139
|
+
<div className="anim-acct__order-main">
|
|
140
|
+
<div className="anim-acct__order-id-row">
|
|
141
|
+
<span className="anim-acct__order-id">#{order.display_id}</span>
|
|
142
|
+
<span className={`anim-acct__status anim-acct__status--${fulfillmentTone(order)}`}>
|
|
143
|
+
{fulfillment}
|
|
144
|
+
</span>
|
|
145
|
+
</div>
|
|
146
|
+
<span className="anim-acct__order-date">
|
|
147
|
+
{order.created_at
|
|
148
|
+
? new Date(order.created_at).toLocaleDateString("en-IN", {
|
|
149
|
+
day: "numeric",
|
|
150
|
+
month: "short",
|
|
151
|
+
year: "numeric",
|
|
152
|
+
})
|
|
153
|
+
: "—"}
|
|
154
|
+
{" · "}
|
|
155
|
+
{items.length} item{items.length === 1 ? "" : "s"}
|
|
156
|
+
</span>
|
|
157
|
+
<span className="anim-acct__order-items-preview">{itemLabel(order)}</span>
|
|
158
|
+
<span className={`anim-acct__status anim-acct__status--${paymentTone(order.payment_status)} anim-acct__status--payment`}>
|
|
159
|
+
Payment: {payment}
|
|
160
|
+
</span>
|
|
161
|
+
</div>
|
|
162
|
+
<div className="anim-acct__order-side">
|
|
163
|
+
<strong>{formatPrice(order.total, order.currency_code)}</strong>
|
|
164
|
+
<span className="anim-acct__order-view">View →</span>
|
|
165
|
+
</div>
|
|
166
|
+
</LocalizedLink>
|
|
167
|
+
</li>
|
|
168
|
+
)
|
|
169
|
+
})}
|
|
112
170
|
</ul>
|
|
113
171
|
)}
|
|
114
172
|
</section>
|
|
@@ -206,6 +206,100 @@
|
|
|
206
206
|
color: var(--aa-ink);
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
.anim-acct__orders--detailed .anim-acct__order--detailed {
|
|
210
|
+
align-items: flex-start;
|
|
211
|
+
gap: 1.25rem;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.anim-acct__order-main {
|
|
215
|
+
display: flex;
|
|
216
|
+
flex-direction: column;
|
|
217
|
+
gap: 0.35rem;
|
|
218
|
+
min-width: 0;
|
|
219
|
+
flex: 1;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.anim-acct__order-id-row {
|
|
223
|
+
display: flex;
|
|
224
|
+
flex-wrap: wrap;
|
|
225
|
+
align-items: center;
|
|
226
|
+
gap: 0.5rem;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.anim-acct__order-items-preview {
|
|
230
|
+
display: block;
|
|
231
|
+
font-size: 0.8125rem;
|
|
232
|
+
color: var(--aa-ink);
|
|
233
|
+
overflow: hidden;
|
|
234
|
+
text-overflow: ellipsis;
|
|
235
|
+
white-space: nowrap;
|
|
236
|
+
max-width: 100%;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.anim-acct__status--payment {
|
|
240
|
+
width: fit-content;
|
|
241
|
+
margin-top: 0.15rem;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.anim-acct__order-side {
|
|
245
|
+
display: flex;
|
|
246
|
+
flex-direction: column;
|
|
247
|
+
align-items: flex-end;
|
|
248
|
+
gap: 0.35rem;
|
|
249
|
+
flex-shrink: 0;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.anim-acct__order-view {
|
|
253
|
+
font-size: 0.6875rem;
|
|
254
|
+
font-weight: 600;
|
|
255
|
+
letter-spacing: 0.1em;
|
|
256
|
+
text-transform: uppercase;
|
|
257
|
+
color: var(--aa-accent, #e23b00);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.anim-acct__order--detailed:hover .anim-acct__order-view {
|
|
261
|
+
text-decoration: underline;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.anim-acct-modal__actions {
|
|
265
|
+
display: flex;
|
|
266
|
+
flex-wrap: wrap;
|
|
267
|
+
gap: 0.75rem;
|
|
268
|
+
margin-top: 1.25rem;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
.anim-acct-modal__actions .anim-acct__btn {
|
|
272
|
+
flex: 1;
|
|
273
|
+
min-width: 8rem;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.anim-acct-modal__body > p {
|
|
277
|
+
margin: 0;
|
|
278
|
+
font-size: 0.9375rem;
|
|
279
|
+
line-height: 1.55;
|
|
280
|
+
color: var(--aa-muted);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.anim-acct-modal__body > p strong {
|
|
284
|
+
color: var(--aa-ink);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
.anim-acct__btn--danger {
|
|
288
|
+
background: #be123c;
|
|
289
|
+
color: #ffffff;
|
|
290
|
+
border: 1px solid #be123c;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.anim-acct__btn--danger:hover:not(:disabled) {
|
|
294
|
+
background: #9f1239;
|
|
295
|
+
border-color: #9f1239;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
.anim-acct__btn--danger:disabled {
|
|
299
|
+
opacity: 0.6;
|
|
300
|
+
cursor: not-allowed;
|
|
301
|
+
}
|
|
302
|
+
|
|
209
303
|
.anim-acct__btn {
|
|
210
304
|
display: inline-flex;
|
|
211
305
|
align-items: center;
|