create-nextblock 0.9.0 → 0.9.6

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 (45) hide show
  1. package/bin/create-nextblock.js +40 -60
  2. package/docker-template/.env.docker.example +5 -4
  3. package/docker-template/Dockerfile +20 -3
  4. package/docker-template/docker-compose.yml +5 -1
  5. package/docker-template/scripts/docker-setup.mjs +19 -4
  6. package/package.json +1 -1
  7. package/templates/nextblock-template/Dockerfile +20 -3
  8. package/templates/nextblock-template/app/[slug]/page.tsx +5 -0
  9. package/templates/nextblock-template/app/actions.ts +58 -8
  10. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +83 -0
  11. package/templates/nextblock-template/app/api/process-image/route.ts +13 -9
  12. package/templates/nextblock-template/app/article/[slug]/page.tsx +5 -0
  13. package/templates/nextblock-template/app/cms/components/ContentLanguageSwitcher.tsx +19 -13
  14. package/templates/nextblock-template/app/cms/settings/security/actions.ts +30 -0
  15. package/templates/nextblock-template/app/cms/settings/security/components/SecurityPanel.tsx +69 -0
  16. package/templates/nextblock-template/app/layout.tsx +49 -3
  17. package/templates/nextblock-template/app/lib/site-settings.ts +22 -7
  18. package/templates/nextblock-template/app/page.tsx +6 -0
  19. package/templates/nextblock-template/app/product/[slug]/page.tsx +5 -0
  20. package/templates/nextblock-template/app/providers.tsx +1 -1
  21. package/templates/nextblock-template/app/setup/SetupWizard.tsx +773 -0
  22. package/templates/nextblock-template/app/setup/layout.tsx +13 -0
  23. package/templates/nextblock-template/app/setup/page.tsx +103 -0
  24. package/templates/nextblock-template/components/AppShell.tsx +12 -0
  25. package/templates/nextblock-template/components/PublicEnvBootstrap.tsx +30 -0
  26. package/templates/nextblock-template/components/header-auth.tsx +24 -62
  27. package/templates/nextblock-template/docker-compose.yml +5 -1
  28. package/templates/nextblock-template/docs/11-SELF-HOSTED-DOCKER.md +173 -0
  29. package/templates/nextblock-template/docs/12-VERCEL-DEPLOYMENT.md +67 -0
  30. package/templates/nextblock-template/docs/README.md +2 -0
  31. package/templates/nextblock-template/lib/blocks/FeaturedProductBlock.tsx +1 -1
  32. package/templates/nextblock-template/lib/blocks/ProductGridBlock.tsx +1 -1
  33. package/templates/nextblock-template/lib/media/resolveMediaUrl.ts +9 -1
  34. package/templates/nextblock-template/lib/setup/actions.ts +370 -0
  35. package/templates/nextblock-template/lib/setup/env-status.ts +86 -0
  36. package/templates/nextblock-template/lib/setup/env-write.ts +111 -0
  37. package/templates/nextblock-template/lib/setup/provisioning.ts +59 -0
  38. package/templates/nextblock-template/lib/setup/schema-apply.ts +392 -0
  39. package/templates/nextblock-template/lib/setup/system-config.ts +105 -0
  40. package/templates/nextblock-template/lib/setup/types.ts +18 -0
  41. package/templates/nextblock-template/next.config.js +13 -0
  42. package/templates/nextblock-template/package.json +1 -1
  43. package/templates/nextblock-template/proxy.ts +143 -49
  44. package/templates/nextblock-template/scripts/docker-setup.mjs +19 -4
  45. package/templates/nextblock-template/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,773 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useMemo, useState, useTransition } from 'react';
