@pradip1995/segment-powerhouse-cart 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 +2 -2
- package/src/cart.css +97 -21
- package/src/segment.tsx +63 -43
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pradip1995/segment-powerhouse-cart",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@pradip1995/segment-analytics": "^0.2.4",
|
|
29
29
|
"@pradip1995/segment-login-popup": "^0.1.3",
|
|
30
|
-
"@pradip1995/segment-primitives": "^0.4.
|
|
30
|
+
"@pradip1995/segment-primitives": "^0.4.11"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@medusajs/types": "^2.0.0",
|
package/src/cart.css
CHANGED
|
@@ -412,79 +412,155 @@
|
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
+
@keyframes powerhouseModalFadeIn {
|
|
416
|
+
from {
|
|
417
|
+
opacity: 0;
|
|
418
|
+
transform: scale(0.95) translateY(10px);
|
|
419
|
+
}
|
|
420
|
+
to {
|
|
421
|
+
opacity: 1;
|
|
422
|
+
transform: scale(1) translateY(0);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
@keyframes powerhouseBackdropFade {
|
|
427
|
+
from { opacity: 0; }
|
|
428
|
+
to { opacity: 1; }
|
|
429
|
+
}
|
|
430
|
+
|
|
415
431
|
.powerhouse-cart-confirm {
|
|
416
432
|
position: fixed;
|
|
417
433
|
inset: 0;
|
|
418
|
-
z-index:
|
|
434
|
+
z-index: 99999;
|
|
419
435
|
display: flex;
|
|
420
436
|
align-items: center;
|
|
421
437
|
justify-content: center;
|
|
422
|
-
padding:
|
|
438
|
+
padding: 1.25rem;
|
|
423
439
|
}
|
|
424
440
|
|
|
425
441
|
.powerhouse-cart-confirm__backdrop {
|
|
426
442
|
position: absolute;
|
|
427
443
|
inset: 0;
|
|
428
444
|
border: 0;
|
|
429
|
-
background: rgba(
|
|
445
|
+
background: rgba(15, 10, 25, 0.55);
|
|
446
|
+
backdrop-filter: blur(6px);
|
|
447
|
+
-webkit-backdrop-filter: blur(6px);
|
|
448
|
+
animation: powerhouseBackdropFade 0.2s ease-out forwards;
|
|
430
449
|
}
|
|
431
450
|
|
|
432
451
|
.powerhouse-cart-confirm__panel {
|
|
433
452
|
position: relative;
|
|
434
|
-
width: min(
|
|
435
|
-
padding: 1.
|
|
453
|
+
width: min(25.5rem, 100%);
|
|
454
|
+
padding: 2.25rem 2rem 1.75rem;
|
|
436
455
|
background: #ffffff;
|
|
437
|
-
border:
|
|
456
|
+
border-radius: 1.25rem;
|
|
457
|
+
border: 1px solid rgba(59, 31, 78, 0.1);
|
|
458
|
+
box-shadow:
|
|
459
|
+
0 20px 40px -10px rgba(30, 15, 45, 0.25),
|
|
460
|
+
0 2px 10px rgba(0, 0, 0, 0.05);
|
|
461
|
+
text-align: center;
|
|
462
|
+
animation: powerhouseModalFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.powerhouse-cart-confirm__close {
|
|
466
|
+
position: absolute;
|
|
467
|
+
top: 1rem;
|
|
468
|
+
right: 1rem;
|
|
469
|
+
display: flex;
|
|
470
|
+
align-items: center;
|
|
471
|
+
justify-content: center;
|
|
472
|
+
width: 2rem;
|
|
473
|
+
height: 2rem;
|
|
474
|
+
padding: 0;
|
|
475
|
+
border: none;
|
|
476
|
+
border-radius: 9999px;
|
|
477
|
+
background: rgba(59, 31, 78, 0.05);
|
|
478
|
+
color: #6b7280;
|
|
479
|
+
font-size: 0.875rem;
|
|
480
|
+
line-height: 1;
|
|
481
|
+
cursor: pointer;
|
|
482
|
+
transition: all 0.2s ease;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
.powerhouse-cart-confirm__close:hover {
|
|
486
|
+
background: rgba(59, 31, 78, 0.12);
|
|
487
|
+
color: #111827;
|
|
438
488
|
}
|
|
439
489
|
|
|
440
490
|
.powerhouse-cart-confirm__title {
|
|
441
491
|
margin: 0 0 0.5rem;
|
|
442
492
|
font-family: var(--font-heading, Georgia, serif);
|
|
443
|
-
font-size: 1.
|
|
444
|
-
|
|
493
|
+
font-size: 1.4rem;
|
|
494
|
+
font-weight: 500;
|
|
495
|
+
letter-spacing: -0.01em;
|
|
496
|
+
color: #111827;
|
|
445
497
|
}
|
|
446
498
|
|
|
447
499
|
.powerhouse-cart-confirm__text {
|
|
448
|
-
margin: 0 0 1.
|
|
500
|
+
margin: 0 0 1.5rem;
|
|
449
501
|
font-size: 0.875rem;
|
|
450
|
-
|
|
502
|
+
line-height: 1.5;
|
|
503
|
+
color: #4b5563;
|
|
451
504
|
}
|
|
452
505
|
|
|
453
506
|
.powerhouse-cart-confirm__actions {
|
|
454
507
|
display: flex;
|
|
455
508
|
flex-direction: column;
|
|
456
|
-
gap: 0.
|
|
509
|
+
gap: 0.625rem;
|
|
457
510
|
}
|
|
458
511
|
|
|
459
512
|
.powerhouse-cart-confirm__btn {
|
|
460
|
-
|
|
461
|
-
|
|
513
|
+
display: inline-flex;
|
|
514
|
+
align-items: center;
|
|
515
|
+
justify-content: center;
|
|
516
|
+
min-height: 2.75rem;
|
|
517
|
+
padding: 0.7rem 1.25rem;
|
|
518
|
+
border-radius: 9999px;
|
|
462
519
|
font-size: 0.75rem;
|
|
463
520
|
font-weight: 600;
|
|
464
|
-
letter-spacing: 0.
|
|
521
|
+
letter-spacing: 0.09em;
|
|
465
522
|
text-transform: uppercase;
|
|
466
523
|
cursor: pointer;
|
|
524
|
+
transition: all 0.2s ease;
|
|
467
525
|
}
|
|
468
526
|
|
|
469
527
|
.powerhouse-cart-confirm__btn--primary {
|
|
470
|
-
border:
|
|
471
|
-
background: #
|
|
528
|
+
border: 1px solid #362447;
|
|
529
|
+
background: #362447;
|
|
472
530
|
color: #ffffff;
|
|
531
|
+
box-shadow: 0 4px 14px rgba(54, 36, 71, 0.25);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
.powerhouse-cart-confirm__btn--primary:hover:not(:disabled) {
|
|
535
|
+
background: #4a3260;
|
|
536
|
+
border-color: #4a3260;
|
|
537
|
+
box-shadow: 0 6px 18px rgba(54, 36, 71, 0.35);
|
|
473
538
|
}
|
|
474
539
|
|
|
475
540
|
.powerhouse-cart-confirm__btn--danger {
|
|
476
|
-
border: 1px solid #
|
|
541
|
+
border: 1px solid #dc2626;
|
|
477
542
|
background: #ffffff;
|
|
478
|
-
color: #
|
|
543
|
+
color: #dc2626;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
.powerhouse-cart-confirm__btn--danger:hover:not(:disabled) {
|
|
547
|
+
background: #fef2f2;
|
|
548
|
+
border-color: #b91c1c;
|
|
549
|
+
color: #b91c1c;
|
|
479
550
|
}
|
|
480
551
|
|
|
481
552
|
.powerhouse-cart-confirm__btn--ghost {
|
|
482
|
-
border:
|
|
553
|
+
border: 1px solid transparent;
|
|
483
554
|
background: transparent;
|
|
484
|
-
color: #
|
|
555
|
+
color: #6b7280;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
.powerhouse-cart-confirm__btn--ghost:hover:not(:disabled) {
|
|
559
|
+
background: rgba(59, 31, 78, 0.05);
|
|
560
|
+
color: #111827;
|
|
485
561
|
}
|
|
486
562
|
|
|
487
563
|
.powerhouse-cart-confirm__btn:disabled {
|
|
488
|
-
opacity: 0.
|
|
564
|
+
opacity: 0.75;
|
|
489
565
|
cursor: not-allowed;
|
|
490
566
|
}
|
package/src/segment.tsx
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import Image from "next/image"
|
|
4
4
|
import { useRouter } from "next/navigation"
|
|
5
|
-
import { useState, useTransition } from "react"
|
|
5
|
+
import { useEffect, useState, useTransition } from "react"
|
|
6
|
+
import { createPortal } from "react-dom"
|
|
6
7
|
import type { HttpTypes } from "@medusajs/types"
|
|
7
8
|
import { deleteLineItem, updateLineItem } from "@pradip1995/commerce-core/client/actions/cart"
|
|
8
9
|
import { addToWishlist } from "@pradip1995/commerce-core/client/actions/wishlist"
|
|
@@ -13,7 +14,10 @@ import {
|
|
|
13
14
|
import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
|
|
14
15
|
import { formatPrice } from "@pradip1995/segment-primitives/format-price"
|
|
15
16
|
import { resolveMediaUrl } from "@pradip1995/segment-primitives/resolve-media-url"
|
|
16
|
-
import LoginRequiredModal
|
|
17
|
+
import LoginRequiredModal, {
|
|
18
|
+
isAuthRequiredError,
|
|
19
|
+
promptLoginForWishlist,
|
|
20
|
+
} from "@pradip1995/segment-login-popup/required"
|
|
17
21
|
import {
|
|
18
22
|
DEFAULT_CHECKOUT_LABEL,
|
|
19
23
|
DEFAULT_CONTINUE_HREF,
|
|
@@ -135,10 +139,15 @@ function LineItemRow({
|
|
|
135
139
|
const [pending, startTransition] = useTransition()
|
|
136
140
|
const [confirmOpen, setConfirmOpen] = useState(false)
|
|
137
141
|
const [loginRequired, setLoginRequired] = useState(false)
|
|
142
|
+
const [mounted, setMounted] = useState(false)
|
|
138
143
|
const thumbnail = lineItemImage(item)
|
|
139
144
|
const variantLabel = item.variant?.title
|
|
140
145
|
const showVariant = Boolean(variantLabel && !isPlaceholderVariant(variantLabel))
|
|
141
146
|
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
setMounted(true)
|
|
149
|
+
}, [])
|
|
150
|
+
|
|
142
151
|
function changeQty(next: number) {
|
|
143
152
|
if (next < 1 || !item.id) return
|
|
144
153
|
const previousQuantity = item.quantity ?? 1
|
|
@@ -167,9 +176,9 @@ function LineItemRow({
|
|
|
167
176
|
}
|
|
168
177
|
startTransition(async () => {
|
|
169
178
|
const result = await addToWishlist(productId)
|
|
170
|
-
if (!result.success && result.error
|
|
179
|
+
if (!result.success && isAuthRequiredError(result.error)) {
|
|
171
180
|
setConfirmOpen(false)
|
|
172
|
-
setLoginRequired(true)
|
|
181
|
+
promptLoginForWishlist(() => setLoginRequired(true))
|
|
173
182
|
return
|
|
174
183
|
}
|
|
175
184
|
if (!result.success) {
|
|
@@ -241,48 +250,59 @@ function LineItemRow({
|
|
|
241
250
|
</div>
|
|
242
251
|
<p className="powerhouse-cart__total">{formatPrice(lineTotal(item), currency)}</p>
|
|
243
252
|
|
|
244
|
-
{confirmOpen
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
type="button"
|
|
248
|
-
className="powerhouse-cart-confirm__backdrop"
|
|
249
|
-
aria-label="Close"
|
|
250
|
-
onClick={() => setConfirmOpen(false)}
|
|
251
|
-
/>
|
|
252
|
-
<div className="powerhouse-cart-confirm__panel" role="dialog" aria-modal="true">
|
|
253
|
-
<h3 className="powerhouse-cart-confirm__title">Remove this item?</h3>
|
|
254
|
-
<p className="powerhouse-cart-confirm__text">
|
|
255
|
-
Move it to your wishlist to save it for later, or remove it from your cart.
|
|
256
|
-
</p>
|
|
257
|
-
<div className="powerhouse-cart-confirm__actions">
|
|
253
|
+
{confirmOpen && mounted
|
|
254
|
+
? createPortal(
|
|
255
|
+
<div className="powerhouse-cart-confirm">
|
|
258
256
|
<button
|
|
259
257
|
type="button"
|
|
260
|
-
className="powerhouse-cart-
|
|
261
|
-
|
|
262
|
-
onClick={moveToWishlist}
|
|
263
|
-
>
|
|
264
|
-
{pending ? "Saving…" : "Move to Wishlist"}
|
|
265
|
-
</button>
|
|
266
|
-
<button
|
|
267
|
-
type="button"
|
|
268
|
-
className="powerhouse-cart-confirm__btn powerhouse-cart-confirm__btn--danger"
|
|
269
|
-
disabled={pending}
|
|
270
|
-
onClick={removeFromCart}
|
|
271
|
-
>
|
|
272
|
-
Remove the Product
|
|
273
|
-
</button>
|
|
274
|
-
<button
|
|
275
|
-
type="button"
|
|
276
|
-
className="powerhouse-cart-confirm__btn powerhouse-cart-confirm__btn--ghost"
|
|
277
|
-
disabled={pending}
|
|
258
|
+
className="powerhouse-cart-confirm__backdrop"
|
|
259
|
+
aria-label="Close"
|
|
278
260
|
onClick={() => setConfirmOpen(false)}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
261
|
+
/>
|
|
262
|
+
<div className="powerhouse-cart-confirm__panel" role="dialog" aria-modal="true">
|
|
263
|
+
<button
|
|
264
|
+
type="button"
|
|
265
|
+
className="powerhouse-cart-confirm__close"
|
|
266
|
+
aria-label="Close dialog"
|
|
267
|
+
onClick={() => setConfirmOpen(false)}
|
|
268
|
+
>
|
|
269
|
+
✕
|
|
270
|
+
</button>
|
|
271
|
+
<h3 className="powerhouse-cart-confirm__title">Remove this item?</h3>
|
|
272
|
+
<p className="powerhouse-cart-confirm__text">
|
|
273
|
+
Move it to your wishlist to save it for later, or remove it from your cart.
|
|
274
|
+
</p>
|
|
275
|
+
<div className="powerhouse-cart-confirm__actions">
|
|
276
|
+
<button
|
|
277
|
+
type="button"
|
|
278
|
+
className="powerhouse-cart-confirm__btn powerhouse-cart-confirm__btn--primary"
|
|
279
|
+
disabled={pending}
|
|
280
|
+
onClick={moveToWishlist}
|
|
281
|
+
>
|
|
282
|
+
{pending ? "Saving…" : "Move to Wishlist"}
|
|
283
|
+
</button>
|
|
284
|
+
<button
|
|
285
|
+
type="button"
|
|
286
|
+
className="powerhouse-cart-confirm__btn powerhouse-cart-confirm__btn--danger"
|
|
287
|
+
disabled={pending}
|
|
288
|
+
onClick={removeFromCart}
|
|
289
|
+
>
|
|
290
|
+
Remove the Product
|
|
291
|
+
</button>
|
|
292
|
+
<button
|
|
293
|
+
type="button"
|
|
294
|
+
className="powerhouse-cart-confirm__btn powerhouse-cart-confirm__btn--ghost"
|
|
295
|
+
disabled={pending}
|
|
296
|
+
onClick={() => setConfirmOpen(false)}
|
|
297
|
+
>
|
|
298
|
+
Keep in cart
|
|
299
|
+
</button>
|
|
300
|
+
</div>
|
|
301
|
+
</div>
|
|
302
|
+
</div>,
|
|
303
|
+
document.body
|
|
304
|
+
)
|
|
305
|
+
: null}
|
|
286
306
|
|
|
287
307
|
<LoginRequiredModal
|
|
288
308
|
isOpen={loginRequired}
|