@hszrdm/create-commerce 1.0.3 → 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.
- package/bin/create-commerce.mjs +9 -2
- package/package.json +1 -1
- package/src/cli.mjs +5 -2
- package/templates/backend/.env.example +66 -7
- package/templates/backend/medusa-config.ts +17 -1
- package/templates/backend/package.json +2 -1
- package/templates/backend/src/scripts/core-init.ts +13 -1
- package/templates/storefront/next-env.d.ts +4 -1
- package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +9 -3
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +46 -10
- package/templates/storefront/src/app/[countryCode]/products/page.tsx +17 -10
- package/templates/storefront/src/app/account/page.tsx +12 -1
- package/templates/storefront/src/app/account/wishlist/page.tsx +9 -0
- package/templates/storefront/src/app/checkout/page.tsx +12 -3
- package/templates/storefront/src/app/checkout/success/page.tsx +58 -18
- package/templates/storefront/src/app/core-ux.css +244 -0
- package/templates/storefront/src/app/layout.tsx +40 -14
- package/templates/storefront/src/app/legal/page.tsx +11 -5
- package/templates/storefront/src/app/newsletter/confirm/page.tsx +19 -0
- package/templates/storefront/src/app/newsletter/unsubscribe/page.tsx +19 -0
- package/templates/storefront/src/app/page.tsx +18 -12
- package/templates/storefront/src/app/reset-password/page.tsx +8 -2
- package/templates/storefront/src/components/accessibility-preferences.tsx +126 -0
- package/templates/storefront/src/components/accessible-dialog.tsx +88 -0
- package/templates/storefront/src/components/accessible-dropdown.tsx +98 -0
- package/templates/storefront/src/components/account-dashboard.tsx +197 -76
- package/templates/storefront/src/components/account-wishlist.tsx +95 -0
- package/templates/storefront/src/components/add-to-cart.tsx +127 -18
- package/templates/storefront/src/components/back-to-top.tsx +26 -0
- package/templates/storefront/src/components/breadcrumbs.tsx +26 -0
- package/templates/storefront/src/components/cart-provider.tsx +29 -12
- package/templates/storefront/src/components/cart-view.tsx +96 -32
- package/templates/storefront/src/components/checkout-analytics.tsx +23 -0
- package/templates/storefront/src/components/checkout-flow.tsx +354 -102
- package/templates/storefront/src/components/form-ux.tsx +47 -0
- package/templates/storefront/src/components/free-shipping-progress.tsx +35 -0
- package/templates/storefront/src/components/newsletter-action.tsx +66 -0
- package/templates/storefront/src/components/order-detail.tsx +84 -45
- package/templates/storefront/src/components/product-card.tsx +16 -8
- package/templates/storefront/src/components/product-gallery.tsx +64 -0
- package/templates/storefront/src/components/quantity-stepper.tsx +41 -0
- package/templates/storefront/src/components/reset-password-form.tsx +19 -13
- package/templates/storefront/src/components/share-button.tsx +63 -0
- package/templates/storefront/src/components/storefront-header.tsx +88 -20
- package/templates/storefront/src/components/stripe-payment.tsx +20 -4
- package/templates/storefront/src/components/tier-progress-hint.tsx +32 -0
- package/templates/storefront/src/components/toast-provider.tsx +92 -0
- package/templates/storefront/src/components/variant-price-display.tsx +31 -0
- package/templates/storefront/src/components/wishlist-button.tsx +88 -0
- package/templates/storefront/src/lib/core/account.ts +3 -0
- package/templates/storefront/src/lib/core/catalog.ts +37 -5
- package/templates/storefront/src/lib/core/client.ts +5 -0
- package/templates/storefront/src/lib/core/cms-contract.ts +35 -0
- package/templates/storefront/src/lib/core/cms.ts +171 -0
- package/templates/storefront/src/lib/core/commerce.ts +14 -4
- package/templates/storefront/src/lib/core/form-ux.ts +57 -0
- package/templates/storefront/src/lib/core/leads.ts +50 -0
- package/templates/storefront/src/lib/core/newsletter.ts +53 -0
- package/templates/storefront/src/lib/core/pricing.ts +68 -0
- package/templates/storefront/src/lib/core/quotes.ts +43 -0
- package/templates/storefront/src/lib/core/reviews.ts +40 -0
- package/templates/storefront/src/lib/core/seo.ts +44 -6
- package/templates/storefront/src/lib/core/share.ts +57 -0
- package/templates/storefront/src/lib/core/wishlist.ts +88 -0
- package/templates/storefront/src/lib/storefront-copy.ts +435 -0
- package/templates/storefront/src/lib/storefront-locale-server.ts +11 -0
- package/templates/storefront/src/lib/storefront-routes.ts +94 -0
- package/templates/storefront/src/proxy.ts +145 -0
- package/templates/storefront/tsconfig.json +23 -5
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
3
|
import Link from "next/link"
|
|
4
|
+
import { usePathname } from "next/navigation"
|
|
4
5
|
import { useState } from "react"
|
|
6
|
+
import { QuantityStepper } from "./quantity-stepper"
|
|
7
|
+
import { useToast } from "./toast-provider"
|
|
5
8
|
import { useCart } from "./cart-provider"
|
|
6
9
|
import {
|
|
7
10
|
cartCurrency,
|
|
@@ -16,7 +19,10 @@ import {
|
|
|
16
19
|
numberValue,
|
|
17
20
|
stringValue,
|
|
18
21
|
} from "@/lib/core/commerce"
|
|
22
|
+
import { humanizeStorefrontError } from "@/lib/core/form-ux"
|
|
19
23
|
import type { CoreConfig } from "@/lib/core/types"
|
|
24
|
+
import { storefrontCopy } from "@/lib/storefront-copy"
|
|
25
|
+
import { localeFromPathname, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
|
|
20
26
|
|
|
21
27
|
export function CartView({ config, compact = false }: { config: CoreConfig; compact?: boolean }) {
|
|
22
28
|
const {
|
|
@@ -24,23 +30,30 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
|
|
|
24
30
|
loading,
|
|
25
31
|
mutating,
|
|
26
32
|
error,
|
|
33
|
+
addItem,
|
|
27
34
|
updateItem,
|
|
28
35
|
removeItem,
|
|
29
36
|
addPromotion,
|
|
30
37
|
removePromotion,
|
|
31
38
|
setDrawerOpen,
|
|
32
39
|
} = useCart()
|
|
40
|
+
const pathname = usePathname()
|
|
41
|
+
const locale = localeFromPathname(pathname)
|
|
42
|
+
const routes = STOREFRONT_ROUTES[locale]
|
|
43
|
+
const copy = storefrontCopy(locale)
|
|
44
|
+
const formatLocale = locale === "en" ? "en-US" : "hu-HU"
|
|
33
45
|
const [promo, setPromo] = useState("")
|
|
46
|
+
const { showToast } = useToast()
|
|
34
47
|
|
|
35
|
-
if (loading) return <div className="empty-state">
|
|
48
|
+
if (loading) return <div className="empty-state" role="status">{copy.cartLoading}</div>
|
|
36
49
|
const items = cartItems(cart)
|
|
37
50
|
if (!cart || !items.length) {
|
|
38
51
|
return (
|
|
39
52
|
<div className="empty-state stack-sm">
|
|
40
|
-
<strong>
|
|
41
|
-
<span className="muted">
|
|
42
|
-
<Link className="button inline-button" href={
|
|
43
|
-
|
|
53
|
+
<strong>{copy.emptyCart}</strong>
|
|
54
|
+
<span className="muted">{copy.chooseProduct}</span>
|
|
55
|
+
<Link className="button inline-button" href={routes.products} onClick={() => setDrawerOpen(false)}>
|
|
56
|
+
{copy.viewProducts}
|
|
44
57
|
</Link>
|
|
45
58
|
</div>
|
|
46
59
|
)
|
|
@@ -51,30 +64,58 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
|
|
|
51
64
|
? cart.promotions.filter((item): item is Record<string, unknown> => Boolean(item && typeof item === "object"))
|
|
52
65
|
: []
|
|
53
66
|
|
|
67
|
+
const reportError = (cause: unknown) => {
|
|
68
|
+
const message = humanizeStorefrontError(cause, locale)
|
|
69
|
+
showToast({ message, tone: "error" })
|
|
70
|
+
}
|
|
71
|
+
|
|
54
72
|
return (
|
|
55
73
|
<div className="stack">
|
|
56
|
-
<div className="cart-lines">
|
|
74
|
+
<div className="cart-lines" aria-live="polite">
|
|
57
75
|
{items.map((item) => {
|
|
58
76
|
const id = stringValue(item.id)
|
|
59
77
|
const quantity = Math.max(1, numberValue(item.quantity, 1))
|
|
60
78
|
const thumbnail = stringValue(item.thumbnail)
|
|
79
|
+
const title = stringValue(item.product_title || item.title)
|
|
80
|
+
const variantId = stringValue(item.variant_id)
|
|
61
81
|
return (
|
|
62
82
|
<div className="cart-line" key={id}>
|
|
63
83
|
<div className="cart-line-image">
|
|
64
|
-
{thumbnail ? <img src={thumbnail} alt="" /> : <span />}
|
|
84
|
+
{thumbnail ? <img src={thumbnail} alt={title} loading="lazy" /> : <span className="media-placeholder" aria-hidden="true" />}
|
|
65
85
|
</div>
|
|
66
86
|
<div className="cart-line-copy">
|
|
67
|
-
<strong>{
|
|
87
|
+
<strong>{title}</strong>
|
|
68
88
|
{item.variant_title ? <span className="muted">{stringValue(item.variant_title)}</span> : null}
|
|
69
|
-
<span>{formatMoney(lineTotal(item), currency,
|
|
70
|
-
</div>
|
|
71
|
-
<div className="quantity-control">
|
|
72
|
-
<button type="button" disabled={mutating} onClick={() => void updateItem(id, quantity - 1)} aria-label="Mennyiség csökkentése">−</button>
|
|
73
|
-
<span>{quantity}</span>
|
|
74
|
-
<button type="button" disabled={mutating} onClick={() => void updateItem(id, quantity + 1)} aria-label="Mennyiség növelése">+</button>
|
|
89
|
+
<span>{formatMoney(lineTotal(item), currency, formatLocale)}</span>
|
|
75
90
|
</div>
|
|
76
|
-
<
|
|
77
|
-
|
|
91
|
+
<QuantityStepper
|
|
92
|
+
value={quantity}
|
|
93
|
+
min={1}
|
|
94
|
+
max={999}
|
|
95
|
+
disabled={mutating}
|
|
96
|
+
label={locale === "en" ? `Quantity for ${title}` : `${title} mennyisége`}
|
|
97
|
+
decreaseLabel={locale === "en" ? `Decrease quantity for ${title}` : `${title} mennyiségének csökkentése`}
|
|
98
|
+
increaseLabel={locale === "en" ? `Increase quantity for ${title}` : `${title} mennyiségének növelése`}
|
|
99
|
+
onChange={(next) => void updateItem(id, next).catch(reportError)}
|
|
100
|
+
/>
|
|
101
|
+
<button
|
|
102
|
+
className="text-button danger"
|
|
103
|
+
type="button"
|
|
104
|
+
disabled={mutating}
|
|
105
|
+
onClick={() => {
|
|
106
|
+
void removeItem(id)
|
|
107
|
+
.then(() => {
|
|
108
|
+
showToast({
|
|
109
|
+
message: locale === "en" ? "Item removed from cart." : "A terméket eltávolítottuk a kosárból.",
|
|
110
|
+
tone: "info",
|
|
111
|
+
actionLabel: variantId ? (locale === "en" ? "Undo" : "Visszavonás") : undefined,
|
|
112
|
+
onAction: variantId ? () => addItem(variantId, quantity) : undefined,
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
.catch(reportError)
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
{copy.remove}
|
|
78
119
|
</button>
|
|
79
120
|
</div>
|
|
80
121
|
)
|
|
@@ -83,20 +124,43 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
|
|
|
83
124
|
|
|
84
125
|
{!compact ? (
|
|
85
126
|
<div className="panel stack-sm">
|
|
86
|
-
<strong>
|
|
127
|
+
<strong>{copy.couponCode}</strong>
|
|
87
128
|
<div className="inline-form">
|
|
88
|
-
<input
|
|
89
|
-
|
|
90
|
-
|
|
129
|
+
<input
|
|
130
|
+
value={promo}
|
|
131
|
+
onChange={(event) => setPromo(event.target.value)}
|
|
132
|
+
placeholder={copy.couponCode}
|
|
133
|
+
aria-label={copy.couponCode}
|
|
134
|
+
autoComplete="off"
|
|
135
|
+
/>
|
|
136
|
+
<button
|
|
137
|
+
className="button secondary"
|
|
138
|
+
type="button"
|
|
139
|
+
disabled={mutating || !promo.trim()}
|
|
140
|
+
aria-busy={mutating}
|
|
141
|
+
onClick={() => void addPromotion(promo)
|
|
142
|
+
.then(() => {
|
|
143
|
+
setPromo("")
|
|
144
|
+
showToast({ message: locale === "en" ? "Coupon applied." : "Kuponkód alkalmazva.", tone: "success" })
|
|
145
|
+
})
|
|
146
|
+
.catch(reportError)}
|
|
147
|
+
>
|
|
148
|
+
{copy.redeem}
|
|
91
149
|
</button>
|
|
92
150
|
</div>
|
|
93
151
|
{promotions.length ? (
|
|
94
|
-
<div className="chip-row">
|
|
152
|
+
<div className="chip-row" aria-label={locale === "en" ? "Applied promotions" : "Alkalmazott kedvezmények"}>
|
|
95
153
|
{promotions.map((promotion) => {
|
|
96
154
|
const code = stringValue(promotion.code)
|
|
97
155
|
return (
|
|
98
|
-
<button
|
|
99
|
-
|
|
156
|
+
<button
|
|
157
|
+
className="chip"
|
|
158
|
+
key={stringValue(promotion.id || code)}
|
|
159
|
+
type="button"
|
|
160
|
+
aria-label={locale === "en" ? `Remove promotion ${code}` : `${code} kedvezmény eltávolítása`}
|
|
161
|
+
onClick={() => void removePromotion(code).catch(reportError)}
|
|
162
|
+
>
|
|
163
|
+
{code || copy.discount} ×
|
|
100
164
|
</button>
|
|
101
165
|
)
|
|
102
166
|
})}
|
|
@@ -105,21 +169,21 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
|
|
|
105
169
|
</div>
|
|
106
170
|
) : null}
|
|
107
171
|
|
|
108
|
-
<div className="totals">
|
|
109
|
-
<TotalRow label=
|
|
110
|
-
{cartDiscountTotal(cart) ? <TotalRow label=
|
|
111
|
-
<TotalRow label=
|
|
112
|
-
{cartTaxTotal(cart) ? <TotalRow label=
|
|
113
|
-
<TotalRow label=
|
|
172
|
+
<div className="totals" aria-live="polite">
|
|
173
|
+
<TotalRow label={copy.subtotal} value={cartSubtotal(cart)} currency={currency} locale={formatLocale} />
|
|
174
|
+
{cartDiscountTotal(cart) ? <TotalRow label={copy.discount} value={-cartDiscountTotal(cart)} currency={currency} locale={formatLocale} /> : null}
|
|
175
|
+
<TotalRow label={copy.shipping} value={cartShippingTotal(cart)} currency={currency} locale={formatLocale} />
|
|
176
|
+
{cartTaxTotal(cart) ? <TotalRow label={copy.tax} value={cartTaxTotal(cart)} currency={currency} locale={formatLocale} subtle /> : null}
|
|
177
|
+
<TotalRow label={copy.total} value={cartTotal(cart)} currency={currency} locale={formatLocale} strong />
|
|
114
178
|
</div>
|
|
115
179
|
|
|
116
|
-
{error ? <p className="error">{error}</p> : null}
|
|
180
|
+
{error ? <p className="error" role="alert">{humanizeStorefrontError(new Error(error), locale)}</p> : null}
|
|
117
181
|
|
|
118
182
|
<div className="button-row">
|
|
119
183
|
{compact ? (
|
|
120
|
-
<Link className="button secondary" href=
|
|
184
|
+
<Link className="button secondary" href={routes.cart} onClick={() => setDrawerOpen(false)}>{copy.cart}</Link>
|
|
121
185
|
) : null}
|
|
122
|
-
<Link className="button" href=
|
|
186
|
+
<Link className="button" href={routes.checkout} onClick={() => setDrawerOpen(false)}>{copy.checkoutContinue}</Link>
|
|
123
187
|
</div>
|
|
124
188
|
</div>
|
|
125
189
|
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useMemo, useRef } from "react"
|
|
4
|
+
import { useCart } from "./cart-provider"
|
|
5
|
+
import { checkoutApi } from "@/lib/core/checkout"
|
|
6
|
+
import type { CoreConfig } from "@/lib/core/types"
|
|
7
|
+
|
|
8
|
+
export function CheckoutAnalytics({ config }: { config: CoreConfig }) {
|
|
9
|
+
const api = useMemo(() => checkoutApi(config), [config])
|
|
10
|
+
const { cart, cartId } = useCart()
|
|
11
|
+
const trackedCart = useRef<string | null>(null)
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (!cart || !cartId || trackedCart.current === cartId) return
|
|
15
|
+
|
|
16
|
+
trackedCart.current = cartId
|
|
17
|
+
void api.beginCheckout(cartId).catch(() => {
|
|
18
|
+
if (trackedCart.current === cartId) trackedCart.current = null
|
|
19
|
+
})
|
|
20
|
+
}, [api, cart, cartId])
|
|
21
|
+
|
|
22
|
+
return null
|
|
23
|
+
}
|