@hszrdm/create-commerce 1.1.0 → 1.2.0

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.
Files changed (38) hide show
  1. package/package.json +1 -1
  2. package/src/cli.mjs +5 -2
  3. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +41 -9
  4. package/templates/storefront/src/app/account/page.tsx +12 -1
  5. package/templates/storefront/src/app/account/wishlist/page.tsx +9 -0
  6. package/templates/storefront/src/app/core-ux.css +244 -0
  7. package/templates/storefront/src/app/layout.tsx +31 -12
  8. package/templates/storefront/src/app/newsletter/confirm/page.tsx +19 -0
  9. package/templates/storefront/src/app/newsletter/unsubscribe/page.tsx +19 -0
  10. package/templates/storefront/src/components/accessibility-preferences.tsx +126 -0
  11. package/templates/storefront/src/components/accessible-dialog.tsx +88 -0
  12. package/templates/storefront/src/components/accessible-dropdown.tsx +98 -0
  13. package/templates/storefront/src/components/account-wishlist.tsx +95 -0
  14. package/templates/storefront/src/components/add-to-cart.tsx +110 -15
  15. package/templates/storefront/src/components/back-to-top.tsx +26 -0
  16. package/templates/storefront/src/components/breadcrumbs.tsx +26 -0
  17. package/templates/storefront/src/components/cart-view.tsx +72 -16
  18. package/templates/storefront/src/components/form-ux.tsx +47 -0
  19. package/templates/storefront/src/components/free-shipping-progress.tsx +35 -0
  20. package/templates/storefront/src/components/newsletter-action.tsx +66 -0
  21. package/templates/storefront/src/components/product-gallery.tsx +64 -0
  22. package/templates/storefront/src/components/quantity-stepper.tsx +41 -0
  23. package/templates/storefront/src/components/share-button.tsx +63 -0
  24. package/templates/storefront/src/components/storefront-header.tsx +72 -18
  25. package/templates/storefront/src/components/tier-progress-hint.tsx +32 -0
  26. package/templates/storefront/src/components/toast-provider.tsx +92 -0
  27. package/templates/storefront/src/components/variant-price-display.tsx +31 -0
  28. package/templates/storefront/src/components/wishlist-button.tsx +88 -0
  29. package/templates/storefront/src/lib/core/account.ts +3 -0
  30. package/templates/storefront/src/lib/core/cms-contract.ts +35 -0
  31. package/templates/storefront/src/lib/core/cms.ts +66 -7
  32. package/templates/storefront/src/lib/core/form-ux.ts +57 -0
  33. package/templates/storefront/src/lib/core/newsletter.ts +53 -0
  34. package/templates/storefront/src/lib/core/reviews.ts +40 -0
  35. package/templates/storefront/src/lib/core/share.ts +57 -0
  36. package/templates/storefront/src/lib/core/wishlist.ts +88 -0
  37. package/templates/storefront/src/lib/storefront-routes.ts +3 -0
  38. package/templates/storefront/src/proxy.ts +3 -0
