@pradip1995/segment-animation-login 0.1.2 → 0.1.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pradip1995/segment-animation-login",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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,7 +27,7 @@
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.13",
30
+ "@pradip1995/segment-login-template": "^0.5.14",
35
31
  "@pradip1995/segment-primitives": "^0.4.11",
36
32
  "framer-motion": "^11.0.0"
37
33
  },
@@ -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
- } finally {
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
- if (iconOnly) {
340
- return (
341
- <button
342
- type="button"
343
- onClick={handleDelete}
344
- disabled={pending}
345
- className="anim-acct__icon-btn anim-acct__icon-btn--danger"
346
- aria-label={pending ? "Deleting address" : "Delete address"}
347
- title="Delete"
348
- >
349
- <DeleteIcon />
350
- </button>
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={handleDelete}
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() {
@@ -236,12 +236,6 @@ export default function AnimationAccountOrders({
236
236
  </ul>
237
237
 
238
238
  <div className="anim-acct__order-card-actions">
239
- <LocalizedLink
240
- href={`/orders/${order.id}`}
241
- className="anim-acct__btn anim-acct__btn--primary anim-acct__btn--sm"
242
- >
243
- View details
244
- </LocalizedLink>
245
239
  {showReorder ? (
246
240
  <button
247
241
  type="button"
@@ -252,6 +246,12 @@ export default function AnimationAccountOrders({
252
246
  {reorderingId === order.id ? "Adding…" : "Reorder"}
253
247
  </button>
254
248
  ) : null}
249
+ <LocalizedLink
250
+ href={`/orders/${order.id}`}
251
+ className="anim-acct__btn anim-acct__btn--primary anim-acct__btn--sm"
252
+ >
253
+ View details
254
+ </LocalizedLink>
255
255
  </div>
256
256
  </li>
257
257
  )
@@ -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
- <li key={order.id}>
97
- <LocalizedLink href={`/orders/${order.id}`} className="anim-acct__order">
98
- <div>
99
- <span className="anim-acct__order-id">#{order.display_id}</span>
100
- <span className="anim-acct__order-date">
101
- {order.created_at
102
- ? new Date(order.created_at).toLocaleDateString("en-IN", {
103
- dateStyle: "medium",
104
- })
105
- : "—"}
106
- </span>
107
- </div>
108
- <strong>{formatPrice(order.total, order.currency_code)}</strong>
109
- </LocalizedLink>
110
- </li>
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>
@@ -1,12 +1,12 @@
1
1
  /* Motion account content (overview + restyle nested login-template panels) */
2
2
 
3
3
  .anim-acct {
4
- --aa-ink: #1c1412;
5
- --aa-muted: #7a6e68;
6
- --aa-line: #ebe4df;
7
- --aa-accent: #e23b00;
8
- --aa-accent-hover: #c43200;
9
- --aa-accent-soft: rgba(226, 59, 0, 0.08);
4
+ --aa-ink: #0a0a0a;
5
+ --aa-muted: #737373;
6
+ --aa-line: #e5e5e5;
7
+ --aa-accent: #111111;
8
+ --aa-accent-hover: #333333;
9
+ --aa-accent-soft: rgba(17, 17, 17, 0.08);
10
10
  --aa-sans: var(--font-sans, "DM Sans", sans-serif);
11
11
  display: flex;
12
12
  flex-direction: column;
@@ -77,7 +77,7 @@
77
77
  gap: 0.35rem;
78
78
  padding: 1.1rem 1rem;
79
79
  border: 1px solid var(--aa-line);
80
- background: #fffaf7;
80
+ background: #ffffff;
81
81
  text-decoration: none;
82
82
  color: inherit;
83
83
  transition: border-color 0.2s ease, background 0.2s ease;
@@ -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;
@@ -262,7 +356,7 @@
262
356
  .anim-acct__address-card {
263
357
  padding: 1.15rem 1.1rem;
264
358
  border: 1px solid var(--aa-line);
265
- background: #fffaf7;
359
+ background: #ffffff;
266
360
  }
267
361
 
268
362
  .anim-acct__address-top {
@@ -577,7 +671,7 @@
577
671
 
578
672
  .anim-acct__order-card {
579
673
  border: 1px solid var(--aa-line);
580
- background: #fffaf7;
674
+ background: #ffffff;
581
675
  padding: 1.15rem 1.1rem 1.2rem;
582
676
  }
583
677
 
@@ -796,6 +890,8 @@
796
890
  .anim-acct__order-card-actions {
797
891
  display: flex;
798
892
  flex-wrap: wrap;
893
+ align-items: center;
894
+ justify-content: flex-end;
799
895
  gap: 0.55rem;
800
896
  padding-top: 0.15rem;
801
897
  }
@@ -833,27 +929,27 @@
833
929
  [data-anim-account] [class*="btnPrimary"],
834
930
  [data-anim-account] button[class*="bg-heading"],
835
931
  [data-anim-account] .bg-heading {
836
- background: #e23b00 !important;
837
- border-color: #e23b00 !important;
932
+ background: #111111 !important;
933
+ border-color: #111111 !important;
838
934
  color: #ffffff !important;
839
935
  }
840
936
 
841
937
  [data-anim-account] .hover\:bg-brand-accent:hover,
842
938
  [data-anim-account] .bg-brand-primary:hover,
843
939
  [data-anim-account] .bg-brand-accent:hover {
844
- background: #c43200 !important;
845
- border-color: #c43200 !important;
940
+ background: #333333 !important;
941
+ border-color: #333333 !important;
846
942
  }
847
943
 
848
944
  [data-anim-account] .text-brand-accent,
849
945
  [data-anim-account] .text-heading.font-bold,
850
946
  [data-anim-account] .border-brand-accent {
851
- color: #e23b00 !important;
947
+ color: #111111 !important;
852
948
  }
853
949
 
854
950
  [data-anim-account] .border-brand-accent,
855
951
  [data-anim-account] .border-heading {
856
- border-color: #e23b00 !important;
952
+ border-color: #111111 !important;
857
953
  }
858
954
 
859
955
  [data-anim-account] button.border,
@@ -864,7 +960,7 @@
864
960
  [data-anim-account] input:focus,
865
961
  [data-anim-account] select:focus,
866
962
  [data-anim-account] textarea:focus {
867
- border-color: #e23b00 !important;
963
+ border-color: #111111 !important;
868
964
  outline: none !important;
869
965
  box-shadow: none !important;
870
966
  }
@@ -872,7 +968,7 @@
872
968
  [data-anim-account] input:focus-visible,
873
969
  [data-anim-account] select:focus-visible,
874
970
  [data-anim-account] textarea:focus-visible {
875
- border-color: #e23b00 !important;
971
+ border-color: #111111 !important;
876
972
  outline: none !important;
877
973
  box-shadow: none !important;
878
974
  }