'use client' import { useRouter } from 'next/navigation' import { useState } from 'react' import type { SpeechCutTextUpdateResponse } from '@/app/(campaign)/campanha/(app)/comunicacao/acervo/cortes/[id]/types' import { Alert, AlertDescription } from '@/components/ui/Alert' import { Button } from '@/components/ui/button' import { Field, FieldLabel } from '@/components/ui/field' import { Input } from '@/components/ui/input' import { Spinner } from '@/components/ui/Spinner' import { Textarea } from '@/components/ui/textarea' import { postCampaignJson } from '@/lib/campaignJsonRequest' import { SPEECH_CUT_DESCRIPTION_MAX_LENGTH, SPEECH_CUT_TITLE_MAX_LENGTH } from '@/lib/speechCut' type SpeechCutTextEditorProps = { cutId: number initialTitle: string initialDescription: string } /** * C168 — edits the cut's own title/description through the JSON route. Saving * refreshes the server tree, so the public page and the link preview reflect * the new text (the `afterChange` revalidation is the C167 one). Only rendered * for a cut with a stored file; a pending/failed one shows the C183 placeholder. */ export const SpeechCutTextEditor = ({ cutId, initialTitle, initialDescription, }: SpeechCutTextEditorProps) => { const router = useRouter() const [title, setTitle] = useState(initialTitle) const [description, setDescription] = useState(initialDescription) const [saved, setSaved] = useState({ title: initialTitle, description: initialDescription }) const [submitting, setSubmitting] = useState(false) const [feedback, setFeedback] = useState<'idle' | 'saved' | 'error'>('idle') const [error, setError] = useState(null) const trimmedTitle = title.trim() const trimmedDescription = description.trim() const dirty = trimmedTitle !== saved.title.trim() || trimmedDescription !== saved.description.trim() const canSave = dirty && trimmedTitle.length > 0 && trimmedDescription.length > 0 && !submitting const save = async () => { setSubmitting(true) setFeedback('idle') setError(null) try { const { ok, payload } = await postCampaignJson( `/campanha/comunicacao/acervo/cortes/${cutId}/texto`, { cutId, title: trimmedTitle, description: trimmedDescription }, ) if (!ok || payload.status !== 'success') { setFeedback('error') setError( payload.status === 'error' ? payload.message : 'Não foi possível salvar as alterações.', ) return } setSaved({ title: trimmedTitle, description: trimmedDescription }) setFeedback('saved') router.refresh() } catch { setFeedback('error') setError('Não foi possível salvar as alterações.') } finally { setSubmitting(false) } } return (

Editar título e descrição

O que você salvar aqui aparece na página pública e no preview do link.

Título { setTitle(event.target.value) setFeedback('idle') }} /> Descrição