create-nextblock 0.15.8 → 0.15.9

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 (71) hide show
  1. package/package.json +1 -1
  2. package/templates/nextblock-template/app/ToasterProvider.tsx +26 -17
  3. package/templates/nextblock-template/app/actions/contactSellerActions.test.ts +280 -0
  4. package/templates/nextblock-template/app/actions/contactSellerActions.ts +222 -0
  5. package/templates/nextblock-template/app/actions/email-retry.test.ts +62 -0
  6. package/templates/nextblock-template/app/actions/email.ts +241 -110
  7. package/templates/nextblock-template/app/actions/formActions.ts +245 -116
  8. package/templates/nextblock-template/app/actions/interactions.ts +489 -396
  9. package/templates/nextblock-template/app/actions/threadActions.ts +166 -0
  10. package/templates/nextblock-template/app/api/checkout/route.ts +162 -146
  11. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +664 -1
  12. package/templates/nextblock-template/app/checkout/page.tsx +57 -52
  13. package/templates/nextblock-template/app/cms/CmsClientLayout.tsx +552 -529
  14. package/templates/nextblock-template/app/cms/blocks/editors/FormBlockEditor.tsx +304 -181
  15. package/templates/nextblock-template/app/cms/components/ContactReminderBanner.tsx +75 -0
  16. package/templates/nextblock-template/app/cms/components/PaymentsReminderBanner.tsx +58 -0
  17. package/templates/nextblock-template/app/cms/components/VisibilityControl.tsx +542 -528
  18. package/templates/nextblock-template/app/cms/inquiries/actions.ts +66 -0
  19. package/templates/nextblock-template/app/cms/inquiries/page.tsx +12 -0
  20. package/templates/nextblock-template/app/cms/interactions/page.tsx +12 -51
  21. package/templates/nextblock-template/app/cms/layout.tsx +101 -73
  22. package/templates/nextblock-template/app/cms/messages/MessagesClient.tsx +661 -0
  23. package/templates/nextblock-template/app/cms/messages/actions.ts +404 -0
  24. package/templates/nextblock-template/app/cms/messages/loadInbox.ts +333 -0
  25. package/templates/nextblock-template/app/cms/messages/page.tsx +87 -0
  26. package/templates/nextblock-template/app/cms/messages/require-admin.ts +37 -0
  27. package/templates/nextblock-template/app/cms/products/[id]/edit/page.tsx +370 -362
  28. package/templates/nextblock-template/app/cms/revisions/service.ts +20 -0
  29. package/templates/nextblock-template/app/cms/settings/email/components/EmailForm.tsx +227 -185
  30. package/templates/nextblock-template/app/layout.tsx +671 -671
  31. package/templates/nextblock-template/app/product/[slug]/page.tsx +502 -482
  32. package/templates/nextblock-template/app/providers.tsx +96 -96
  33. package/templates/nextblock-template/app/thread/ThreadView.tsx +164 -0
  34. package/templates/nextblock-template/app/thread/[token]/route.ts +57 -0
  35. package/templates/nextblock-template/app/thread/layout.tsx +15 -0
  36. package/templates/nextblock-template/app/thread/page.tsx +98 -0
  37. package/templates/nextblock-template/components/BlockRenderer.tsx +312 -296
  38. package/templates/nextblock-template/components/ContactSellerSection.tsx +188 -0
  39. package/templates/nextblock-template/components/PostCommentsSection.tsx +378 -369
  40. package/templates/nextblock-template/components/ProductReviewsSection.tsx +426 -419
  41. package/templates/nextblock-template/components/StaffReplies.tsx +102 -0
  42. package/templates/nextblock-template/components/blocks/renderers/CartBlockRenderer.tsx +18 -17
  43. package/templates/nextblock-template/components/blocks/renderers/CheckoutBlockRenderer.tsx +20 -19
  44. package/templates/nextblock-template/components/blocks/renderers/FeaturedProductBlockRenderer.tsx +25 -22
  45. package/templates/nextblock-template/components/blocks/renderers/FormBlockRenderer.tsx +385 -381
  46. package/templates/nextblock-template/components/blocks/renderers/ProductDetailsBlockRenderer.tsx +157 -92
  47. package/templates/nextblock-template/components/blocks/renderers/ProductGridBlockRenderer.tsx +34 -31
  48. package/templates/nextblock-template/components/blocks/renderers/SectionBlockRenderer.tsx +612 -600
  49. package/templates/nextblock-template/components/commerce/PaymentReadinessBoundary.tsx +32 -0
  50. package/templates/nextblock-template/docs/14-MESSAGES-INBOX.md +309 -0
  51. package/templates/nextblock-template/docs/README.md +42 -41
  52. package/templates/nextblock-template/docs/assets/lighthouse-scores.png +0 -0
  53. package/templates/nextblock-template/lib/blocks/blockColors.test.ts +22 -2
  54. package/templates/nextblock-template/lib/blocks/blockColors.ts +44 -1
  55. package/templates/nextblock-template/lib/blocks/blockRegistry.ts +761 -753
  56. package/templates/nextblock-template/lib/cms/contact-reminder.ts +64 -0
  57. package/templates/nextblock-template/lib/cms/payments-reminder.ts +98 -0
  58. package/templates/nextblock-template/lib/cms/unread-messages.ts +42 -0
  59. package/templates/nextblock-template/lib/commerce/seller-contact.ts +162 -0
  60. package/templates/nextblock-template/lib/config/email-settings.ts +323 -254
  61. package/templates/nextblock-template/lib/config/email-tls.test.ts +57 -0
  62. package/templates/nextblock-template/lib/email/placeholder-address.test.ts +59 -0
  63. package/templates/nextblock-template/lib/email/placeholder-address.ts +39 -0
  64. package/templates/nextblock-template/lib/messages/thread-reference.test.ts +70 -0
  65. package/templates/nextblock-template/lib/messages/thread-token.test.ts +93 -0
  66. package/templates/nextblock-template/lib/messages/thread-token.ts +157 -0
  67. package/templates/nextblock-template/lib/messages/threads.ts +579 -0
  68. package/templates/nextblock-template/lib/setup/migrations-bundle.ts +20 -0
  69. package/templates/nextblock-template/lib/site-url.test.ts +89 -0
  70. package/templates/nextblock-template/lib/site-url.ts +102 -48
  71. package/templates/nextblock-template/package.json +1 -1
