create-nymbal-app 0.4.0 → 0.6.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/dist/index.d.ts +2 -1
- package/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/scaffold/project/astro/src/pages/index.astro +13 -15
- package/scaffold/templates/astro/_dot.node-version +1 -1
- package/scaffold/templates/astro/astro.config.mjs +23 -0
- package/scaffold/templates/astro/package.json +26 -26
- package/scaffold/templates/astro/src/components/SkipNav.astro +3 -1
- package/scaffold/templates/astro/src/elements/index.ts +11 -0
- package/scaffold/templates/astro/src/layouts/BaseLayout.astro +15 -4
- package/scaffold/templates/astro/src/lib/api.ts +162 -38
- package/scaffold/templates/astro/src/lib/chrome.ts +59 -0
- package/scaffold/templates/astro/src/lib/client.ts +4 -4
- package/scaffold/templates/astro/src/lib/fragments.ts +48 -0
- package/scaffold/templates/astro/src/lib/server-elements.ts +5 -0
- package/scaffold/templates/astro/src/middleware.ts +37 -0
- package/scaffold/templates/astro/src/pages/404.astro +3 -0
- package/scaffold/templates/astro/src/pages/account/addresses.astro +5 -97
- package/scaffold/templates/astro/src/pages/account/login.astro +7 -34
- package/scaffold/templates/astro/src/pages/account/orders/[orderNumber].astro +11 -3
- package/scaffold/templates/astro/src/pages/account/profile.astro +6 -56
- package/scaffold/templates/astro/src/pages/account/register.astro +7 -73
- package/scaffold/templates/astro/src/pages/alerts/confirm.astro +59 -0
- package/scaffold/templates/astro/src/pages/alerts/unsubscribe.astro +53 -0
- package/scaffold/templates/astro/src/pages/cart.astro +14 -7
- package/scaffold/templates/astro/src/pages/category/[slug].astro +25 -27
- package/scaffold/templates/astro/src/pages/checkout.astro +30 -94
- package/scaffold/templates/astro/src/pages/fragments/footer.astro +5 -2
- package/scaffold/templates/astro/src/pages/fragments/header.astro +12 -2
- package/scaffold/templates/astro/src/pages/fragments/nav.astro +8 -5
- package/scaffold/templates/astro/src/pages/fragments/product/[slug].astro +9 -10
- package/scaffold/templates/astro/src/pages/index.astro +25 -15
- package/scaffold/templates/astro/src/pages/order/[orderNumber].astro +34 -45
- package/scaffold/templates/astro/src/pages/product/[slug].astro +64 -34
- package/scaffold/templates/astro/src/pages/products/index.astro +16 -21
- package/scaffold/templates/astro/src/pages/search.astro +10 -11
- package/scaffold/templates/astro/src/scripts/init-client.ts +14 -0
- package/scaffold/templates/astro/src/scripts/order-status.ts +3 -1
- package/scaffold/templates/astro/src/scripts/pdp.ts +29 -21
- package/scaffold/templates/astro/src/scripts/plp.ts +15 -93
- package/scaffold/templates/astro/src/scripts/search.ts +7 -132
- package/scaffold/templates/astro/src/scripts/signed-in-redirect.ts +4 -0
- package/scaffold/templates/astro/src/styles/global.css +49 -45
- package/scaffold/templates/astro/src/styles/pages/account.css +4 -90
- package/scaffold/templates/astro/src/styles/pages/confirmation.css +6 -0
- package/scaffold/templates/astro/src/styles/pages/home.css +9 -100
- package/scaffold/templates/astro/src/styles/pages/pdp.css +5 -171
- package/scaffold/templates/astro/src/styles/pages/plp.css +3 -42
- package/scaffold/templates/astro/src/styles/pages/search.css +4 -110
- package/scaffold/templates/astro/src/styles/tokens.css +56 -0
- package/scaffold/templates/nextjs/_dot.node-version +1 -1
- package/scaffold/templates/nextjs/app/(catalog)/category/[slug]/page.tsx +74 -0
- package/scaffold/templates/nextjs/app/(catalog)/home/[key]/page.tsx +85 -0
- package/scaffold/templates/nextjs/app/(catalog)/layout.tsx +13 -0
- package/scaffold/templates/nextjs/app/(catalog)/not-found.tsx +7 -0
- package/scaffold/templates/nextjs/app/(catalog)/product/[slug]/page.tsx +201 -0
- package/scaffold/templates/nextjs/app/(catalog)/products/page.tsx +62 -0
- package/scaffold/templates/nextjs/app/(catalog)/search/SearchView.tsx +90 -0
- package/scaffold/templates/nextjs/app/(catalog)/search/page.tsx +46 -0
- package/scaffold/templates/nextjs/app/(shopper)/account/addresses/AddressesView.tsx +5 -0
- package/scaffold/templates/nextjs/app/(shopper)/account/addresses/page.tsx +17 -0
- package/scaffold/templates/nextjs/app/(shopper)/account/login/LoginView.tsx +28 -0
- package/scaffold/templates/nextjs/app/(shopper)/account/login/page.tsx +23 -0
- package/scaffold/templates/nextjs/app/{account → (shopper)/account}/orders/[orderNumber]/page.tsx +10 -3
- package/scaffold/templates/nextjs/app/(shopper)/account/profile/ProfileView.tsx +5 -0
- package/scaffold/templates/nextjs/app/(shopper)/account/profile/page.tsx +20 -0
- package/scaffold/templates/nextjs/app/(shopper)/account/register/RegisterView.tsx +26 -0
- package/scaffold/templates/nextjs/app/(shopper)/account/register/page.tsx +11 -0
- package/scaffold/templates/nextjs/app/(shopper)/alerts/AlertLinkForm.tsx +90 -0
- package/scaffold/templates/nextjs/app/(shopper)/alerts/LinkInvalid.tsx +19 -0
- package/scaffold/templates/nextjs/app/(shopper)/alerts/actions.ts +33 -0
- package/scaffold/templates/nextjs/app/(shopper)/alerts/confirm/page.tsx +19 -0
- package/scaffold/templates/nextjs/app/(shopper)/alerts/unsubscribe/page.tsx +17 -0
- package/scaffold/templates/nextjs/app/(shopper)/cart/CartView.tsx +5 -0
- package/scaffold/templates/nextjs/app/(shopper)/cart/page.tsx +22 -0
- package/scaffold/templates/nextjs/app/(shopper)/checkout/CheckoutView.tsx +34 -0
- package/scaffold/templates/nextjs/app/(shopper)/checkout/page.tsx +39 -0
- package/scaffold/templates/nextjs/app/(shopper)/layout.tsx +12 -0
- package/scaffold/templates/nextjs/app/(shopper)/not-found.tsx +6 -0
- package/scaffold/templates/nextjs/app/{order → (shopper)/order}/[orderNumber]/page.tsx +44 -9
- package/scaffold/templates/nextjs/app/error.tsx +3 -7
- package/scaffold/templates/nextjs/app/fragments/footer/route.ts +13 -0
- package/scaffold/templates/nextjs/app/fragments/header/[key]/route.ts +18 -0
- package/scaffold/templates/nextjs/app/fragments/nav/[key]/route.ts +23 -0
- package/scaffold/templates/nextjs/app/fragments/product/[slug]/route.ts +22 -0
- package/scaffold/templates/nextjs/app/globals.css +5 -23
- package/scaffold/templates/nextjs/app/layout.tsx +8 -5
- package/scaffold/templates/nextjs/app/not-found.tsx +9 -33
- package/scaffold/templates/nextjs/app/tokens.css +56 -0
- package/scaffold/templates/nextjs/components/client/ListingControls.tsx +87 -0
- package/scaffold/templates/nextjs/components/client/NymbalSetup.tsx +48 -6
- package/scaffold/templates/nextjs/components/client/OrderStatusRefresh.tsx +8 -2
- package/scaffold/templates/nextjs/components/client/ProductInteractive.tsx +47 -15
- package/scaffold/templates/nextjs/components/client/elements.tsx +17 -0
- package/scaffold/templates/nextjs/components/server/Header.tsx +33 -102
- package/scaffold/templates/nextjs/components/server/NotFoundView.tsx +39 -0
- package/scaffold/templates/nextjs/components/server/SkipNav.tsx +7 -3
- package/scaffold/templates/nextjs/elements/index.ts +12 -0
- package/scaffold/templates/nextjs/lib/api.ts +198 -62
- package/scaffold/templates/nextjs/lib/chrome.ts +40 -0
- package/scaffold/templates/nextjs/lib/fragments.ts +16 -0
- package/scaffold/templates/nextjs/lib/header.ts +39 -0
- package/scaffold/templates/nextjs/lib/render.ts +14 -0
- package/scaffold/templates/nextjs/next.config.mjs +41 -0
- package/scaffold/templates/nextjs/package.json +28 -27
- package/scaffold/templates/nextjs/styles/pages/account.module.css +0 -70
- package/scaffold/templates/nextjs/styles/pages/confirmation.module.css +6 -85
- package/scaffold/templates/nextjs/styles/pages/home.module.css +2 -103
- package/scaffold/templates/nextjs/styles/pages/pdp.module.css +3 -183
- package/scaffold/templates/nextjs/styles/pages/plp.module.css +9 -143
- package/scaffold/templates/nextjs/styles/pages/search.module.css +1 -145
- package/scaffold/templates/nextjs/tsconfig.dist.json +5 -0
- package/scaffold/templates/astro/src/components/AddressForm.astro +0 -107
- package/scaffold/templates/astro/src/components/Breadcrumb.astro +0 -20
- package/scaffold/templates/astro/src/components/CategoryNav.astro +0 -27
- package/scaffold/templates/astro/src/components/CheckoutSteps.astro +0 -29
- package/scaffold/templates/astro/src/components/Footer.astro +0 -108
- package/scaffold/templates/astro/src/components/Header.astro +0 -198
- package/scaffold/templates/astro/src/components/ImageGallery.astro +0 -42
- package/scaffold/templates/astro/src/components/OrderSummary.astro +0 -53
- package/scaffold/templates/astro/src/components/Pagination.astro +0 -13
- package/scaffold/templates/astro/src/components/PriceDisplay.astro +0 -25
- package/scaffold/templates/astro/src/components/ProductCard.astro +0 -44
- package/scaffold/templates/astro/src/components/RelatedProducts.astro +0 -28
- package/scaffold/templates/astro/src/components/ReviewForm.astro +0 -74
- package/scaffold/templates/astro/src/components/ReviewList.astro +0 -41
- package/scaffold/templates/astro/src/components/StockBadge.astro +0 -15
- package/scaffold/templates/astro/src/scripts/auth-forms.ts +0 -82
- package/scaffold/templates/astro/src/scripts/cart-page.ts +0 -118
- package/scaffold/templates/astro/src/scripts/checkout.ts +0 -271
- package/scaffold/templates/astro/src/scripts/image-gallery.ts +0 -22
- package/scaffold/templates/astro/src/scripts/profile-form.ts +0 -57
- package/scaffold/templates/astro/src/scripts/review-form.ts +0 -27
- package/scaffold/templates/astro/src/styles/pages/cart.css +0 -215
- package/scaffold/templates/astro/src/styles/pages/checkout.css +0 -270
- package/scaffold/templates/nextjs/app/account/addresses/page.tsx +0 -10
- package/scaffold/templates/nextjs/app/account/login/page.tsx +0 -23
- package/scaffold/templates/nextjs/app/account/profile/page.tsx +0 -10
- package/scaffold/templates/nextjs/app/account/register/page.tsx +0 -10
- package/scaffold/templates/nextjs/app/cart/page.tsx +0 -10
- package/scaffold/templates/nextjs/app/category/[slug]/page.tsx +0 -61
- package/scaffold/templates/nextjs/app/checkout/page.tsx +0 -17
- package/scaffold/templates/nextjs/app/page.tsx +0 -63
- package/scaffold/templates/nextjs/app/product/[slug]/page.tsx +0 -111
- package/scaffold/templates/nextjs/app/products/page.tsx +0 -40
- package/scaffold/templates/nextjs/app/search/page.tsx +0 -24
- package/scaffold/templates/nextjs/components/client/AddressManager.tsx +0 -181
- package/scaffold/templates/nextjs/components/client/CartPage.tsx +0 -121
- package/scaffold/templates/nextjs/components/client/CheckoutForm.tsx +0 -482
- package/scaffold/templates/nextjs/components/client/ImageGallery.tsx +0 -68
- package/scaffold/templates/nextjs/components/client/LoginForm.tsx +0 -89
- package/scaffold/templates/nextjs/components/client/MiniCartWrapper.tsx +0 -12
- package/scaffold/templates/nextjs/components/client/ProductGrid.tsx +0 -137
- package/scaffold/templates/nextjs/components/client/ProfileForm.tsx +0 -112
- package/scaffold/templates/nextjs/components/client/RegisterForm.tsx +0 -131
- package/scaffold/templates/nextjs/components/client/ReviewForm.tsx +0 -116
- package/scaffold/templates/nextjs/components/client/SearchBarWrapper.tsx +0 -27
- package/scaffold/templates/nextjs/components/client/SearchResults.tsx +0 -181
- package/scaffold/templates/nextjs/components/server/Breadcrumb.tsx +0 -36
- package/scaffold/templates/nextjs/components/server/CategoryNav.tsx +0 -29
- package/scaffold/templates/nextjs/components/server/CheckoutSteps.tsx +0 -60
- package/scaffold/templates/nextjs/components/server/Footer.module.css +0 -64
- package/scaffold/templates/nextjs/components/server/Footer.tsx +0 -79
- package/scaffold/templates/nextjs/components/server/Header.module.css +0 -147
- package/scaffold/templates/nextjs/components/server/OrderSummary.tsx +0 -79
- package/scaffold/templates/nextjs/components/server/PriceDisplay.tsx +0 -31
- package/scaffold/templates/nextjs/components/server/ProductCard.tsx +0 -59
- package/scaffold/templates/nextjs/components/server/RelatedProducts.tsx +0 -31
- package/scaffold/templates/nextjs/components/server/ReviewList.tsx +0 -62
- package/scaffold/templates/nextjs/styles/pages/cart.module.css +0 -240
- package/scaffold/templates/nextjs/styles/pages/checkout.module.css +0 -404
- /package/scaffold/templates/nextjs/app/{account → (shopper)/account}/layout.tsx +0 -0
- /package/scaffold/templates/nextjs/app/{account → (shopper)/account}/orders/page.tsx +0 -0
- /package/scaffold/templates/nextjs/app/{account → (shopper)/account}/page.tsx +0 -0
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import { formatPrice } from '../lib/format'
|
|
3
|
-
|
|
4
|
-
interface Props {
|
|
5
|
-
items: Array<{ name: string; qty: number; priceMinor: number }>
|
|
6
|
-
subtotalMinor: number
|
|
7
|
-
currency: string
|
|
8
|
-
shippingMinor?: number
|
|
9
|
-
taxMinor?: number
|
|
10
|
-
totalMinor?: number
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const { items, subtotalMinor, currency, shippingMinor, taxMinor, totalMinor } = Astro.props
|
|
14
|
-
const computedTotal = totalMinor ?? subtotalMinor + (shippingMinor ?? 0) + (taxMinor ?? 0)
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
<div class="order-summary" data-testid="order-summary">
|
|
18
|
-
<div class="checkout-summary-items">
|
|
19
|
-
{items.map((item) => (
|
|
20
|
-
<div class="checkout-summary-item">
|
|
21
|
-
<span class="checkout-summary-item-name">{item.name}</span>
|
|
22
|
-
<span class="checkout-summary-item-qty">x{item.qty}</span>
|
|
23
|
-
<span class="checkout-summary-item-price">
|
|
24
|
-
{formatPrice(item.priceMinor * item.qty, currency)}
|
|
25
|
-
</span>
|
|
26
|
-
</div>
|
|
27
|
-
))}
|
|
28
|
-
</div>
|
|
29
|
-
|
|
30
|
-
<dl>
|
|
31
|
-
<div class="checkout-summary-row">
|
|
32
|
-
<dt>Subtotal</dt>
|
|
33
|
-
<dd>{formatPrice(subtotalMinor, currency)}</dd>
|
|
34
|
-
</div>
|
|
35
|
-
{shippingMinor != null && (
|
|
36
|
-
<div class="checkout-summary-row">
|
|
37
|
-
<dt>Shipping</dt>
|
|
38
|
-
<dd>{shippingMinor === 0 ? 'Free' : formatPrice(shippingMinor, currency)}</dd>
|
|
39
|
-
</div>
|
|
40
|
-
)}
|
|
41
|
-
{taxMinor != null && (
|
|
42
|
-
<div class="checkout-summary-row">
|
|
43
|
-
<dt>Tax</dt>
|
|
44
|
-
<dd>{formatPrice(taxMinor, currency)}</dd>
|
|
45
|
-
</div>
|
|
46
|
-
)}
|
|
47
|
-
</dl>
|
|
48
|
-
|
|
49
|
-
<div class="checkout-summary-total">
|
|
50
|
-
<span>Total</span>
|
|
51
|
-
<span>{formatPrice(computedTotal, currency)}</span>
|
|
52
|
-
</div>
|
|
53
|
-
</div>
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import { formatPrice } from '../lib/format'
|
|
3
|
-
|
|
4
|
-
interface Props {
|
|
5
|
-
priceMinor: number
|
|
6
|
-
currency: string
|
|
7
|
-
compareAtMinor?: number
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const { priceMinor, currency, compareAtMinor } = Astro.props
|
|
11
|
-
const price = formatPrice(priceMinor, currency)
|
|
12
|
-
const comparePrice = compareAtMinor ? formatPrice(compareAtMinor, currency) : null
|
|
13
|
-
const isOnSale = compareAtMinor != null && compareAtMinor > priceMinor
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
<div class="pdp-price" data-testid="product-price">
|
|
17
|
-
{isOnSale && comparePrice && (
|
|
18
|
-
<span
|
|
19
|
-
style="text-decoration: line-through; color: var(--nymbal-color-text-muted, #71717a); font-weight: var(--nymbal-font-weight-normal, 400); margin-right: var(--nymbal-spacing-sm, 0.5rem);"
|
|
20
|
-
>
|
|
21
|
-
{comparePrice}
|
|
22
|
-
</span>
|
|
23
|
-
)}
|
|
24
|
-
<span>{price}</span>
|
|
25
|
-
</div>
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import { formatPrice } from '../lib/format'
|
|
3
|
-
|
|
4
|
-
interface Props {
|
|
5
|
-
product: {
|
|
6
|
-
slug: string
|
|
7
|
-
name: string
|
|
8
|
-
priceMinor: number | null
|
|
9
|
-
priceRange?: { minMinor: number } | null
|
|
10
|
-
currency: string | null
|
|
11
|
-
media: any
|
|
12
|
-
imageUrl?: string
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const { product } = Astro.props
|
|
17
|
-
const imageUrl =
|
|
18
|
-
product.imageUrl ??
|
|
19
|
-
(Array.isArray(product.media) && product.media[0]?.url) ??
|
|
20
|
-
`https://picsum.photos/seed/${product.slug}/600/600`
|
|
21
|
-
// The "from" price, which the price sorts order by.
|
|
22
|
-
const fromMinor = product.priceRange?.minMinor ?? product.priceMinor
|
|
23
|
-
const price =
|
|
24
|
-
fromMinor != null ? formatPrice(fromMinor, product.currency ?? 'GBP') : ''
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
<a
|
|
28
|
-
href={`/product/${product.slug}`}
|
|
29
|
-
class="product-card"
|
|
30
|
-
data-testid={`product-card-${product.slug}`}
|
|
31
|
-
>
|
|
32
|
-
<img
|
|
33
|
-
src={imageUrl}
|
|
34
|
-
alt={product.name}
|
|
35
|
-
class="product-card-image"
|
|
36
|
-
loading="lazy"
|
|
37
|
-
width="600"
|
|
38
|
-
height="600"
|
|
39
|
-
/>
|
|
40
|
-
<div class="product-card-body">
|
|
41
|
-
<span class="product-card-name">{product.name}</span>
|
|
42
|
-
{price && <span class="product-card-price">{price}</span>}
|
|
43
|
-
</div>
|
|
44
|
-
</a>
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import ProductCard from './ProductCard.astro'
|
|
3
|
-
|
|
4
|
-
interface Props {
|
|
5
|
-
products: Array<{
|
|
6
|
-
slug: string
|
|
7
|
-
name: string
|
|
8
|
-
priceMinor: number | null
|
|
9
|
-
currency: string | null
|
|
10
|
-
media: any
|
|
11
|
-
imageUrl?: string
|
|
12
|
-
}>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const { products } = Astro.props
|
|
16
|
-
const displayProducts = products.slice(0, 4)
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
{displayProducts.length > 0 && (
|
|
20
|
-
<section class="section" data-testid="related-products">
|
|
21
|
-
<h2 class="section-title">You may also like</h2>
|
|
22
|
-
<div class="product-grid">
|
|
23
|
-
{displayProducts.map((product) => (
|
|
24
|
-
<ProductCard product={product} />
|
|
25
|
-
))}
|
|
26
|
-
</div>
|
|
27
|
-
</section>
|
|
28
|
-
)}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
interface Props {
|
|
3
|
-
productId: string
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
const { productId } = Astro.props
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
<form
|
|
10
|
-
class="review-form"
|
|
11
|
-
id="review-form"
|
|
12
|
-
data-product-id={productId}
|
|
13
|
-
data-testid="review-form"
|
|
14
|
-
>
|
|
15
|
-
<h3 style="font-size: 1.125rem; font-weight: var(--nymbal-font-weight-bold, 700); margin-bottom: var(--nymbal-spacing-md, 1rem);">
|
|
16
|
-
Write a Review
|
|
17
|
-
</h3>
|
|
18
|
-
|
|
19
|
-
<div class="form-group">
|
|
20
|
-
<label for="review-rating">Rating</label>
|
|
21
|
-
<select id="review-rating" name="rating" required data-testid="review-rating">
|
|
22
|
-
<option value="">Select a rating</option>
|
|
23
|
-
<option value="5">5 - Excellent</option>
|
|
24
|
-
<option value="4">4 - Very Good</option>
|
|
25
|
-
<option value="3">3 - Good</option>
|
|
26
|
-
<option value="2">2 - Fair</option>
|
|
27
|
-
<option value="1">1 - Poor</option>
|
|
28
|
-
</select>
|
|
29
|
-
</div>
|
|
30
|
-
|
|
31
|
-
<div class="form-group">
|
|
32
|
-
<label for="review-title">Title</label>
|
|
33
|
-
<input
|
|
34
|
-
type="text"
|
|
35
|
-
id="review-title"
|
|
36
|
-
name="title"
|
|
37
|
-
placeholder="Summarise your experience"
|
|
38
|
-
required
|
|
39
|
-
data-testid="review-title"
|
|
40
|
-
/>
|
|
41
|
-
</div>
|
|
42
|
-
|
|
43
|
-
<div class="form-group">
|
|
44
|
-
<label for="review-body">Review</label>
|
|
45
|
-
<textarea
|
|
46
|
-
id="review-body"
|
|
47
|
-
name="body"
|
|
48
|
-
rows="4"
|
|
49
|
-
placeholder="Tell us what you think..."
|
|
50
|
-
required
|
|
51
|
-
data-testid="review-body"
|
|
52
|
-
style="resize: vertical;"
|
|
53
|
-
></textarea>
|
|
54
|
-
</div>
|
|
55
|
-
|
|
56
|
-
<button type="submit" class="btn btn-primary" data-testid="review-submit">
|
|
57
|
-
Submit Review
|
|
58
|
-
</button>
|
|
59
|
-
|
|
60
|
-
<p class="review-form-message" id="review-form-message" style="display:none; margin-top: var(--nymbal-spacing-md, 1rem); font-size: var(--nymbal-font-size-sm, 0.875rem);"></p>
|
|
61
|
-
</form>
|
|
62
|
-
|
|
63
|
-
<script>
|
|
64
|
-
import '../scripts/review-form.js'
|
|
65
|
-
</script>
|
|
66
|
-
|
|
67
|
-
<style>
|
|
68
|
-
.review-form {
|
|
69
|
-
margin-top: var(--nymbal-spacing-xl, 2rem);
|
|
70
|
-
padding-top: var(--nymbal-spacing-xl, 2rem);
|
|
71
|
-
border-top: 1px solid var(--nymbal-color-border, #e4e4e7);
|
|
72
|
-
max-width: 32rem;
|
|
73
|
-
}
|
|
74
|
-
</style>
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import '../styles/pages/pdp.css'
|
|
3
|
-
import { formatDate } from '../lib/format'
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
reviews: Array<{
|
|
7
|
-
id: string
|
|
8
|
-
rating: number
|
|
9
|
-
title: string
|
|
10
|
-
body: string
|
|
11
|
-
submittedAt: string
|
|
12
|
-
}>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const { reviews } = Astro.props
|
|
16
|
-
|
|
17
|
-
function renderStars(rating: number): string {
|
|
18
|
-
const filled = '★'
|
|
19
|
-
const empty = '☆'
|
|
20
|
-
return filled.repeat(rating) + empty.repeat(5 - rating)
|
|
21
|
-
}
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
{reviews.length > 0 ? (
|
|
25
|
-
<div class="review-list" data-testid="review-list">
|
|
26
|
-
{reviews.map((review) => (
|
|
27
|
-
<div class="review-item" data-testid={`review-${review.id}`}>
|
|
28
|
-
<div class="review-header">
|
|
29
|
-
<span class="review-rating" aria-label={`${review.rating} out of 5 stars`}>
|
|
30
|
-
{renderStars(review.rating)}
|
|
31
|
-
</span>
|
|
32
|
-
<span class="review-date">{formatDate(review.submittedAt)}</span>
|
|
33
|
-
</div>
|
|
34
|
-
<h4 class="review-title">{review.title}</h4>
|
|
35
|
-
<p class="review-body">{review.body}</p>
|
|
36
|
-
</div>
|
|
37
|
-
))}
|
|
38
|
-
</div>
|
|
39
|
-
) : (
|
|
40
|
-
<p class="reviews-empty">No reviews yet. Be the first to review this product.</p>
|
|
41
|
-
)}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import { STOCK_LABELS, stockLevel } from '@nymbalhq/types'
|
|
3
|
-
|
|
4
|
-
interface Props {
|
|
5
|
-
stock: number
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const { stock } = Astro.props
|
|
9
|
-
const level = stockLevel(stock)
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
<span class="pdp-stock" data-testid="stock-badge" data-level={level}>
|
|
13
|
-
<span class="pdp-stock-dot" aria-hidden="true"></span>
|
|
14
|
-
<span data-stock-label>{STOCK_LABELS[level]}</span>
|
|
15
|
-
</span>
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { client } from '../lib/client.js'
|
|
2
|
-
import { submitOnce } from '../lib/submit-once.js'
|
|
3
|
-
|
|
4
|
-
function getRedirectUrl(): string {
|
|
5
|
-
const params = new URLSearchParams(window.location.search)
|
|
6
|
-
return params.get('redirect') ?? '/account'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function showFormError(formId: string, message: string) {
|
|
10
|
-
const errorEl = document.getElementById(`${formId}-error`)
|
|
11
|
-
if (errorEl) {
|
|
12
|
-
errorEl.textContent = message
|
|
13
|
-
errorEl.style.display = 'block'
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function hideFormError(formId: string) {
|
|
18
|
-
const errorEl = document.getElementById(`${formId}-error`)
|
|
19
|
-
if (errorEl) {
|
|
20
|
-
errorEl.style.display = 'none'
|
|
21
|
-
errorEl.textContent = ''
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Login form handler
|
|
26
|
-
const loginForm = document.getElementById('login-form') as HTMLFormElement | null
|
|
27
|
-
submitOnce(loginForm, async () => {
|
|
28
|
-
hideFormError('login')
|
|
29
|
-
|
|
30
|
-
const email = (document.getElementById('login-email') as HTMLInputElement)?.value
|
|
31
|
-
const password = (document.getElementById('login-password') as HTMLInputElement)?.value
|
|
32
|
-
|
|
33
|
-
if (!email || !password) {
|
|
34
|
-
showFormError('login', 'Please enter your email and password.')
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const submitBtn = loginForm?.querySelector(
|
|
39
|
-
'[data-testid="login-submit"]',
|
|
40
|
-
) as HTMLButtonElement | null
|
|
41
|
-
if (submitBtn) submitBtn.textContent = 'Signing in...'
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
await client.auth.login(email, password)
|
|
45
|
-
window.location.href = getRedirectUrl()
|
|
46
|
-
return 'leaving'
|
|
47
|
-
} catch (err: any) {
|
|
48
|
-
showFormError('login', err.message ?? 'Invalid email or password.')
|
|
49
|
-
if (submitBtn) submitBtn.textContent = 'Sign In'
|
|
50
|
-
}
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
// Register form handler
|
|
54
|
-
const registerForm = document.getElementById('register-form') as HTMLFormElement | null
|
|
55
|
-
submitOnce(registerForm, async () => {
|
|
56
|
-
hideFormError('register')
|
|
57
|
-
|
|
58
|
-
const email = (document.getElementById('register-email') as HTMLInputElement)?.value
|
|
59
|
-
const password = (document.getElementById('register-password') as HTMLInputElement)?.value
|
|
60
|
-
const firstName = (document.getElementById('register-firstName') as HTMLInputElement)?.value
|
|
61
|
-
const lastName = (document.getElementById('register-lastName') as HTMLInputElement)?.value
|
|
62
|
-
const phone = (document.getElementById('register-phone') as HTMLInputElement)?.value
|
|
63
|
-
|
|
64
|
-
if (!email || !password) {
|
|
65
|
-
showFormError('register', 'Please enter your email and password.')
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const submitBtn = registerForm?.querySelector(
|
|
70
|
-
'[data-testid="register-submit"]',
|
|
71
|
-
) as HTMLButtonElement | null
|
|
72
|
-
if (submitBtn) submitBtn.textContent = 'Creating account...'
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
await client.auth.register({ email, password, firstName, lastName, phone })
|
|
76
|
-
window.location.href = getRedirectUrl()
|
|
77
|
-
return 'leaving'
|
|
78
|
-
} catch (err: any) {
|
|
79
|
-
showFormError('register', err.message ?? 'Registration failed. Please try again.')
|
|
80
|
-
if (submitBtn) submitBtn.textContent = 'Create Account'
|
|
81
|
-
}
|
|
82
|
-
})
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { client } from '../lib/client.js'
|
|
2
|
-
import { formatPrice } from '../lib/format.js'
|
|
3
|
-
|
|
4
|
-
const container = document.getElementById('cart-content')
|
|
5
|
-
if (!container) throw new Error('Missing #cart-content')
|
|
6
|
-
|
|
7
|
-
function renderCart() {
|
|
8
|
-
const state = client.cart.getState()
|
|
9
|
-
const items = state.items ?? []
|
|
10
|
-
const currency = state.currency || 'GBP'
|
|
11
|
-
|
|
12
|
-
if (items.length === 0) {
|
|
13
|
-
container!.innerHTML = `
|
|
14
|
-
<div class="cart-empty">
|
|
15
|
-
<h1 class="cart-empty-title">Your cart is empty</h1>
|
|
16
|
-
<p class="cart-empty-text">Looks like you haven't added anything yet.</p>
|
|
17
|
-
<a href="/products" class="btn btn-primary" data-testid="continue-shopping">Continue Shopping</a>
|
|
18
|
-
</div>
|
|
19
|
-
`
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const subtotal = items.reduce((sum: number, item: any) => sum + item.priceMinor * item.qty, 0)
|
|
24
|
-
|
|
25
|
-
const itemsHtml = items
|
|
26
|
-
.map(
|
|
27
|
-
(item: any) => `
|
|
28
|
-
<div class="cart-line-item" data-testid="cart-item-${item.variantId}">
|
|
29
|
-
<img
|
|
30
|
-
src="${item.imageUrl || `https://picsum.photos/seed/${item.productId}/200/200`}"
|
|
31
|
-
alt="${item.productName}"
|
|
32
|
-
class="cart-line-image"
|
|
33
|
-
width="100"
|
|
34
|
-
height="100"
|
|
35
|
-
loading="lazy"
|
|
36
|
-
/>
|
|
37
|
-
<div class="cart-line-info">
|
|
38
|
-
<a href="/product/${item.productId}" class="cart-line-name">${item.productName}</a>
|
|
39
|
-
${item.variantName ? `<span class="cart-line-variant">${item.variantName}</span>` : ''}
|
|
40
|
-
<span class="cart-line-price-each">${formatPrice(item.priceMinor, currency)} each</span>
|
|
41
|
-
<button
|
|
42
|
-
type="button"
|
|
43
|
-
class="cart-line-remove"
|
|
44
|
-
data-variant-id="${item.variantId}"
|
|
45
|
-
data-testid="cart-remove-${item.variantId}"
|
|
46
|
-
>
|
|
47
|
-
Remove
|
|
48
|
-
</button>
|
|
49
|
-
</div>
|
|
50
|
-
<div class="cart-line-quantity">
|
|
51
|
-
<nymbal-quantity-selector
|
|
52
|
-
value="${item.qty}"
|
|
53
|
-
min="1"
|
|
54
|
-
max="99"
|
|
55
|
-
data-variant-id="${item.variantId}"
|
|
56
|
-
></nymbal-quantity-selector>
|
|
57
|
-
</div>
|
|
58
|
-
<span class="cart-line-total">${formatPrice(item.priceMinor * item.qty, currency)}</span>
|
|
59
|
-
</div>
|
|
60
|
-
`,
|
|
61
|
-
)
|
|
62
|
-
.join('')
|
|
63
|
-
|
|
64
|
-
container!.innerHTML = `
|
|
65
|
-
<div class="cart-layout">
|
|
66
|
-
<div>
|
|
67
|
-
<div class="cart-header">
|
|
68
|
-
<h1 class="cart-title">Your Cart <span class="cart-item-count">(${items.length} ${items.length === 1 ? 'item' : 'items'})</span></h1>
|
|
69
|
-
</div>
|
|
70
|
-
<div class="cart-items" data-testid="cart-items">
|
|
71
|
-
${itemsHtml}
|
|
72
|
-
</div>
|
|
73
|
-
</div>
|
|
74
|
-
<div class="cart-summary" data-testid="cart-summary">
|
|
75
|
-
<h2 class="cart-summary-title">Order Summary</h2>
|
|
76
|
-
<dl>
|
|
77
|
-
<div class="cart-summary-row">
|
|
78
|
-
<dt>Subtotal</dt>
|
|
79
|
-
<dd>${formatPrice(subtotal, currency)}</dd>
|
|
80
|
-
</div>
|
|
81
|
-
<div class="cart-summary-row">
|
|
82
|
-
<dt>Shipping</dt>
|
|
83
|
-
<dd>Calculated at checkout</dd>
|
|
84
|
-
</div>
|
|
85
|
-
</dl>
|
|
86
|
-
<div class="cart-summary-total">
|
|
87
|
-
<span>Estimated Total</span>
|
|
88
|
-
<span>${formatPrice(subtotal, currency)}</span>
|
|
89
|
-
</div>
|
|
90
|
-
<div class="cart-summary-actions">
|
|
91
|
-
<a href="/checkout" class="btn btn-primary" data-testid="checkout-btn">Proceed to Checkout</a>
|
|
92
|
-
<a href="/products" class="btn btn-secondary">Continue Shopping</a>
|
|
93
|
-
</div>
|
|
94
|
-
</div>
|
|
95
|
-
</div>
|
|
96
|
-
`
|
|
97
|
-
|
|
98
|
-
bindCartActions()
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function bindCartActions() {
|
|
102
|
-
container!.querySelectorAll('.cart-line-remove').forEach((btn) => {
|
|
103
|
-
btn.addEventListener('click', () => {
|
|
104
|
-
const variantId = (btn as HTMLElement).dataset.variantId
|
|
105
|
-
if (variantId) client.cart.removeItem(variantId)
|
|
106
|
-
})
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
container!.querySelectorAll<HTMLElement>('nymbal-quantity-selector').forEach((selector) => {
|
|
110
|
-
selector.addEventListener('nymbal:quantity:changed', ((e: CustomEvent<{ value: number }>) => {
|
|
111
|
-
const variantId = selector.dataset.variantId
|
|
112
|
-
if (variantId) client.cart.updateQuantity(variantId, e.detail.value)
|
|
113
|
-
}) as EventListener)
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
client.cart.subscribe(renderCart)
|
|
118
|
-
renderCart()
|