import { useState } from 'react' import { api } from '../api' import { ErrorBox } from '../hooks' const csv = (s) => s.split(',').map((x) => x.trim()).filter(Boolean) // mode="create": standalone form on the home screen. // mode="edit": step 1 of the wizard, edits the existing project. export default function SetupStep({ mode, data, refreshProject, setStep, onCreated, onCancel }) { const refresh = refreshProject const project = data?.project const [form, setForm] = useState(() => ({ name: project?.name || '', topic: project?.niche.topic || '', keywords: project?.niche.keywords.join(', ') || '', subreddits: project?.niche.subreddits.join(', ') || '', audience: project?.niche.audience || '', tone: project?.niche.tone || '', format: project?.format || 'youtube_short', })) const [busy, setBusy] = useState(false) const [filling, setFilling] = useState(false) const [error, setError] = useState('') const set = (k) => (e) => setForm({ ...form, [k]: e.target.value }) // Ask the LLM to derive the remaining fields from the niche topic. // Only fills columns the user left blank, so it never overwrites their input. const autofill = async () => { if (!form.topic.trim()) { setError('Enter a niche topic first.'); return } setFilling(true) setError('') try { const s = await api.post('/api/niche/suggest', { topic: form.topic.trim() }) setForm((f) => ({ ...f, name: f.name.trim() || s.name || '', keywords: f.keywords.trim() || (s.keywords || []).join(', '), subreddits: f.subreddits.trim() || (s.subreddits || []).join(', '), audience: f.audience.trim() || s.audience || '', tone: f.tone.trim() || s.tone || '', })) } catch (e) { setError(e.message) } finally { setFilling(false) } } const body = () => ({ name: form.name || form.topic, niche: { topic: form.topic, keywords: csv(form.keywords), subreddits: csv(form.subreddits), audience: form.audience, tone: form.tone, }, format: form.format, references: project ? project.references : [], }) const submit = async () => { if (!form.topic.trim()) { setError('A niche topic is required.'); return } setBusy(true) setError('') try { if (mode === 'create') { const created = await api.post('/api/projects', body()) onCreated(created) } else { await api.patch(`/api/projects/${project.id}`, body()) await refresh() setStep(1) } } catch (e) { setError(e.message) } finally { setBusy(false) } } return (

{mode === 'create' ? 'New project' : 'Project setup'}

Define the niche. Nothing here is hardcoded — every later stage builds on these fields.

{onCancel && }
) }