@@ -0,0 +1,188 @@
1
+ 'use client';
2
+
3
+ import { useActionState } from 'react';
4
+ import { useFormStatus } from 'react-dom';
5
+ import { Button } from '@nextblock-cms/ui';
6
+ import { Input } from '@nextblock-cms/ui';
7
+ import { Textarea } from '@nextblock-cms/ui';
8
+ import { useTranslations } from '@nextblock-cms/utils';
9
+ import { Loader2, Mail, CheckCircle2 } from 'lucide-react';
10
+
11
+ import { AuthBotProtection } from './auth/AuthBotProtection';
12
+ import {
13
+ submitProductInquiry,
14
+ type ContactSellerState,
15
+ } from '../app/actions/contactSellerActions';
16
+
17
+ /**
18
+ * Shown in place of Add-to-Cart when the store cannot take payment for this product.
19
+ *
20
+ * The visitor never learns why — "online ordering isn't available yet" is true and
21
+ * actionable, whereas "the merchant hasn't configured Stripe" is an internal detail.
22
+ * No seller address appears anywhere in this component or its payload: the form posts
23
+ * a product id, and the server resolves who to notify.
24
+ */
25
+
26
+ interface ContactSellerSectionProps {
27
+ productId: string;
28
+ botProtectionProvider: 'none' | 'turnstile' | 'recaptcha';
29
+ botProtectionSiteKey: string;
30
+ scriptNonce?: string;
31
+ }
32
+
33
+ const INITIAL_STATE: ContactSellerState = { success: false, messageKey: '' };
34
+
35
+ // `t()` returns the key itself when a translation row is missing, so every string
36
+ // carries the English literal it should fall back to.
37
+ const FALLBACKS: Record<string, string> = {
38
+ 'ecommerce.contact_seller_heading': 'Interested in this product?',
39
+ 'ecommerce.contact_seller_intro':
40
+ "Online ordering isn't available for this item yet. Send the seller a message and they'll get back to you about buying it.",
41
+ 'ecommerce.contact_seller_name': 'Your name',
42
+ 'ecommerce.contact_seller_email': 'Your email',
43
+ 'ecommerce.contact_seller_message': 'Message',
44
+ 'ecommerce.contact_seller_send': 'Send message',
45
+ 'ecommerce.contact_seller_sending': 'Sending…',
46
+ 'ecommerce.contact_seller_sent':
47
+ "Thanks — your message has been sent to the seller. They'll reply to the email address you gave.",
48
+ 'ecommerce.contact_seller_error':
49
+ "Sorry, your message couldn't be sent. Please try again in a moment.",
50
+ 'ecommerce.contact_seller_throttled':
51
+ "You've sent several messages already. Please wait a few minutes before sending another.",
52
+ 'ecommerce.contact_seller_invalid':
53
+ 'Please check your name, email address and message, then try again.',
54
+ };
55
+
56
+ function SubmitButton({ label, pendingLabel }: { label: string; pendingLabel: string }) {
57
+ const { pending } = useFormStatus();
58
+ return (
59
+ <Button type="submit" disabled={pending} className="min-w-[150px]">
60
+ {pending ? (
61
+ <>
62
+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />
63
+ {pendingLabel}
64
+ </>
65
+ ) : (
66
+ <>
67
+ <Mail className="mr-2 h-4 w-4" />
68
+ {label}
69
+ </>
70
+ )}
71
+ </Button>
72
+ );
73
+ }
74
+
75
+ export default function ContactSellerSection({
76
+ productId,
77
+ botProtectionProvider,
78
+ botProtectionSiteKey,
79
+ scriptNonce,
80
+ }: ContactSellerSectionProps) {
81
+ const { t, lang } = useTranslations();
82
+ const [state, formAction] = useActionState(submitProductInquiry, INITIAL_STATE);
83
+
84
+ // Resolve a key to its translation, falling back to the English literal.
85
+ const label = (key: string): string => {
86
+ const value = t(key);
87
+ return value === key ? (FALLBACKS[key] ?? key) : value;
88
+ };
89
+
90
+ if (state.success) {
91
+ return (
92
+ <div
93
+ id="contact-seller"
94
+ className="rounded-2xl border border-emerald-200 bg-emerald-50 p-6 dark:border-emerald-900/50 dark:bg-emerald-950/30"
95
+ >
96
+ <div className="flex items-start gap-3">
97
+ <CheckCircle2 className="mt-0.5 h-5 w-5 shrink-0 text-emerald-600 dark:text-emerald-400" />
98
+ <p className="text-sm text-emerald-900 dark:text-emerald-200">
99
+ {label('ecommerce.contact_seller_sent')}
100
+ </p>
101
+ </div>
102
+ </div>
103
+ );
104
+ }
105
+
106
+ // Captcha failures carry provider-specific text; everything else is a keyed message.
107
+ const errorText =
108
+ state.message || (state.messageKey ? label(state.messageKey) : null);
109
+
110
+ return (
111
+ <div
112
+ id="contact-seller"
113
+ className="scroll-mt-24 rounded-2xl border border-border/80 bg-card/50 p-6 shadow-sm"
114
+ >
115
+ <h3 className="text-lg font-semibold text-foreground">
116
+ {label('ecommerce.contact_seller_heading')}
117
+ </h3>
118
+ <p className="mt-1 text-sm text-muted-foreground">
119
+ {label('ecommerce.contact_seller_intro')}
120
+ </p>
121
+
122
+ <form action={formAction} className="mt-5 space-y-4">
123
+ <input type="hidden" name="product_id" value={productId} />
124
+ <input type="hidden" name="locale" value={lang ?? ''} />
125
+
126
+ <div className="grid gap-4 sm:grid-cols-2">
127
+ <div className="space-y-1.5">
128
+ <label
129
+ htmlFor="contact-seller-name"
130
+ className="block text-xs font-semibold uppercase tracking-wider text-muted-foreground"
131
+ >
132
+ {label('ecommerce.contact_seller_name')}
133
+ </label>
134
+ <Input id="contact-seller-name" name="name" required maxLength={120} autoComplete="name" />
135
+ </div>
136
+
137
+ <div className="space-y-1.5">
138
+ <label
139
+ htmlFor="contact-seller-email"
140
+ className="block text-xs font-semibold uppercase tracking-wider text-muted-foreground"
141
+ >
142
+ {label('ecommerce.contact_seller_email')}
143
+ </label>
144
+ <Input
145
+ id="contact-seller-email"
146
+ name="email"
147
+ type="email"
148
+ required
149
+ maxLength={254}
150
+ autoComplete="email"
151
+ />
152
+ </div>
153
+ </div>
154
+
155
+ <div className="space-y-1.5">
156
+ <label
157
+ htmlFor="contact-seller-message"
158
+ className="block text-xs font-semibold uppercase tracking-wider text-muted-foreground"
159
+ >
160
+ {label('ecommerce.contact_seller_message')}
161
+ </label>
162
+ <Textarea
163
+ id="contact-seller-message"
164
+ name="message"
165
+ required
166
+ maxLength={2000}
167
+ className="min-h-[120px]"
168
+ />
169
+ </div>
170
+
171
+ <AuthBotProtection
172
+ provider={botProtectionProvider}
173
+ siteKey={botProtectionSiteKey}
174
+ scriptNonce={scriptNonce}
175
+ />
176
+
177
+ {errorText && <p className="text-sm font-semibold text-destructive">{errorText}</p>}
178
+
179
+ <div className="flex justify-end pt-1">
180
+ <SubmitButton
181
+ label={label('ecommerce.contact_seller_send')}
182
+ pendingLabel={label('ecommerce.contact_seller_sending')}
183
+ />
184
+ </div>
185
+ </form>
186
+ </div>
187
+ );
188
+ }