4
+ import {
5
+ Alert,
6
+ AlertDescription,
7
+ Badge,
8
+ Button,
9
+ Card,
10
+ CardContent,
11
+ CardDescription,
12
+ CardHeader,
13
+ CardTitle,
14
+ Checkbox,
15
+ Input,
16
+ Label,
17
+ Separator,
18
+ Spinner,
19
+ } from '@nextblock-cms/ui';
20
+ import type { DeployChannel } from '../../lib/setup/env-status';
21
+ import { completeSetup, saveSupabaseConnection } from '../../lib/setup/actions';
22
+ import { signInAction } from '../actions';
23
+
24
+ export type StorageKind = 'minio' | 'supabase' | 'r2';
25
+
26
+ export interface StoragePrefill {
27
+ kind: StorageKind;
28
+ readOnly: boolean;
29
+ accountId: string;
30
+ bucket: string;
31
+ endpoint: string;
32
+ publicUrl: string;
33
+ baseUrl: string;
34
+ accessKeyId: string;
35
+ secretAccessKey: string;
36
+ }
37
+
38
+ interface SmtpPrefill {
39
+ host: string;
40
+ port: string;
41
+ user: string;
42
+ fromEmail: string;
43
+ fromName: string;
44
+ }
45
+
46
+ interface Props {
47
+ channel: DeployChannel;
48
+ configured: boolean;
49
+ writable: boolean;
50
+ siteUrl: string;
51
+ storagePrefill: StoragePrefill;
52
+ smtpPrefill: SmtpPrefill;
53
+ turnstilePrefill: { siteKey: string };
54
+ }
55
+
56
+ type StepId = 'connection' | 'storage' | 'email' | 'bot' | 'signups' | 'admin';
57
+
58
+ const STEP_TITLES: Record<StepId, string> = {
59
+ connection: 'Database connection',
60
+ storage: 'Media storage',
61
+ email: 'Email (SMTP)',
62
+ bot: 'Bot protection',
63
+ signups: 'Sign-ups',
64
+ admin: 'Administrator account',
65
+ };
66
+
67
+ const CHANNEL_LABEL: Record<DeployChannel, string> = {
68
+ docker: 'Self-hosted Docker',
69
+ vercel: 'Vercel',
70
+ local: 'Local development',
71
+ };
72
+
73
+ type Msg = { ok: string } | { err: string } | null;
74
+
75
+ export default function SetupWizard({
76
+ channel,
77
+ configured,
78
+ writable,
79
+ siteUrl,
80
+ storagePrefill,
81
+ smtpPrefill,
82
+ turnstilePrefill,
83
+ }: Props) {
84
+ const [isPending, startTransition] = useTransition();
85
+ const [message, setMessage] = useState<Msg>(null);
86
+ const [phase, setPhase] = useState<'form' | 'working' | 'done'>('form');
87
+
88
+ // Connection (Profile B / local only).
89
+ const [conn, setConn] = useState({
90
+ supabaseUrl: '',
91
+ anonKey: '',
92
+ serviceRoleKey: '',
93
+ postgresUrl: '',
94
+ accessToken: '',
95
+ siteUrl,
96
+ });
97
+ const [connectionDone, setConnectionDone] = useState(configured);
98
+ // "Start from a clean database" — only offered/honored on a local fresh install.
99
+ const [resetFirst, setResetFirst] = useState(true);
100
+
101
+ // Storage / SMTP / bot / signups / admin.
102
+ const [storage, setStorage] = useState(storagePrefill);
103
+ const [smtp, setSmtp] = useState({ ...smtpPrefill, pass: '' });
104
+ const [turnstileEnabled, setTurnstileEnabled] = useState(false);
105
+ const [turnstile, setTurnstile] = useState({
106
+ siteKey: turnstilePrefill.siteKey,
107
+ secretKey: '',
108
+ });
109
+ const [autoAccept, setAutoAccept] = useState(false); // off by default (defense-in-depth)
110
+ const [admin, setAdmin] = useState({ email: '', password: '', fullName: '' });
111
+
112
+ const steps = useMemo<StepId[]>(() => {
113
+ const list: StepId[] = [];
114
+ if (!configured) {
115
+ list.push('connection');
116
+ }
117
+ list.push('storage', 'email', 'bot', 'signups', 'admin');
118
+ return list;
119
+ }, [configured]);
120
+
121
+ const [stepIndex, setStepIndex] = useState(0);
122
+ const current = steps[stepIndex];
123
+ const isLast = stepIndex === steps.length - 1;
124
+
125
+ const setOk = (ok: string) => setMessage({ ok });
126
+ const setErr = (err: string) => setMessage({ err });
127
+
128
+ const goNext = () => {
129
+ setMessage(null);
130
+ setStepIndex((i) => Math.min(i + 1, steps.length - 1));
131
+ };
132
+ const goBack = () => {
133
+ setMessage(null);
134
+ setStepIndex((i) => Math.max(i - 1, 0));
135
+ };
136
+
137
+ // --- Step actions ------------------------------------------------------------
138
+
139
+ const handleSaveConnection = () => {
140
+ setMessage(null);
141
+ if (!conn.accessToken.trim() && !conn.postgresUrl.trim()) {
142
+ setErr(
143
+ 'Provide a Supabase access token (recommended) or a Postgres connection string so the schema can be applied.',
144
+ );
145
+ return;
146
+ }
147
+ startTransition(async () => {
148
+ const result = await saveSupabaseConnection({
149
+ supabaseUrl: conn.supabaseUrl,
150
+ anonKey: conn.anonKey,
151
+ serviceRoleKey: conn.serviceRoleKey,
152
+ postgresUrl: conn.postgresUrl,
153
+ accessToken: conn.accessToken,
154
+ siteUrl: conn.siteUrl,
155
+ });
156
+ if (!result.ok) {
157
+ setErr(result.error ?? 'Could not save the connection.');
158
+ return;
159
+ }
160
+ setConnectionDone(true);
161
+ setOk('Connection saved. The database schema is applied automatically when you finish.');
162
+ goNext();
163
+ });
164
+ };
165
+
166
+ const handleFinish = () => {
167
+ if (!admin.email || !admin.password) {
168
+ setErr('Enter an administrator email and password.');
169
+ return;
170
+ }
171
+ if (admin.password.length < 8) {
172
+ setErr('Use a password of at least 8 characters.');
173
+ return;
174
+ }
175
+
176
+ const envValues: Record<string, string> = {};
177
+ if (writable && channel === 'local') {
178
+ const put = (k: string, v: string) => {
179
+ if (v && v.trim()) envValues[k] = v.trim();
180
+ };
181
+ put('R2_ACCOUNT_ID', storage.accountId);
182
+ put('R2_BUCKET_NAME', storage.bucket);
183
+ put('R2_ACCESS_KEY_ID', storage.accessKeyId);
184
+ put('R2_SECRET_ACCESS_KEY', storage.secretAccessKey);
185
+ // Both must hold the bucket's public read URL: image src is built from
186
+ // NEXT_PUBLIC_R2_BASE_URL, while next.config remotePatterns + CSP read
187
+ // NEXT_PUBLIC_R2_PUBLIC_URL. The wizard collects one URL and writes it to both
188
+ // (baseUrl only differs if a channel prefilled a separate custom domain).
189
+ put('NEXT_PUBLIC_R2_PUBLIC_URL', storage.publicUrl);
190
+ put('NEXT_PUBLIC_R2_BASE_URL', storage.baseUrl || storage.publicUrl);
191
+ put('SMTP_HOST', smtp.host);
192
+ put('SMTP_PORT', smtp.port);
193
+ put('SMTP_USER', smtp.user);
194
+ put('SMTP_PASS', smtp.pass);
195
+ put('SMTP_FROM_EMAIL', smtp.fromEmail);
196
+ put('SMTP_FROM_NAME', smtp.fromName);
197
+ }
198
+
199
+ setMessage(null);
200
+ setPhase('working');
201
+ startTransition(async () => {
202
+ const result = await completeSetup({
203
+ admin,
204
+ autoAcceptSignups: autoAccept,
205
+ envValues,
206
+ resetFirst: resetFirst && writable,
207
+ turnstile: turnstileEnabled
208
+ ? { provider: 'turnstile', siteKey: turnstile.siteKey, secretKey: turnstile.secretKey }
209
+ : { provider: 'none', siteKey: '', secretKey: '' },
210
+ });
211
+
212
+ if (!result.ok) {
213
+ setErr(result.error ?? 'Setup failed.');
214
+ setPhase('form');
215
+ return;
216
+ }
217
+
218
+ // Establish the session via the canonical sign-in path (reliable cookie), which
219
+ // redirects into the CMS. With the runtime public-env injection the client works
220
+ // without a dev-server restart.
221
+ const signInData = new FormData();
222
+ signInData.append('email', admin.email.trim());
223
+ signInData.append('password', admin.password);
224
+ await signInAction(signInData);
225
+
226
+ // signInAction redirects on success (and on failure, to /sign-in with a message),
227
+ // so this only runs in the unlikely case it returned without navigating.
228
+ setPhase('done');
229
+ });
230
+ };
231
+
232
+ // --- Render ------------------------------------------------------------------
233
+
234
+ if (phase === 'working') {
235
+ return (
236
+ <div className="space-y-6">
237
+ <SetupProgress willReset={resetFirst && writable} />
238
+ </div>
239
+ );
240
+ }
241
+
242
+ if (phase === 'done') {
243
+ return (
244
+ <div className="space-y-6">
245
+ <SetupDone />
246
+ </div>
247
+ );
248
+ }
249
+
250
+ const alert =
251
+ message &&
252
+ ('ok' in message ? (
253
+ <Alert variant="success" className="py-2 px-4">
254
+ <AlertDescription>{message.ok}</AlertDescription>
255
+ </Alert>
256
+ ) : (
257
+ <Alert variant="destructive" className="py-2 px-4">
258
+ <AlertDescription>{message.err}</AlertDescription>
259
+ </Alert>
260
+ ));
261
+
262
+ return (
263
+ <div className="space-y-6">
264
+ <div className="space-y-2 text-center">
265
+ <h1 className="text-2xl font-semibold">Welcome to NextBlock</h1>
266
+ <div className="text-sm text-muted-foreground">
267
+ Let&rsquo;s get your CMS running. Detected environment:{' '}
268
+ <Badge variant="secondary">{CHANNEL_LABEL[channel]}</Badge>
269
+ </div>
270
+ </div>
271
+
272
+ <Stepper steps={steps} stepIndex={stepIndex} />
273
+
274
+ <Card>
275
+ <CardHeader>
276
+ <CardTitle>{STEP_TITLES[current]}</CardTitle>
277
+ <CardDescription>{stepDescription(current, channel)}</CardDescription>
278
+ </CardHeader>
279
+ <CardContent className="space-y-5">
280
+ {alert}
281
+
282
+ {current === 'connection' && (
283
+ <div className="space-y-4">
284
+ <Field label="Supabase URL" htmlFor="supabaseUrl">
285
+ <Input
286
+ id="supabaseUrl"
287
+ placeholder="https://YOUR-PROJECT.supabase.co"
288
+ value={conn.supabaseUrl}
289
+ onChange={(e) => setConn({ ...conn, supabaseUrl: e.target.value })}
290
+ />
291
+ </Field>
292
+ <Field label="Anon (publishable) key" htmlFor="anonKey">
293
+ <Input
294
+ id="anonKey"
295
+ value={conn.anonKey}
296
+ onChange={(e) => setConn({ ...conn, anonKey: e.target.value })}
297
+ />
298
+ </Field>
299
+ <Field label="Service-role (secret) key" htmlFor="serviceRoleKey">
300
+ <Input
301
+ id="serviceRoleKey"
302
+ type="password"
303
+ value={conn.serviceRoleKey}
304
+ onChange={(e) => setConn({ ...conn, serviceRoleKey: e.target.value })}
305
+ />
306
+ </Field>
307
+ <Field label="Supabase access token" htmlFor="accessToken">
308
+ <Input
309
+ id="accessToken"
310
+ type="password"
311
+ placeholder="sbp_… (Account → Access Tokens)"
312
+ value={conn.accessToken}
313
+ onChange={(e) => setConn({ ...conn, accessToken: e.target.value })}
314
+ />
315
+ <p className="text-xs text-muted-foreground">
316
+ Recommended — lets the wizard apply the database schema over HTTPS (works on any
317
+ network, no database host to reach).
318
+ </p>
319
+ </Field>
320
+ <Field label="Postgres connection string (optional)" htmlFor="postgresUrl">
321
+ <Input
322
+ id="postgresUrl"
323
+ placeholder="postgresql://postgres.<ref>:[password]@aws-0-<region>.pooler.supabase.com:5432/postgres"
324
+ value={conn.postgresUrl}
325
+ onChange={(e) => setConn({ ...conn, postgresUrl: e.target.value })}
326
+ />
327
+ <p className="text-xs text-muted-foreground">
328
+ Fallback used only if no access token is given. Use the <strong>Session pooler</strong>{' '}
329
+ string (Supabase → Connect → Session pooler); the &ldquo;direct&rdquo;{' '}
330
+ <code>db.&lt;ref&gt;.supabase.co</code> host fails on IPv4-only networks.
331
+ </p>
332
+ </Field>
333
+ <Field label="Public site URL (optional)" htmlFor="siteUrl">
334
+ <Input
335
+ id="siteUrl"
336
+ placeholder="http://localhost:4200"
337
+ value={conn.siteUrl}
338
+ onChange={(e) => setConn({ ...conn, siteUrl: e.target.value })}
339
+ />
340
+ </Field>
341
+ {!writable && (
342
+ <Alert variant="destructive" className="py-2 px-4">
343
+ <AlertDescription>
344
+ This environment is read-only. Set the Supabase variables on your hosting
345
+ platform; this step only works in local development.
346
+ </AlertDescription>
347
+ </Alert>
348
+ )}
349
+ </div>
350
+ )}
351
+
352
+ {current === 'storage' && (
353
+ <StorageStep storage={storage} setStorage={setStorage} channel={channel} />
354
+ )}
355
+
356
+ {current === 'email' && (
357
+ <div className="space-y-4">
358
+ {channel === 'docker' && (
359
+ <p className="text-xs text-muted-foreground">
360
+ Docker auto-confirms sign-ups when SMTP is not configured, so this is optional.
361
+ </p>
362
+ )}
363
+ <div className="grid gap-4 sm:grid-cols-2">
364
+ <Field label="SMTP host" htmlFor="smtpHost">
365
+ <Input
366
+ id="smtpHost"
367
+ value={smtp.host}
368
+ onChange={(e) => setSmtp({ ...smtp, host: e.target.value })}
369
+ />
370
+ </Field>
371
+ <Field label="Port" htmlFor="smtpPort">
372
+ <Input
373
+ id="smtpPort"
374
+ value={smtp.port}
375
+ onChange={(e) => setSmtp({ ...smtp, port: e.target.value })}
376
+ />
377
+ </Field>
378
+ <Field label="Username" htmlFor="smtpUser">
379
+ <Input
380
+ id="smtpUser"
381
+ value={smtp.user}
382
+ onChange={(e) => setSmtp({ ...smtp, user: e.target.value })}
383
+ />
384
+ </Field>
385
+ <Field label="Password" htmlFor="smtpPass">
386
+ <Input
387
+ id="smtpPass"
388
+ type="password"
389
+ value={smtp.pass}
390
+ onChange={(e) => setSmtp({ ...smtp, pass: e.target.value })}
391
+ />
392
+ </Field>
393
+ <Field label="From email" htmlFor="smtpFromEmail">
394
+ <Input
395
+ id="smtpFromEmail"
396
+ value={smtp.fromEmail}
397
+ onChange={(e) => setSmtp({ ...smtp, fromEmail: e.target.value })}
398
+ />
399
+ </Field>
400
+ <Field label="From name" htmlFor="smtpFromName">
401
+ <Input
402
+ id="smtpFromName"
403
+ value={smtp.fromName}
404
+ onChange={(e) => setSmtp({ ...smtp, fromName: e.target.value })}
405
+ />
406
+ </Field>
407
+ </div>
408
+ {!writable && channel !== 'docker' && (
409
+ <p className="text-xs text-muted-foreground">
410
+ On this platform, set SMTP_* as environment variables in your hosting dashboard.
411
+ </p>
412
+ )}
413
+ </div>
414
+ )}
415
+
416
+ {current === 'bot' && (
417
+ <div className="space-y-4">
418
+ <label className="flex items-start gap-3">
419
+ <Checkbox
420
+ checked={turnstileEnabled}
421
+ onCheckedChange={(c) => setTurnstileEnabled(c === true)}
422
+ className="mt-1"
423
+ />
424
+ <span className="text-sm">
425
+ <span className="font-medium">Enable Cloudflare Turnstile</span>
426
+ <span className="block text-xs text-muted-foreground">
427
+ Protects sign-up / sign-in forms. Stored securely in the database.
428
+ </span>
429
+ </span>
430
+ </label>
431
+ {turnstileEnabled && (
432
+ <div className="grid gap-4 sm:grid-cols-2">
433
+ <Field label="Site key" htmlFor="tsSite">
434
+ <Input
435
+ id="tsSite"
436
+ value={turnstile.siteKey}
437
+ onChange={(e) => setTurnstile({ ...turnstile, siteKey: e.target.value })}
438
+ />
439
+ </Field>
440
+ <Field label="Secret key" htmlFor="tsSecret">
441
+ <Input
442
+ id="tsSecret"
443
+ type="password"
444
+ value={turnstile.secretKey}
445
+ onChange={(e) => setTurnstile({ ...turnstile, secretKey: e.target.value })}
446
+ />
447
+ </Field>
448
+ </div>
449
+ )}
450
+ </div>
451
+ )}
452
+
453
+ {current === 'signups' && (
454
+ <label className="flex items-start gap-3">
455
+ <Checkbox
456
+ checked={autoAccept}
457
+ onCheckedChange={(c) => setAutoAccept(c === true)}
458
+ className="mt-1"
459
+ />
460
+ <span className="text-sm">
461
+ <span className="font-medium">
462
+ Auto-approve local registrations (skip outbound email verification)
463
+ </span>
464
+ <span className="block text-xs text-muted-foreground">
465
+ New sign-ups become active immediately, even without SMTP configured. Convenient
466
+ for local / self-hosted use; leave off for public production sites.
467
+ </span>
468
+ </span>
469
+ </label>
470
+ )}
471
+
472
+ {current === 'admin' && (
473
+ <div className="space-y-4">
474
+ <Field label="Full name" htmlFor="adminName">
475
+ <Input
476
+ id="adminName"
477
+ value={admin.fullName}
478
+ onChange={(e) => setAdmin({ ...admin, fullName: e.target.value })}
479
+ />
480
+ </Field>
481
+ <Field label="Email" htmlFor="adminEmail">
482
+ <Input
483
+ id="adminEmail"
484
+ type="email"
485
+ value={admin.email}
486
+ onChange={(e) => setAdmin({ ...admin, email: e.target.value })}
487
+ />
488
+ </Field>
489
+ <Field label="Password" htmlFor="adminPassword">
490
+ <Input
491
+ id="adminPassword"
492
+ type="password"
493
+ value={admin.password}
494
+ onChange={(e) => setAdmin({ ...admin, password: e.target.value })}
495
+ />
496
+ </Field>
497
+ <p className="text-xs text-muted-foreground">
498
+ This first account becomes the site administrator, created already-confirmed (no
499
+ verification email needed). Finishing also applies the database schema and saved
500
+ settings, so it can take up to a minute.
501
+ </p>
502
+
503
+ {writable && (
504
+ <label className="flex items-start gap-3 rounded-lg border p-3">
505
+ <Checkbox
506
+ checked={resetFirst}
507
+ onCheckedChange={(c) => setResetFirst(c === true)}
508
+ className="mt-1"
509
+ />
510
+ <span className="text-sm">
511
+ <span className="font-medium">Start from a clean database</span>
512
+ <span className="block text-xs text-muted-foreground">
513
+ Recommended for a fresh install. Wipes any existing tables, migration history,
514
+ and users in this Supabase project before installing. Uncheck if this database
515
+ already has data you want to keep.
516
+ </span>
517
+ </span>
518
+ </label>
519
+ )}
520
+ </div>
521
+ )}
522
+
523
+ <Separator />
524
+
525
+ <div className="flex items-center justify-between">
526
+ <Button variant="ghost" onClick={goBack} disabled={isPending || stepIndex === 0}>
527
+ Back
528
+ </Button>
529
+
530
+ {current === 'connection' ? (
531
+ <Button onClick={handleSaveConnection} disabled={isPending || !writable}>
532
+ {isPending ? <Spinner className="mr-2 h-4 w-4 animate-spin" /> : null}
533
+ Save &amp; verify
534
+ </Button>
535
+ ) : isLast ? (
536
+ <Button onClick={handleFinish} disabled={isPending}>
537
+ {isPending ? <Spinner className="mr-2 h-4 w-4 animate-spin" /> : null}
538
+ Finish setup
539
+ </Button>
540
+ ) : (
541
+ <Button onClick={goNext} disabled={!connectionDone && !configured}>
542
+ Next
543
+ </Button>
544
+ )}
545
+ </div>
546
+ </CardContent>
547
+ </Card>
548
+ </div>
549
+ );
550
+ }
551
+
552
+ function stepDescription(step: StepId, channel: DeployChannel): string {
553
+ switch (step) {
554
+ case 'connection':
555
+ return 'Connect this instance to your Supabase project.';
556
+ case 'storage':
557
+ return channel === 'docker'
558
+ ? 'Your Docker stack uses MinIO for media storage — already wired up.'
559
+ : channel === 'vercel'
560
+ ? 'Using Supabase Storage (S3-compatible) for media.'
561
+ : 'Bring your own Cloudflare R2 bucket for media storage.';
562
+ case 'email':
563
+ return 'Optional. Used for verification emails, password resets, and 2FA codes.';
564
+ case 'bot':
565
+ return 'Optional. Add Cloudflare Turnstile to your auth forms.';
566
+ case 'signups':
567
+ return 'Choose how new public registrations are handled.';
568
+ case 'admin':
569
+ return 'Create the first administrator account.';
570
+ default:
571
+ return '';
572
+ }
573
+ }
574
+
575
+ const PROGRESS_MESSAGES = [
576
+ 'Laying the foundation blocks…',
577
+ 'Seeding the first blocks…',
578
+ 'Stacking a few more blocks…',
579
+ 'Teaching the blocks to speak (translations)…',
580
+ 'Waiting on some stubborn blocks…',
581
+ 'Polishing the blocks until they shine…',
582
+ 'Almost there — slotting in the last blocks…',
583
+ ];
584
+
585
+ function SetupProgress({ willReset }: { willReset: boolean }) {
586
+ const messages = willReset
587
+ ? ['Wiping the old blocks away…', ...PROGRESS_MESSAGES]
588
+ : PROGRESS_MESSAGES;
589
+ const [pct, setPct] = useState(8);
590
+ const [msgIndex, setMsgIndex] = useState(0);
591
+
592
+ useEffect(() => {
593
+ // Indeterminate work (one server action) shown as a friendly creeping bar that eases
594
+ // toward ~92% and a rotating set of block-themed messages.
595
+ const progress = setInterval(() => {
596
+ setPct((value) => (value >= 92 ? 92 : value + Math.max(1, Math.round((96 - value) / 14))));
597
+ }, 700);
598
+ const cycle = setInterval(() => {
599
+ setMsgIndex((index) => (index + 1) % messages.length);
600
+ }, 2200);
601
+ return () => {
602
+ clearInterval(progress);
603
+ clearInterval(cycle);
604
+ };
605
+ }, [messages.length]);
606
+
607
+ return (
608
+ <Card>
609
+ <CardHeader>
610
+ <CardTitle>Building your NextBlock…</CardTitle>
611
+ <CardDescription>
612
+ {willReset ? 'Resetting the database, then applying' : 'Applying'} the schema, seeding
613
+ content, and creating your account. This can take a minute — hang tight.
614
+ </CardDescription>
615
+ </CardHeader>
616
+ <CardContent className="space-y-4">
617
+ <div className="h-2 w-full overflow-hidden rounded-full bg-muted">
618
+ <div
619
+ className="h-full rounded-full bg-primary transition-all duration-700 ease-out"
620
+ style={{ width: `${pct}%` }}
621
+ />
622
+ </div>
623
+ <p className="text-sm text-muted-foreground">{messages[msgIndex]}</p>
624
+ </CardContent>
625
+ </Card>
626
+ );
627
+ }
628
+
629
+ function SetupDone() {
630
+ return (
631
+ <Card>
632
+ <CardHeader>
633
+ <CardTitle>🎉 Setup complete!</CardTitle>
634
+ <CardDescription>
635
+ Your administrator account is ready and the database is seeded.
636
+ </CardDescription>
637
+ </CardHeader>
638
+ <CardContent>
639
+ <Button onClick={() => (window.location.href = '/cms/dashboard')}>Enter your CMS</Button>
640
+ </CardContent>
641
+ </Card>
642
+ );
643
+ }
644
+
645
+ function Stepper({
646
+ steps,
647
+ stepIndex,
648
+ }: {
649
+ steps: StepId[];
650
+ stepIndex: number;
651
+ }) {
652
+ return (
653
+ <ol className="flex flex-wrap items-center justify-center gap-2 text-xs">
654
+ {steps.map((s, i) => (
655
+ <li
656
+ key={s}
657
+ className={`flex items-center gap-2 rounded-full border px-3 py-1 ${
658
+ i === stepIndex
659
+ ? 'border-primary text-primary'
660
+ : i < stepIndex
661
+ ? 'border-muted text-muted-foreground'
662
+ : 'border-muted text-muted-foreground/60'
663
+ }`}
664
+ >
665
+ <span className="font-medium">{i + 1}</span>
666
+ <span>{STEP_TITLES[s]}</span>
667
+ </li>
668
+ ))}
669
+ </ol>
670
+ );
671
+ }
672
+
673
+ function StorageStep({
674
+ storage,
675
+ setStorage,
676
+ channel,
677
+ }: {
678
+ storage: StoragePrefill;
679
+ setStorage: (s: StoragePrefill) => void;
680
+ channel: DeployChannel;
681
+ }) {
682
+ if (channel === 'docker') {
683
+ return (
684
+ <div className="space-y-3 text-sm">
685
+ <Alert variant="success" className="py-2 px-4">
686
+ <AlertDescription>
687
+ MinIO is already configured by the Docker setup. Nothing to do here.
688
+ </AlertDescription>
689
+ </Alert>
690
+ <dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-xs text-muted-foreground">
691
+ <dt>Endpoint</dt>
692
+ <dd className="font-mono">{storage.endpoint}</dd>
693
+ <dt>Bucket</dt>
694
+ <dd className="font-mono">{storage.bucket}</dd>
695
+ <dt>Public URL</dt>
696
+ <dd className="font-mono">{storage.publicUrl}</dd>
697
+ </dl>
698
+ </div>
699
+ );
700
+ }
701
+
702
+ return (
703
+ <div className="space-y-4">
704
+ {channel === 'vercel' && (
705
+ <p className="text-xs text-muted-foreground">
706
+ Pre-filled for Supabase Storage. Create an S3 access key in your Supabase project
707
+ (Storage → S3 connection) and set R2_ACCESS_KEY_ID / R2_SECRET_ACCESS_KEY in your Vercel
708
+ environment.
709
+ </p>
710
+ )}
711
+ <div className="grid gap-4 sm:grid-cols-2">
712
+ <Field label="Account / provider id" htmlFor="r2Account">
713
+ <Input
714
+ id="r2Account"
715
+ value={storage.accountId}
716
+ onChange={(e) => setStorage({ ...storage, accountId: e.target.value })}
717
+ />
718
+ </Field>
719
+ <Field label="Bucket" htmlFor="r2Bucket">
720
+ <Input
721
+ id="r2Bucket"
722
+ value={storage.bucket}
723
+ onChange={(e) => setStorage({ ...storage, bucket: e.target.value })}
724
+ />
725
+ </Field>
726
+ <Field label="Access key id" htmlFor="r2Access">
727
+ <Input
728
+ id="r2Access"
729
+ value={storage.accessKeyId}
730
+ onChange={(e) => setStorage({ ...storage, accessKeyId: e.target.value })}
731
+ />
732
+ </Field>
733
+ <Field label="Secret access key" htmlFor="r2Secret">
734
+ <Input
735
+ id="r2Secret"
736
+ type="password"
737
+ value={storage.secretAccessKey}
738
+ onChange={(e) => setStorage({ ...storage, secretAccessKey: e.target.value })}
739
+ />
740
+ </Field>
741
+ </div>
742
+ <Field label="Public bucket URL" htmlFor="r2Public">
743
+ <Input
744
+ id="r2Public"
745
+ placeholder="https://pub-xxxx.r2.dev"
746
+ value={storage.publicUrl}
747
+ onChange={(e) => setStorage({ ...storage, publicUrl: e.target.value })}
748
+ />
749
+ <p className="mt-1 text-xs text-muted-foreground">
750
+ Your bucket&apos;s public URL (Cloudflare R2 → your bucket → Public Development URL)
751
+ or a custom domain. Used to serve all media on your site.
752
+ </p>
753
+ </Field>
754
+ </div>
755
+ );
756
+ }
757
+
758
+ function Field({
759
+ label,
760
+ htmlFor,
761
+ children,
762
+ }: {
763
+ label: string;
764
+ htmlFor: string;
765
+ children: React.ReactNode;
766
+ }) {
767
+ return (
768
+ <div className="space-y-1.5">
769
+ <Label htmlFor={htmlFor}>{label}</Label>
770
+ {children}
771
+ </div>
772
+ );
773
+ }