mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-18 05:53:05 +00:00
Envio em lote (1 request raw-body por arquivo, fan-out ≤2, até 50 arquivos) e adicionar por link (Instagram/YouTube; extração só pela Graph API da conta própria, senão peça-link) em /campanha/comunicacao/conteudos. Cada peça tem estado próprio (Processando/Pronto/Falhou + Reprocessar), transcrição/texto e catalogação automática revisável; publicar/despublicar preserva arquivo, slug e publishedAt. - collections contentPiece + contentMedia (upload privado no S3) e migration 20260923_032714_add_content_piece (slug único gerado no 1º publish, sourceUrl única, searchText com índice trigram) - pipeline reusa C199 (job after() + reaper + retry condicional, transcrição DeepInfra, ffmpeg/chunk), o classificador de facetas do acervo e o institutionCatalog; curatedFields impede o job de sobrescrever curadoria - gate único canReadCommunicationCatalog (advisor/leader negados); delete só pelo admin; sem Consent novo - UI portada do design aprovado (lista desktop + cards mobile, diálogo de lote com progresso por arquivo, diálogo de link, ficha editável, kill switch); nav/chrome/column-picker/manifest atualizados - instagramFeed expõe mediaUrl; revalidateTag ganha wrapper seguro fora de request (fixtures/scripts) - testes: 2 unit specs, 1 int spec (16 casos) e 7 e2e na vertical - follow-up de engenharia: #1267 (docs/plans/escala-dry-pos-c211.md) Closes #1254
84 lines
2.8 KiB
TypeScript
84 lines
2.8 KiB
TypeScript
'use client'
|
|
|
|
import { CircleAlertIcon, EyeOffIcon, SendIcon } from 'lucide-react'
|
|
import { useRouter } from 'next/navigation'
|
|
import { useState } from 'react'
|
|
|
|
import type { ContentPiecePublicationResponse } from '@/app/(campaign)/campanha/(app)/comunicacao/conteudos/types'
|
|
import { Alert, AlertDescription } from '@/components/ui/Alert'
|
|
import { Button } from '@/components/ui/button'
|
|
import { Spinner } from '@/components/ui/Spinner'
|
|
import { postCampaignJson } from '@/lib/campaignJsonRequest'
|
|
import { campaignContentPiecePublicationHref } from '@/lib/campaignPaths'
|
|
import type { ContentPieceStatus } from '@/lib/contentPiece'
|
|
|
|
const PUBLICATION_ERROR_MESSAGE = 'Não foi possível mudar a publicação. Tente novamente.'
|
|
|
|
/**
|
|
* C211 — the kill switch of one piece: "Publicar" (the first publication also
|
|
* generates the canonical slug) and "Despublicar" (takes it off the public
|
|
* Central at once, preserving the file and the link). Never a confirm dialog:
|
|
* the gesture is reversible and the badge on the screen is the receipt.
|
|
*/
|
|
export const ContentPiecePublicationButton = ({
|
|
contentPieceId,
|
|
status,
|
|
className,
|
|
}: {
|
|
contentPieceId: number
|
|
status: ContentPieceStatus
|
|
className?: string
|
|
}) => {
|
|
const router = useRouter()
|
|
const [submitting, setSubmitting] = useState(false)
|
|
const [error, setError] = useState<string | null>(null)
|
|
const published = status === 'publicado'
|
|
|
|
const toggle = async () => {
|
|
setSubmitting(true)
|
|
setError(null)
|
|
|
|
try {
|
|
const { ok, payload } = await postCampaignJson<ContentPiecePublicationResponse>(
|
|
campaignContentPiecePublicationHref(contentPieceId),
|
|
{ contentPieceId, published: !published },
|
|
)
|
|
if (!ok || payload.status !== 'success') {
|
|
setError(PUBLICATION_ERROR_MESSAGE)
|
|
return
|
|
}
|
|
router.refresh()
|
|
} catch {
|
|
setError(PUBLICATION_ERROR_MESSAGE)
|
|
} finally {
|
|
setSubmitting(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className={className}>
|
|
<Button
|
|
type="button"
|
|
variant={published ? 'outline' : 'default'}
|
|
className="min-h-11 max-md:w-full"
|
|
disabled={submitting}
|
|
onClick={() => void toggle()}
|
|
>
|
|
{submitting ? (
|
|
<Spinner data-icon="inline-start" aria-hidden="true" />
|
|
) : published ? (
|
|
<EyeOffIcon data-icon="inline-start" aria-hidden="true" />
|
|
) : (
|
|
<SendIcon data-icon="inline-start" aria-hidden="true" />
|
|
)}
|
|
{submitting ? 'Salvando…' : published ? 'Despublicar' : 'Publicar'}
|
|
</Button>
|
|
{error ? (
|
|
<Alert variant="destructive" className="mt-2 py-2">
|
|
<CircleAlertIcon aria-hidden="true" />
|
|
<AlertDescription className="text-xs">{error}</AlertDescription>
|
|
</Alert>
|
|
) : null}
|
|
</div>
|
|
)
|
|
}
|