'use client' import { useRouter } from 'next/navigation' import { useState } from 'react' import type { SpeechCutPublicationResponse } from '@/app/(campaign)/campanha/(app)/comunicacao/acervo/cortes/[id]/types' import { SpeechCutStatusBadge } from '@/components/campaign/speech/SpeechCutStatusBadge' import { Alert, AlertDescription } from '@/components/ui/Alert' import { AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from '@/components/ui/AlertDialog' import { Button } from '@/components/ui/button' import { Spinner } from '@/components/ui/Spinner' import { postCampaignJson } from '@/lib/campaignJsonRequest' import type { SpeechCutStatus } from '@/lib/speechCut' type SpeechCutPublicationPanelProps = { cutId: number status: SpeechCutStatus } const UNPUBLISH_WARNING = 'O link público deixa de funcionar para quem já recebeu. Você pode publicar de novo quando quiser.' /** * C168 — the kill switch on the detail page. Publishing restores the same * public link; unpublishing asks for confirmation with the product copy and * takes it off the air. A cut without a stored file cannot be published. */ export const SpeechCutPublicationPanel = ({ cutId, status }: SpeechCutPublicationPanelProps) => { const router = useRouter() const [submitting, setSubmitting] = useState(false) const [error, setError] = useState(null) const setPublished = async (published: boolean) => { setSubmitting(true) setError(null) try { const { ok, payload } = await postCampaignJson( `/campanha/comunicacao/acervo/cortes/${cutId}/publicacao`, { cutId, published }, ) if (!ok || payload.status !== 'success') { setError( payload.status === 'error' ? payload.message : 'Não foi possível atualizar a publicação.', ) return } router.refresh() } catch { setError('Não foi possível atualizar a publicação.') } finally { setSubmitting(false) } } return (

Publicação

{status === 'published' ? ( <>

{UNPUBLISH_WARNING}

Despublicar este corte? {UNPUBLISH_WARNING} Cancelar ) : null} {status === 'unpublished' ? ( <>

Despublicado, o link público não responde. Publique para reativar o mesmo link.

) : null} {status === 'processing' ? (

O corte ainda está sendo preparado. Assim que o arquivo ficar pronto, publique por aqui.

) : null} {status === 'failed' ? (

O corte falhou e não tem arquivo publicado. Refaça o corte no acervo de falas.

) : null} {error ? ( {error} ) : null}
) }