create-nymbal-app 0.5.0 → 0.7.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.js +12 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/scaffold/templates/astro/astro.config.mjs +3 -0
- package/scaffold/templates/astro/package.json +25 -25
- package/scaffold/templates/astro/src/layouts/AccountLayout.astro +1 -0
- package/scaffold/templates/astro/src/layouts/BaseLayout.astro +3 -1
- package/scaffold/templates/astro/src/lib/api.ts +64 -22
- package/scaffold/templates/astro/src/lib/client.ts +5 -2
- package/scaffold/templates/astro/src/pages/404.astro +3 -0
- package/scaffold/templates/astro/src/pages/account/index.astro +1 -0
- package/scaffold/templates/astro/src/pages/account/orders/[orderNumber].astro +11 -3
- 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 +3 -0
- package/scaffold/templates/astro/src/pages/category/[slug].astro +8 -6
- package/scaffold/templates/astro/src/pages/checkout.astro +10 -3
- package/scaffold/templates/astro/src/pages/index.astro +7 -0
- package/scaffold/templates/astro/src/pages/order/[orderNumber].astro +158 -54
- package/scaffold/templates/astro/src/pages/product/[slug].astro +20 -4
- package/scaffold/templates/astro/src/scripts/account-guard.ts +1 -0
- package/scaffold/templates/astro/src/scripts/order-access.ts +154 -0
- package/scaffold/templates/astro/src/scripts/order-status.ts +3 -1
- package/scaffold/templates/astro/src/scripts/pdp.ts +6 -0
- package/scaffold/templates/astro/src/scripts/plp.ts +1 -0
- package/scaffold/templates/astro/src/scripts/search.ts +1 -0
- package/scaffold/templates/astro/src/styles/pages/account.css +4 -0
- package/scaffold/templates/nextjs/app/(catalog)/home/[key]/page.tsx +6 -1
- package/scaffold/templates/nextjs/app/(catalog)/product/[slug]/page.tsx +22 -3
- package/scaffold/templates/nextjs/app/(shopper)/account/orders/[orderNumber]/page.tsx +10 -3
- 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)/checkout/CheckoutView.tsx +20 -9
- package/scaffold/templates/nextjs/app/(shopper)/not-found.tsx +6 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderDetails.tsx +23 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderEmailPrompt.tsx +90 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderLinkForm.tsx +73 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderNotFound.tsx +25 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/OrderView.tsx +140 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/not-found.tsx +6 -0
- package/scaffold/templates/nextjs/app/(shopper)/order/[orderNumber]/page.tsx +17 -129
- package/scaffold/templates/nextjs/app/not-found.tsx +1 -1
- package/scaffold/templates/nextjs/components/client/OrderStatusRefresh.tsx +8 -2
- package/scaffold/templates/nextjs/components/client/ProductInteractive.tsx +18 -1
- package/scaffold/templates/nextjs/components/client/elements.tsx +2 -0
- package/scaffold/templates/nextjs/lib/api.ts +62 -14
- package/scaffold/templates/nextjs/next.config.mjs +9 -0
- package/scaffold/templates/nextjs/package.json +26 -26
|
@@ -4,7 +4,7 @@ import BaseLayout from '../../layouts/BaseLayout.astro'
|
|
|
4
4
|
import NymbalElement from '@nymbalhq/web-components/astro'
|
|
5
5
|
import { cardImageOf, cardProductOf } from '@nymbalhq/web-components/ssr'
|
|
6
6
|
import { PRODUCT_SORT_LABELS } from '@nymbalhq/types'
|
|
7
|
-
import { fetchProducts,
|
|
7
|
+
import { fetchProducts, loadCategories, fetchCapabilities, sortFromUrl } from '../../lib/api'
|
|
8
8
|
|
|
9
9
|
const { slug } = Astro.params
|
|
10
10
|
const capabilities = await fetchCapabilities()
|
|
@@ -13,21 +13,23 @@ const sort = sortFromUrl(Astro.url, capabilities?.catalog)
|
|
|
13
13
|
|
|
14
14
|
const [productResult, categories] = await Promise.all([
|
|
15
15
|
fetchProducts({ limit: 24, category: slug, sort }),
|
|
16
|
-
|
|
16
|
+
// Rejects when the API fails, so a failed read is a 500 and never a 404 for a category the store has.
|
|
17
|
+
loadCategories(),
|
|
17
18
|
])
|
|
19
|
+
const category = categories.find((c) => c.slug === slug)
|
|
20
|
+
if (!category) return Astro.rewrite('/404')
|
|
18
21
|
|
|
19
22
|
const products = productResult.items.map(cardProductOf)
|
|
20
23
|
// The first card's image is the page's LCP, and the preload scanner never reaches it inside the grid's shadow root:
|
|
21
24
|
// the head starts it.
|
|
22
25
|
const firstImage = products[0] === undefined ? null : cardImageOf(products[0]).url
|
|
23
|
-
const
|
|
24
|
-
const categoryName = category?.name ?? slug ?? 'Category'
|
|
26
|
+
const categoryName = category.name
|
|
25
27
|
const facets = productResult.facets ?? []
|
|
26
28
|
---
|
|
27
29
|
|
|
28
30
|
<BaseLayout
|
|
29
31
|
title={`${categoryName} | Nymbal`}
|
|
30
|
-
description={category
|
|
32
|
+
description={category.description ?? `Browse ${categoryName} products.`}
|
|
31
33
|
>
|
|
32
34
|
{firstImage && <link slot="head" rel="preload" as="image" href={firstImage} fetchpriority="high" />}
|
|
33
35
|
<div class="container section">
|
|
@@ -35,7 +37,7 @@ const facets = productResult.facets ?? []
|
|
|
35
37
|
|
|
36
38
|
<div class="plp-header">
|
|
37
39
|
<h1 class="plp-title">{categoryName}</h1>
|
|
38
|
-
{category
|
|
40
|
+
{category.description && (
|
|
39
41
|
<p style="font-size: var(--nymbal-font-size-sm, 0.875rem); color: var(--nymbal-color-text-muted, #71717a); margin-bottom: var(--nymbal-spacing-sm, 0.5rem);">
|
|
40
42
|
{category.description}
|
|
41
43
|
</p>
|
|
@@ -3,6 +3,9 @@ import NymbalElement from '@nymbalhq/web-components/astro'
|
|
|
3
3
|
import BaseLayout from '../layouts/BaseLayout.astro'
|
|
4
4
|
import { fetchCapabilities, fetchCart } from '../lib/api'
|
|
5
5
|
|
|
6
|
+
// The shopper's own cart and checkout: no shared cache may keep them for the next visitor.
|
|
7
|
+
Astro.response.headers.set('Cache-Control', 'no-store')
|
|
8
|
+
|
|
6
9
|
const [capabilities, cart] = await Promise.all([
|
|
7
10
|
fetchCapabilities(),
|
|
8
11
|
fetchCart(Astro.request.headers.get('cookie')),
|
|
@@ -36,9 +39,13 @@ const paymentElement = `<nymbal-payment-element slot="payment" data-testid="paym
|
|
|
36
39
|
NymbalPaymentElement.define()
|
|
37
40
|
NymbalCheckout.define()
|
|
38
41
|
|
|
39
|
-
// The element places the order; the page only goes to it.
|
|
42
|
+
// The element places the order; the page only goes to it. A guest's order opens with its key; a signed-in
|
|
43
|
+
// shopper's checkout answers none, and their account is the order's home.
|
|
40
44
|
document.addEventListener('nymbal:checkout:placed', (event) => {
|
|
41
|
-
const { orderNumber } = (event as CustomEvent<{ orderNumber: string }>).detail
|
|
42
|
-
|
|
45
|
+
const { orderNumber, orderKey } = (event as CustomEvent<{ orderNumber: string; orderKey?: string }>).detail
|
|
46
|
+
const number = encodeURIComponent(orderNumber)
|
|
47
|
+
window.location.href = orderKey
|
|
48
|
+
? `/order/${number}?key=${encodeURIComponent(orderKey)}`
|
|
49
|
+
: `/account/orders/${number}`
|
|
43
50
|
})
|
|
44
51
|
</script>
|
|
@@ -40,13 +40,20 @@ const jsonLd = organizationJsonLd('Nymbal', Astro.url.origin)
|
|
|
40
40
|
</section>
|
|
41
41
|
|
|
42
42
|
<NewsletterSignup />
|
|
43
|
+
|
|
44
|
+
<!-- The shopper's own list, read in the browser: a bare tag, so no shopper's list is in the page's HTML. -->
|
|
45
|
+
<div class="container">
|
|
46
|
+
<nymbal-recently-viewed data-testid="recently-viewed"></nymbal-recently-viewed>
|
|
47
|
+
</div>
|
|
43
48
|
</BaseLayout>
|
|
44
49
|
|
|
45
50
|
<script>
|
|
46
51
|
import '../lib/client.js'
|
|
47
52
|
import { NymbalCategoryNav } from '@nymbalhq/web-components/elements/nymbal-category-nav'
|
|
48
53
|
import { NymbalProductGrid } from '@nymbalhq/web-components/elements/nymbal-product-grid'
|
|
54
|
+
import { NymbalRecentlyViewed } from '@nymbalhq/web-components/elements/nymbal-recently-viewed'
|
|
49
55
|
|
|
50
56
|
NymbalCategoryNav.define()
|
|
51
57
|
NymbalProductGrid.define()
|
|
58
|
+
NymbalRecentlyViewed.define()
|
|
52
59
|
</script>
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
---
|
|
2
2
|
import '../../styles/pages/confirmation.css'
|
|
3
|
+
import '../../styles/pages/error.css'
|
|
3
4
|
import BaseLayout from '../../layouts/BaseLayout.astro'
|
|
4
5
|
import NymbalElement from '@nymbalhq/web-components/astro'
|
|
5
6
|
import { fetchOrder } from '../../lib/api'
|
|
6
7
|
import { isPaid, orderHeading } from '../../lib/order-status'
|
|
7
8
|
|
|
9
|
+
// The URL carries the order's key (`?key=`), so nothing this page links to or loads may be told the URL: a header,
|
|
10
|
+
// the meta tag below and a canonical URL without the query. No shared cache may keep what a key opened.
|
|
11
|
+
Astro.response.headers.set('Referrer-Policy', 'no-referrer')
|
|
12
|
+
Astro.response.headers.set('Cache-Control', 'no-store')
|
|
13
|
+
|
|
8
14
|
const { orderNumber } = Astro.params
|
|
9
|
-
const
|
|
15
|
+
const key = Astro.url.searchParams.get('key') ?? undefined
|
|
16
|
+
// Rejects when the API fails, so a failed read is a 500 and never a not-found page for an order the shopper has. A POST
|
|
17
|
+
// here (a form sent before its script ran) is answered as the plain page: its body is never read.
|
|
18
|
+
const read = await fetchOrder(orderNumber!, key)
|
|
19
|
+
const order = read === 'expired' ? null : read
|
|
20
|
+
const canonical = new URL(Astro.url.pathname, Astro.url).href
|
|
10
21
|
|
|
11
|
-
|
|
22
|
+
// The order page's own not-found state, which offers a fresh link; the site-wide 404 would drop the headers above.
|
|
23
|
+
if (read === null) Astro.response.status = 404
|
|
12
24
|
|
|
13
|
-
const summary = {
|
|
25
|
+
const summary = order && {
|
|
14
26
|
items: JSON.stringify(
|
|
15
27
|
(order.lineItems ?? []).map((item) => ({
|
|
16
28
|
name: `${item.productName}${item.variantName ? ` - ${item.variantName}` : ''}`,
|
|
@@ -27,79 +39,171 @@ const summary = {
|
|
|
27
39
|
currency: order.currency,
|
|
28
40
|
}
|
|
29
41
|
|
|
30
|
-
const shippingAddress = order
|
|
31
|
-
const heading = orderHeading(order.status)
|
|
32
|
-
const paid = isPaid(order.status)
|
|
42
|
+
const shippingAddress = order?.shippingAddress
|
|
43
|
+
const heading = order ? orderHeading(order.status) : read === 'expired' ? 'Open your order' : 'Order not found'
|
|
44
|
+
const paid = order ? isPaid(order.status) : false
|
|
33
45
|
---
|
|
34
46
|
|
|
35
|
-
<BaseLayout title={`${heading} | Nymbal`} description="Your order with Nymbal.">
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
<BaseLayout title={`${heading} | Nymbal`} description="Your order with Nymbal." canonical={canonical}>
|
|
48
|
+
<meta slot="head" name="referrer" content="no-referrer" />
|
|
49
|
+
{read === 'expired' && (
|
|
50
|
+
<div class="container section" id="order-email-prompt">
|
|
51
|
+
<form method="post" class="error-page" id="order-email-form" data-order-number={orderNumber}>
|
|
52
|
+
<h1 class="error-title">Open your order</h1>
|
|
53
|
+
<p class="error-message">This order link has expired. Enter the email you gave at checkout to open the order.</p>
|
|
54
|
+
<div class="form-group">
|
|
55
|
+
<label for="order-email">Email</label>
|
|
56
|
+
<input id="order-email" type="email" name="email" autocomplete="email" required data-testid="order-email-input" />
|
|
57
|
+
</div>
|
|
58
|
+
<p class="error-message" data-testid="order-email-limited" hidden>
|
|
59
|
+
Too many tries for now. Please try again in a while.
|
|
60
|
+
</p>
|
|
61
|
+
<p class="error-message" id="order-email-failed" hidden>We could not open the order just now. Please try again.</p>
|
|
62
|
+
<div class="error-actions">
|
|
63
|
+
<button type="submit" class="btn btn-primary" data-testid="order-email-submit">Open order</button>
|
|
64
|
+
</div>
|
|
65
|
+
</form>
|
|
66
|
+
</div>
|
|
67
|
+
)}
|
|
68
|
+
{read === 'expired' && (
|
|
69
|
+
<div class="container section" id="order-opened" hidden>
|
|
70
|
+
<div class="confirmation-page">
|
|
71
|
+
<div class="confirmation-icon" data-order-field="paid">
|
|
40
72
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
41
73
|
<polyline points="20 6 9 17 4 12"></polyline>
|
|
42
74
|
</svg>
|
|
43
75
|
</div>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
76
|
+
<h1 class="confirmation-title" data-order-field="heading"></h1>
|
|
77
|
+
<p class="confirmation-subtitle" data-order-field="subtitle"></p>
|
|
78
|
+
<div class="confirmation-card">
|
|
79
|
+
<h2 class="confirmation-card-title">Order Details</h2>
|
|
80
|
+
<dl>
|
|
81
|
+
<div class="confirmation-detail-row">
|
|
82
|
+
<dt>Order Number</dt>
|
|
83
|
+
<dd data-order-field="number"></dd>
|
|
84
|
+
</div>
|
|
85
|
+
<div class="confirmation-detail-row">
|
|
86
|
+
<dt>Status</dt>
|
|
87
|
+
<dd style="text-transform: capitalize;" data-order-field="status"></dd>
|
|
88
|
+
</div>
|
|
89
|
+
</dl>
|
|
90
|
+
</div>
|
|
91
|
+
<nymbal-order-timeline class="confirmation-summary"></nymbal-order-timeline>
|
|
92
|
+
<nymbal-order-summary class="confirmation-summary"></nymbal-order-summary>
|
|
93
|
+
<div class="confirmation-card" data-order-field="shipping" hidden>
|
|
94
|
+
<h2 class="confirmation-card-title">Shipping Address</h2>
|
|
95
|
+
<p style="font-size: var(--nymbal-font-size-sm, 0.875rem); color: var(--nymbal-color-text-muted, #71717a); line-height: 1.6;" data-order-field="address"></p>
|
|
96
|
+
</div>
|
|
97
|
+
<div class="confirmation-actions">
|
|
98
|
+
<a href="/account/register" class="btn btn-primary">Create an Account</a>
|
|
99
|
+
<a href="/products" class="btn btn-secondary">Continue Shopping</a>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
)}
|
|
104
|
+
{(read === 'expired' || read === null) && (
|
|
105
|
+
<div class="container section" id="order-not-found" hidden={read === 'expired'}>
|
|
106
|
+
<div class="error-page">
|
|
107
|
+
<span class="error-code">404</span>
|
|
108
|
+
<h1 class="error-title">Order not found</h1>
|
|
109
|
+
<p class="error-message">
|
|
110
|
+
This link does not open an order. Give its order number and the email you gave at checkout, and we'll email
|
|
111
|
+
you a fresh link if they match.
|
|
60
112
|
</p>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
<
|
|
69
|
-
<dd>{order.orderNumber}</dd>
|
|
113
|
+
<form method="post" id="order-link-form">
|
|
114
|
+
<div class="form-group">
|
|
115
|
+
<label for="order-link-number">Order number</label>
|
|
116
|
+
<input id="order-link-number" name="orderNumber" required data-testid="order-link-number" />
|
|
117
|
+
</div>
|
|
118
|
+
<div class="form-group">
|
|
119
|
+
<label for="order-link-email">Email</label>
|
|
120
|
+
<input id="order-link-email" type="email" name="email" autocomplete="email" required data-testid="order-link-email" />
|
|
70
121
|
</div>
|
|
71
|
-
<div class="
|
|
72
|
-
<
|
|
73
|
-
<dd style="text-transform: capitalize;" data-testid="order-status">{order.status}</dd>
|
|
122
|
+
<div class="error-actions">
|
|
123
|
+
<button type="submit" class="btn btn-primary" data-testid="order-link-submit">Send me my order link</button>
|
|
74
124
|
</div>
|
|
75
|
-
</
|
|
125
|
+
</form>
|
|
126
|
+
<p class="error-message" data-testid="order-link-sent" hidden>
|
|
127
|
+
If that number and email match an order, its link is on its way to that email.
|
|
128
|
+
</p>
|
|
129
|
+
<p class="error-message" id="order-link-failed" hidden>We could not send the link just now. Please try again.</p>
|
|
76
130
|
</div>
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
{order && (
|
|
134
|
+
<div class="container section">
|
|
135
|
+
<div class="confirmation-page" data-order-number={order.orderNumber} data-order-status={order.status}>
|
|
136
|
+
{paid && (
|
|
137
|
+
<div class="confirmation-icon">
|
|
138
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
139
|
+
<polyline points="20 6 9 17 4 12"></polyline>
|
|
140
|
+
</svg>
|
|
141
|
+
</div>
|
|
142
|
+
)}
|
|
77
143
|
|
|
78
|
-
|
|
144
|
+
<h1 class="confirmation-title" data-testid="order-heading">{heading}</h1>
|
|
145
|
+
{paid ? (
|
|
146
|
+
<p class="confirmation-subtitle">
|
|
147
|
+
Thank you. Your order <strong data-testid="order-number">{order.orderNumber}</strong> is paid.
|
|
148
|
+
We'll send a confirmation to the email you gave at checkout.
|
|
149
|
+
</p>
|
|
150
|
+
) : order.status === 'pending' ? (
|
|
151
|
+
<p class="confirmation-subtitle">
|
|
152
|
+
Your order <strong data-testid="order-number">{order.orderNumber}</strong> is waiting for its payment.
|
|
153
|
+
We'll email the address you gave at checkout once it arrives.
|
|
154
|
+
</p>
|
|
155
|
+
) : (
|
|
156
|
+
<p class="confirmation-subtitle">
|
|
157
|
+
Your order <strong data-testid="order-number">{order.orderNumber}</strong> is {order.status.replace(/_/g, ' ')}.
|
|
158
|
+
</p>
|
|
159
|
+
)}
|
|
79
160
|
|
|
80
|
-
{shippingAddress && (
|
|
81
161
|
<div class="confirmation-card">
|
|
82
|
-
<h2 class="confirmation-card-title">
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
162
|
+
<h2 class="confirmation-card-title">Order Details</h2>
|
|
163
|
+
|
|
164
|
+
<dl>
|
|
165
|
+
<div class="confirmation-detail-row">
|
|
166
|
+
<dt>Order Number</dt>
|
|
167
|
+
<dd>{order.orderNumber}</dd>
|
|
168
|
+
</div>
|
|
169
|
+
<div class="confirmation-detail-row">
|
|
170
|
+
<dt>Status</dt>
|
|
171
|
+
<dd style="text-transform: capitalize;" data-testid="order-status">{order.status}</dd>
|
|
172
|
+
</div>
|
|
173
|
+
</dl>
|
|
89
174
|
</div>
|
|
90
|
-
)}
|
|
91
175
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
<
|
|
176
|
+
<NymbalElement tag="nymbal-order-timeline" attributes={{ class: 'confirmation-summary', entries: JSON.stringify(order.timeline ?? []) }} />
|
|
177
|
+
|
|
178
|
+
<NymbalElement tag="nymbal-order-summary" attributes={{ class: 'confirmation-summary', ...summary }} />
|
|
179
|
+
|
|
180
|
+
{shippingAddress && (
|
|
181
|
+
<div class="confirmation-card">
|
|
182
|
+
<h2 class="confirmation-card-title">Shipping Address</h2>
|
|
183
|
+
<p style="font-size: var(--nymbal-font-size-sm, 0.875rem); color: var(--nymbal-color-text-muted, #71717a); line-height: 1.6;">
|
|
184
|
+
{shippingAddress.addressLine1}<br />
|
|
185
|
+
{shippingAddress.addressLine2 && <>{shippingAddress.addressLine2}<br /></>}
|
|
186
|
+
{shippingAddress.city}, {shippingAddress.region} {shippingAddress.postalCode}<br />
|
|
187
|
+
{shippingAddress.country}
|
|
188
|
+
</p>
|
|
189
|
+
</div>
|
|
190
|
+
)}
|
|
191
|
+
|
|
192
|
+
<div class="confirmation-actions">
|
|
193
|
+
<a href="/account/register" class="btn btn-primary">Create an Account</a>
|
|
194
|
+
<a href="/products" class="btn btn-secondary">Continue Shopping</a>
|
|
195
|
+
</div>
|
|
95
196
|
</div>
|
|
96
197
|
</div>
|
|
97
|
-
|
|
198
|
+
)}
|
|
98
199
|
</BaseLayout>
|
|
99
200
|
|
|
100
201
|
<script>
|
|
101
202
|
import '../../scripts/order-status.js'
|
|
203
|
+
import '../../scripts/order-access.js'
|
|
102
204
|
import { NymbalOrderSummary } from '@nymbalhq/web-components/elements/nymbal-order-summary'
|
|
205
|
+
import { NymbalOrderTimeline } from '@nymbalhq/web-components/elements/nymbal-order-timeline'
|
|
103
206
|
|
|
104
207
|
NymbalOrderSummary.define()
|
|
208
|
+
NymbalOrderTimeline.define()
|
|
105
209
|
</script>
|
|
@@ -3,20 +3,22 @@ import '../../styles/pages/pdp.css'
|
|
|
3
3
|
import BaseLayout from '../../layouts/BaseLayout.astro'
|
|
4
4
|
import NymbalElement from '@nymbalhq/web-components/astro'
|
|
5
5
|
import { cardProductOf } from '@nymbalhq/web-components/ssr'
|
|
6
|
-
import {
|
|
6
|
+
import { loadProduct, fetchReviews, fetchProducts, fetchCapabilities } from '../../lib/api'
|
|
7
7
|
import { productJsonLd, breadcrumbJsonLd } from '../../lib/seo'
|
|
8
8
|
|
|
9
9
|
const { slug } = Astro.params
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// Rejects when the API fails, so a failed read is a 500 and never a 404 for a product the store has.
|
|
12
|
+
const product = await loadProduct(slug!)
|
|
13
|
+
if (!product) return Astro.rewrite('/404')
|
|
13
14
|
|
|
14
|
-
const [reviewsResult, relatedResult] = await Promise.all([
|
|
15
|
+
const [reviewsResult, relatedResult, capabilities] = await Promise.all([
|
|
15
16
|
fetchReviews(product.id),
|
|
16
17
|
fetchProducts({
|
|
17
18
|
limit: 4,
|
|
18
19
|
category: product.categories?.[0]?.slug,
|
|
19
20
|
}),
|
|
21
|
+
fetchCapabilities(),
|
|
20
22
|
])
|
|
21
23
|
|
|
22
24
|
const reviews = reviewsResult.items ?? []
|
|
@@ -40,6 +42,10 @@ const breadcrumb = breadcrumbJsonLd([
|
|
|
40
42
|
{ name: product.name, url: `${Astro.url.origin}/product/${product.slug}` },
|
|
41
43
|
])
|
|
42
44
|
|
|
45
|
+
// The alert form only where the store's email reaches a mailbox (an API older than the report says nothing): back in
|
|
46
|
+
// stock for a variant out of stock, price drop for one in stock.
|
|
47
|
+
const offersAlerts = capabilities?.email?.delivers === true && defaultVariant !== undefined
|
|
48
|
+
|
|
43
49
|
// The selector derives its option groups from the product's variants.
|
|
44
50
|
const hasVariantChoice = (product.variants?.length ?? 0) > 1
|
|
45
51
|
---
|
|
@@ -93,6 +99,13 @@ const hasVariantChoice = (product.variants?.length ?? 0) > 1
|
|
|
93
99
|
</div>
|
|
94
100
|
</div>
|
|
95
101
|
|
|
102
|
+
{offersAlerts && (
|
|
103
|
+
<NymbalElement
|
|
104
|
+
tag="nymbal-notify-me"
|
|
105
|
+
attributes={{ 'product-id': product.id, 'variant-id': defaultVariant!.id, stock: String(stock) }}
|
|
106
|
+
/>
|
|
107
|
+
)}
|
|
108
|
+
|
|
96
109
|
{product.description && (
|
|
97
110
|
<div class="pdp-description" data-testid="product-description">
|
|
98
111
|
<Fragment set:html={product.description} />
|
|
@@ -116,6 +129,9 @@ const hasVariantChoice = (product.variants?.length ?? 0) > 1
|
|
|
116
129
|
/>
|
|
117
130
|
</section>
|
|
118
131
|
)}
|
|
132
|
+
|
|
133
|
+
<!-- The shopper's own list, read in the browser: a bare tag, so no shopper's list is in the page's HTML. -->
|
|
134
|
+
<nymbal-recently-viewed data-testid="recently-viewed" current={product.id}></nymbal-recently-viewed>
|
|
119
135
|
</div>
|
|
120
136
|
</BaseLayout>
|
|
121
137
|
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { NymbalApiError } from '@nymbalhq/sdk/core'
|
|
2
|
+
import type { ShopperAddress, ShopperOrder } from '@nymbalhq/types'
|
|
3
|
+
import { client } from '../lib/client.js'
|
|
4
|
+
import { isPaid, orderHeading } from '../lib/order-status.js'
|
|
5
|
+
import { submitOnce } from '../lib/submit-once.js'
|
|
6
|
+
|
|
7
|
+
// The order page's two forms, each sent once per click from the browser. The expired key's email prompt reads the
|
|
8
|
+
// order with the email in a header and shows it on this page: read by the storefront's server instead, every shopper's
|
|
9
|
+
// tries would count against the API's per-address limit as one. "Send me my order link" asks the API, which answers
|
|
10
|
+
// the same whatever matched.
|
|
11
|
+
|
|
12
|
+
const byId = (id: string): HTMLElement | null => document.getElementById(id)
|
|
13
|
+
|
|
14
|
+
const field = (root: HTMLElement, name: string): HTMLElement | null =>
|
|
15
|
+
root.querySelector<HTMLElement>(`[data-order-field="${name}"]`)
|
|
16
|
+
|
|
17
|
+
/** The subtitle the server-rendered page gives the same status, its number under the same test id. */
|
|
18
|
+
function subtitle(order: ShopperOrder): Node[] {
|
|
19
|
+
const number = document.createElement('strong')
|
|
20
|
+
number.dataset.testid = 'order-number'
|
|
21
|
+
number.textContent = order.orderNumber
|
|
22
|
+
const text = (value: string) => document.createTextNode(value)
|
|
23
|
+
if (isPaid(order.status)) {
|
|
24
|
+
return [
|
|
25
|
+
text('Thank you. Your order '),
|
|
26
|
+
number,
|
|
27
|
+
text(" is paid. We'll send a confirmation to the email you gave at checkout."),
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
if (order.status === 'pending') {
|
|
31
|
+
return [
|
|
32
|
+
text('Your order '),
|
|
33
|
+
number,
|
|
34
|
+
text(
|
|
35
|
+
" is waiting for its payment. We'll email the address you gave at checkout once it arrives.",
|
|
36
|
+
),
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
return [text('Your order '), number, text(` is ${order.status.replace(/_/g, ' ')}.`)]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function addressLines(address: ShopperAddress): Node[] {
|
|
43
|
+
const lines = [
|
|
44
|
+
address.addressLine1,
|
|
45
|
+
address.addressLine2,
|
|
46
|
+
`${address.city}, ${address.region} ${address.postalCode}`,
|
|
47
|
+
address.country,
|
|
48
|
+
].filter((line): line is string => typeof line === 'string' && line !== '')
|
|
49
|
+
return lines.flatMap((line, i) => {
|
|
50
|
+
const node = document.createTextNode(line)
|
|
51
|
+
return i === 0 ? [node] : [document.createElement('br'), node]
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Fills the page's empty confirmation with the order, as the server renders a key's order. */
|
|
56
|
+
function fillOrder(view: HTMLElement, order: ShopperOrder): void {
|
|
57
|
+
// The check mark is a flex box, which `hidden` does not hide: an unpaid order's is removed.
|
|
58
|
+
if (!isPaid(order.status)) field(view, 'paid')?.remove()
|
|
59
|
+
const heading = field(view, 'heading')
|
|
60
|
+
if (heading) {
|
|
61
|
+
heading.textContent = orderHeading(order.status)
|
|
62
|
+
heading.dataset.testid = 'order-heading'
|
|
63
|
+
}
|
|
64
|
+
field(view, 'subtitle')?.replaceChildren(...subtitle(order))
|
|
65
|
+
const number = field(view, 'number')
|
|
66
|
+
if (number) number.textContent = order.orderNumber
|
|
67
|
+
const status = field(view, 'status')
|
|
68
|
+
if (status) {
|
|
69
|
+
status.textContent = order.status
|
|
70
|
+
status.dataset.testid = 'order-status'
|
|
71
|
+
}
|
|
72
|
+
view
|
|
73
|
+
.querySelector('nymbal-order-timeline')
|
|
74
|
+
?.setAttribute('entries', JSON.stringify(order.timeline ?? []))
|
|
75
|
+
const summary = view.querySelector('nymbal-order-summary')
|
|
76
|
+
if (summary) {
|
|
77
|
+
const items = (order.lineItems ?? []).map((item) => ({
|
|
78
|
+
name: `${item.productName}${item.variantName ? ` - ${item.variantName}` : ''}`,
|
|
79
|
+
qty: item.qty,
|
|
80
|
+
unitPriceMinor: item.unitPriceMinor,
|
|
81
|
+
lineTotalMinor: item.lineTotalMinor,
|
|
82
|
+
}))
|
|
83
|
+
summary.setAttribute('items', JSON.stringify(items))
|
|
84
|
+
summary.setAttribute('subtotal-minor', String(order.subtotalMinor))
|
|
85
|
+
summary.setAttribute('discount-minor', String(order.discountTotalMinor ?? 0))
|
|
86
|
+
summary.setAttribute('shipping-minor', String(order.shippingTotalMinor ?? 0))
|
|
87
|
+
summary.setAttribute('tax-minor', String(order.taxTotalMinor ?? 0))
|
|
88
|
+
summary.setAttribute('total-minor', String(order.totalMinor))
|
|
89
|
+
summary.setAttribute('currency', order.currency)
|
|
90
|
+
}
|
|
91
|
+
const shipping = field(view, 'shipping')
|
|
92
|
+
if (shipping) {
|
|
93
|
+
field(shipping, 'address')?.replaceChildren(...addressLines(order.shippingAddress))
|
|
94
|
+
shipping.hidden = false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Shows one of the expired page's three views: the prompt, the order, or the not-found state. */
|
|
99
|
+
function show(id: 'order-email-prompt' | 'order-opened' | 'order-not-found'): void {
|
|
100
|
+
for (const view of ['order-email-prompt', 'order-opened', 'order-not-found']) {
|
|
101
|
+
const el = byId(view)
|
|
102
|
+
if (el) el.hidden = view !== id
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const prompt = document.getElementById('order-email-form') as HTMLFormElement | null
|
|
107
|
+
submitOnce(prompt, async () => {
|
|
108
|
+
if (prompt === null) return
|
|
109
|
+
const limited = prompt.querySelector<HTMLElement>('[data-testid="order-email-limited"]')
|
|
110
|
+
const failed = byId('order-email-failed')
|
|
111
|
+
if (limited) limited.hidden = true
|
|
112
|
+
if (failed) failed.hidden = true
|
|
113
|
+
const orderNumber = prompt.dataset.orderNumber ?? ''
|
|
114
|
+
const key = new URLSearchParams(window.location.search).get('key') ?? ''
|
|
115
|
+
const email = String(new FormData(prompt).get('email') ?? '').trim()
|
|
116
|
+
|
|
117
|
+
let order: ShopperOrder
|
|
118
|
+
try {
|
|
119
|
+
order = await client.orders.get(orderNumber, { key, email })
|
|
120
|
+
} catch (err) {
|
|
121
|
+
// The answer an unknown number gets: the email did not open the order.
|
|
122
|
+
if (err instanceof NymbalApiError && err.status === 404) return show('order-not-found')
|
|
123
|
+
if (err instanceof NymbalApiError && err.status === 429) {
|
|
124
|
+
if (limited) limited.hidden = false
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
if (failed) failed.hidden = false
|
|
128
|
+
throw err
|
|
129
|
+
}
|
|
130
|
+
const view = byId('order-opened')
|
|
131
|
+
if (view === null) return
|
|
132
|
+
fillOrder(view, order)
|
|
133
|
+
show('order-opened')
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const linkForm = document.getElementById('order-link-form') as HTMLFormElement | null
|
|
137
|
+
submitOnce(linkForm, async () => {
|
|
138
|
+
if (linkForm === null) return
|
|
139
|
+
const data = new FormData(linkForm)
|
|
140
|
+
const failed = document.getElementById('order-link-failed')
|
|
141
|
+
if (failed) failed.hidden = true
|
|
142
|
+
try {
|
|
143
|
+
await client.orders.requestLink({
|
|
144
|
+
orderNumber: String(data.get('orderNumber') ?? '').trim(),
|
|
145
|
+
email: String(data.get('email') ?? '').trim(),
|
|
146
|
+
})
|
|
147
|
+
} catch (err) {
|
|
148
|
+
if (failed) failed.hidden = false
|
|
149
|
+
throw err
|
|
150
|
+
}
|
|
151
|
+
linkForm.hidden = true
|
|
152
|
+
const sent = document.querySelector<HTMLElement>('[data-testid="order-link-sent"]')
|
|
153
|
+
if (sent) sent.hidden = false
|
|
154
|
+
})
|
|
@@ -8,12 +8,14 @@ const POLL_FOR_MS = 10_000
|
|
|
8
8
|
const root = document.querySelector<HTMLElement>('[data-order-number][data-order-status]')
|
|
9
9
|
const orderNumber = root?.dataset.orderNumber
|
|
10
10
|
const shown = root?.dataset.orderStatus
|
|
11
|
+
// The page's own key, from its URL: the API answers a guest's order to its key only.
|
|
12
|
+
const key = new URLSearchParams(window.location.search).get('key')
|
|
11
13
|
|
|
12
14
|
if (orderNumber && shown === 'pending') {
|
|
13
15
|
const until = Date.now() + POLL_FOR_MS
|
|
14
16
|
const poll = async (): Promise<void> => {
|
|
15
17
|
try {
|
|
16
|
-
const order = await client.customer.orders.get(orderNumber)
|
|
18
|
+
const order = await client.customer.orders.get(orderNumber, key ? { key } : {})
|
|
17
19
|
if (order.status !== shown) {
|
|
18
20
|
window.location.reload()
|
|
19
21
|
return
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import '@nymbalhq/sdk/ns/product'
|
|
1
2
|
import { NymbalAddToCart } from '@nymbalhq/web-components/elements/nymbal-add-to-cart'
|
|
2
3
|
import { NymbalBreadcrumb } from '@nymbalhq/web-components/elements/nymbal-breadcrumb'
|
|
3
4
|
import { NymbalImageGallery } from '@nymbalhq/web-components/elements/nymbal-image-gallery'
|
|
5
|
+
import { NymbalNotifyMe } from '@nymbalhq/web-components/elements/nymbal-notify-me'
|
|
4
6
|
import { NymbalProductGrid } from '@nymbalhq/web-components/elements/nymbal-product-grid'
|
|
5
7
|
import { NymbalProductPrice } from '@nymbalhq/web-components/elements/nymbal-product-price'
|
|
6
8
|
import { NymbalQuantitySelector } from '@nymbalhq/web-components/elements/nymbal-quantity-selector'
|
|
9
|
+
import { NymbalRecentlyViewed } from '@nymbalhq/web-components/elements/nymbal-recently-viewed'
|
|
7
10
|
import { NymbalReviewForm } from '@nymbalhq/web-components/elements/nymbal-review-form'
|
|
8
11
|
import { NymbalReviewList } from '@nymbalhq/web-components/elements/nymbal-review-list'
|
|
9
12
|
import { NymbalStockBadge } from '@nymbalhq/web-components/elements/nymbal-stock-badge'
|
|
@@ -19,8 +22,11 @@ NymbalQuantitySelector.define()
|
|
|
19
22
|
NymbalAddToCart.define()
|
|
20
23
|
NymbalReviewList.define()
|
|
21
24
|
NymbalReviewForm.define()
|
|
25
|
+
NymbalRecentlyViewed.define()
|
|
22
26
|
// The related grid is there only when the product has relations.
|
|
23
27
|
if (document.querySelector('nymbal-product-grid') !== null) NymbalProductGrid.define()
|
|
28
|
+
// The back-in-stock form is there only when the store's email delivers.
|
|
29
|
+
if (document.querySelector('nymbal-notify-me') !== null) NymbalNotifyMe.define()
|
|
24
30
|
|
|
25
31
|
const slug = document.querySelector<HTMLElement>('[data-product-slug]')?.dataset.productSlug
|
|
26
32
|
const addRow = document.querySelector<HTMLElement>('.pdp-add-row')
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import '@nymbalhq/sdk/ns/product-list'
|
|
1
2
|
import type { ProductSortKey } from '@nymbalhq/types'
|
|
2
3
|
import { NymbalBreadcrumb } from '@nymbalhq/web-components/elements/nymbal-breadcrumb'
|
|
3
4
|
import { NymbalProductFilter } from '@nymbalhq/web-components/elements/nymbal-product-filter'
|
|
@@ -33,7 +33,10 @@
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/* A `1fr` track is at least its content's min-content width: without `min-width: 0` and `overflow-wrap`, a long
|
|
37
|
+
email (one unbreakable word) widens its card past a phone's viewport. */
|
|
36
38
|
.account-stat-card {
|
|
39
|
+
min-width: 0;
|
|
37
40
|
padding: var(--nymbal-spacing-md, 1rem);
|
|
38
41
|
background-color: #fafafa;
|
|
39
42
|
border: 1px solid var(--nymbal-color-border, #e4e4e7);
|
|
@@ -49,6 +52,7 @@
|
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
.account-stat-value {
|
|
55
|
+
overflow-wrap: anywhere;
|
|
52
56
|
font-size: 1.25rem;
|
|
53
57
|
font-weight: var(--nymbal-font-weight-bold, 700);
|
|
54
58
|
color: var(--nymbal-color-primary, #18181b);
|