@pradip1995/segment-product-card 0.3.29 → 0.3.31
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-product-card",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.31",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"react-dom": ">=19"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@pradip1995/segment-login-popup": "^0.1.
|
|
28
|
+
"@pradip1995/segment-login-popup": "^0.1.6",
|
|
29
29
|
"@pradip1995/segment-primitives": "^0.4.11",
|
|
30
30
|
"@pradip1995/segment-tokens": "^0.3.14"
|
|
31
31
|
},
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { revalidateWishlistCache } from "./revalidate-wishlist"
|
|
4
|
+
import { dispatchWishlistUpdated, type WishlistUpdatedDetail } from "./wishlist-count"
|
|
5
|
+
|
|
6
|
+
export async function notifyWishlistChanged(detail: WishlistUpdatedDetail) {
|
|
7
|
+
dispatchWishlistUpdated(detail)
|
|
8
|
+
await revalidateWishlistCache()
|
|
9
|
+
}
|
|
@@ -10,9 +10,11 @@ import {
|
|
|
10
10
|
} from "@pradip1995/commerce-core/client/actions/wishlist"
|
|
11
11
|
import type { HttpTypes } from "@medusajs/types"
|
|
12
12
|
import { isNextRedirect } from "@pradip1995/segment-primitives/is-next-redirect"
|
|
13
|
+
import { notifyWishlistChanged } from "./notify-wishlist"
|
|
13
14
|
import LoginRequiredModal, {
|
|
14
15
|
isAuthRequiredError,
|
|
15
16
|
promptLoginForWishlist,
|
|
17
|
+
requireLoginForWishlist,
|
|
16
18
|
} from "@pradip1995/segment-login-popup/required"
|
|
17
19
|
import QuickAddPanel from "./quick-add-panel"
|
|
18
20
|
import {
|
|
@@ -104,6 +106,7 @@ export default function ProductCardActions({
|
|
|
104
106
|
const handleWishlistToggle = async (event: React.MouseEvent) => {
|
|
105
107
|
stopCardNav(event)
|
|
106
108
|
if (!product.id || wishlistLoading) return
|
|
109
|
+
if (requireLoginForWishlist()) return
|
|
107
110
|
|
|
108
111
|
setWishlistLoading(true)
|
|
109
112
|
try {
|
|
@@ -125,6 +128,7 @@ export default function ProductCardActions({
|
|
|
125
128
|
|
|
126
129
|
if (result.success) {
|
|
127
130
|
setWishlisted(!currentlyWishlisted)
|
|
131
|
+
await notifyWishlistChanged({ delta: currentlyWishlisted ? -1 : 1 })
|
|
128
132
|
router.refresh()
|
|
129
133
|
return
|
|
130
134
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const WISHLIST_UPDATED_EVENT = "wishlist:updated"
|
|
2
|
+
|
|
3
|
+
export type WishlistUpdatedDetail = {
|
|
4
|
+
delta?: number
|
|
5
|
+
count?: number
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function dispatchWishlistUpdated(detail: WishlistUpdatedDetail) {
|
|
9
|
+
if (typeof window === "undefined") return
|
|
10
|
+
window.dispatchEvent(new CustomEvent(WISHLIST_UPDATED_EVENT, { detail }))
|
|
11
|
+
}
|