@pradip1995/segment-product-card 0.3.30 → 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
|
@@ -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,6 +10,7 @@ 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,
|
|
@@ -127,6 +128,7 @@ export default function ProductCardActions({
|
|
|
127
128
|
|
|
128
129
|
if (result.success) {
|
|
129
130
|
setWishlisted(!currentlyWishlisted)
|
|
131
|
+
await notifyWishlistChanged({ delta: currentlyWishlisted ? -1 : 1 })
|
|
130
132
|
router.refresh()
|
|
131
133
|
return
|
|
132
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
|
+
}
|