@@ -0,0 +1,88 @@
1
+ import { medusaFetch } from "./client"
2
+
3
+ export type WishlistProduct = {
4
+ id: string
5
+ title?: string
6
+ handle?: string
7
+ thumbnail?: string | null
8
+ status?: string
9
+ }
10
+
11
+ export type WishlistItem = {
12
+ id: string
13
+ product_id: string
14
+ created_at?: string
15
+ product?: WishlistProduct | null
16
+ }
17
+
18
+ const GUEST_WISHLIST_KEY = "hszrdm_guest_wishlist_v1"
19
+
20
+ export function listWishlist() {
21
+ return medusaFetch<{ items: WishlistItem[]; count: number }>("/store/account/wishlist", {
22
+ cache: "no-store",
23
+ })
24
+ }
25
+
26
+ export function addWishlistProduct(productId: string) {
27
+ return medusaFetch<{ item: WishlistItem; already_saved: boolean }>("/store/account/wishlist", {
28
+ method: "POST",
29
+ body: JSON.stringify({ product_id: productId }),
30
+ })
31
+ }
32
+
33
+ export function removeWishlistProduct(productId: string) {
34
+ return medusaFetch<{ product_id: string; deleted: boolean }>(
35
+ `/store/account/wishlist/${encodeURIComponent(productId)}`,
36
+ { method: "DELETE" },
37
+ )
38
+ }
39
+
40
+ export function mergeWishlistProducts(productIds: string[]) {
41
+ return medusaFetch<{ merged: number; ignored: number; product_ids: string[] }>("/store/account/wishlist/merge", {
42
+ method: "POST",
43
+ body: JSON.stringify({ product_ids: productIds }),
44
+ })
45
+ }
46
+
47
+ export function getGuestWishlistProductIds() {
48
+ if (typeof window === "undefined") return []
49
+ try {
50
+ const parsed = JSON.parse(window.localStorage.getItem(GUEST_WISHLIST_KEY) || "[]")
51
+ if (!Array.isArray(parsed)) return []
52
+ return [...new Set(parsed.map((item) => typeof item === "string" ? item.trim() : "").filter(Boolean))]
53
+ } catch {
54
+ return []
55
+ }
56
+ }
57
+
58
+ export function addGuestWishlistProduct(productId: string) {
59
+ const ids = getGuestWishlistProductIds()
60
+ const normalized = productId.trim()
61
+ if (!normalized) return ids
62
+ const next = ids.includes(normalized) ? ids : [...ids, normalized]
63
+ writeGuestWishlist(next)
64
+ return next
65
+ }
66
+
67
+ export function removeGuestWishlistProduct(productId: string) {
68
+ const next = getGuestWishlistProductIds().filter((id) => id !== productId)
69
+ writeGuestWishlist(next)
70
+ return next
71
+ }
72
+
73
+ export function clearGuestWishlist() {
74
+ if (typeof window !== "undefined") window.localStorage.removeItem(GUEST_WISHLIST_KEY)
75
+ }
76
+
77
+ export async function mergeGuestWishlistAfterLogin() {
78
+ const ids = getGuestWishlistProductIds()
79
+ if (!ids.length) return { merged: 0, ignored: 0, product_ids: [] as string[] }
80
+ const result = await mergeWishlistProducts(ids)
81
+ clearGuestWishlist()
82
+ return result
83
+ }
84
+
85
+ function writeGuestWishlist(ids: string[]) {
86
+ if (typeof window === "undefined") return
87
+ window.localStorage.setItem(GUEST_WISHLIST_KEY, JSON.stringify([...new Set(ids)].slice(0, 200)))
88
+ }
@@ -8,6 +8,7 @@ export const STOREFRONT_ROUTES = {
8
8
  checkout: "/hu/penztar",
9
9
  checkoutSuccess: "/hu/penztar/sikeres-rendeles",
10
10
  account: "/hu/fiokom",
11
+ wishlist: "/hu/fiokom/kedvencek",
11
12
  orders: "/hu/fiokom/rendelesek",
12
13
  resetPassword: "/hu/jelszo-visszaallitas",
13
14
  legal: "/hu/jogi",
@@ -21,6 +22,7 @@ export const STOREFRONT_ROUTES = {
21
22
  checkout: "/en/checkout",
22
23
  checkoutSuccess: "/en/checkout/success",
23
24
  account: "/en/account",
25
+ wishlist: "/en/account/wishlist",
24
26
  orders: "/en/account/orders",
25
27
  resetPassword: "/en/reset-password",
26
28
  legal: "/en/legal",
@@ -80,6 +82,7 @@ export function equivalentLocalePath(
80
82
  if (pathname === source.checkout) return target.checkout
81
83
  if (pathname === source.checkoutSuccess) return target.checkoutSuccess
82
84
  if (pathname === source.account) return target.account
85
+ if (pathname === source.wishlist) return target.wishlist
83
86
  if (pathname === source.orders) return target.orders
84
87
  if (pathname.startsWith(`${source.orders}/`)) {
85
88
  return `${target.orders}/${pathname.slice(source.orders.length + 1)}`
@@ -55,6 +55,7 @@ function legacyRedirect(pathname: string, locale: StorefrontLocale) {
55
55
  if (pathname === "/checkout") return STOREFRONT_ROUTES[locale].checkout
56
56
  if (pathname === "/checkout/success") return STOREFRONT_ROUTES[locale].checkoutSuccess
57
57
  if (pathname === "/account") return STOREFRONT_ROUTES[locale].account
58
+ if (pathname === "/account/wishlist") return STOREFRONT_ROUTES[locale].wishlist
58
59
  if (pathname.startsWith("/account/orders/")) {
59
60
  return `${STOREFRONT_ROUTES[locale].orders}/${pathname.slice("/account/orders/".length)}`
60
61
  }
@@ -73,6 +74,7 @@ function legacyRedirect(pathname: string, locale: StorefrontLocale) {
73
74
  if (pathname === "/hu/checkout") return STOREFRONT_ROUTES.hu.checkout
74
75
  if (pathname === "/hu/checkout/success") return STOREFRONT_ROUTES.hu.checkoutSuccess
75
76
  if (pathname === "/hu/account") return STOREFRONT_ROUTES.hu.account
77
+ if (pathname === "/hu/account/wishlist") return STOREFRONT_ROUTES.hu.wishlist
76
78
  if (pathname.startsWith("/hu/account/orders/")) {
77
79
  return `${STOREFRONT_ROUTES.hu.orders}/${pathname.slice("/hu/account/orders/".length)}`
78
80
  }
@@ -102,6 +104,7 @@ function internalRewrite(pathname: string, locale: StorefrontLocale) {
102
104
  if (pathname === routes.checkout) return "/checkout"
103
105
  if (pathname === routes.checkoutSuccess) return "/checkout/success"
104
106
  if (pathname === routes.account) return "/account"
107
+ if (pathname === routes.wishlist) return "/account/wishlist"
105
108
  if (pathname.startsWith(`${routes.orders}/`)) {
106
109
  return `/account/orders/${pathname.slice(routes.orders.length + 1)}`
107
110
  }