@pradip1995/segment-product-card 0.3.30 → 0.3.32

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.30",
3
+ "version": "0.3.32",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -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,8 @@
1
+ "use server"
2
+
3
+ import { revalidatePath } from "next/cache"
4
+
5
+ export async function revalidateWishlistCache() {
6
+ revalidatePath("/", "layout")
7
+ revalidatePath("/wishlist")
8
+ }
@@ -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
+ }