'use client' import { CircleAlertIcon, LinkIcon } from 'lucide-react' import { useRouter } from 'next/navigation' import { useState, type ReactNode } from 'react' import type { ContentPieceLinkResponse } from '@/app/(campaign)/campanha/(app)/comunicacao/conteudos/types' import { Alert, AlertDescription } from '@/components/ui/Alert' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Spinner } from '@/components/ui/Spinner' import { postCampaignJson } from '@/lib/campaignJsonRequest' import { CAMPAIGN_CONTENT_PIECE_LINK_HREF } from '@/lib/campaignPaths' import { CONTENT_PIECE_LINK_INVALID_MESSAGE } from '@/lib/schemas/contentPiece' import { cn } from '@/lib/utils' const GENERIC_ERROR_MESSAGE = 'Não foi possível adicionar a peça. Tente novamente.' /** * C211 — "Adicionar por link" (approved design scene 3): the assessoria pastes * an Instagram/YouTube publication and the piece enters the same catalogue. The * panel states the product rule up front — no scraping; when the platform * offers no official path the piece circulates by link and the original can be * attached. */ export const AddContentPieceLinkDialog = ({ triggerClassName, triggerLabel = 'Adicionar por link', }: { triggerClassName?: string /** A node so the page can shorten the label on mobile ("Link"). */ triggerLabel?: ReactNode }) => { const router = useRouter() const [open, setOpen] = useState(false) const [url, setUrl] = useState('') const [submitting, setSubmitting] = useState(false) const [error, setError] = useState(null) const submit = async () => { const trimmed = url.trim() if (!trimmed) { setError(CONTENT_PIECE_LINK_INVALID_MESSAGE) return } setSubmitting(true) setError(null) try { const { ok, payload } = await postCampaignJson( CAMPAIGN_CONTENT_PIECE_LINK_HREF, { url: trimmed }, ) if (!ok || payload.status !== 'success') { setError(payload.status === 'error' ? payload.message : GENERIC_ERROR_MESSAGE) return } setUrl('') setOpen(false) router.refresh() } catch { setError(GENERIC_ERROR_MESSAGE) } finally { setSubmitting(false) } } return ( { if (submitting) return setOpen(next) if (!next) { setUrl('') setError(null) } }} > Adicionar por link Instagram ou YouTube. Conteúdo próprio é extraído somente quando a plataforma oferece caminho oficial.
{ setUrl(event.target.value) if (error) setError(null) }} placeholder="https://www.instagram.com/reel/…" className="mt-1.5 min-h-11" aria-invalid={error ? true : undefined} onKeyDown={(event) => { if (event.key === 'Enter') { event.preventDefault() void submit() } }} />
Sem scraping.
Se não houver acesso oficial à mídia, a peça continua pelo link e o arquivo original pode ser anexado.
  • Mídia encontrada na conta oficial: o arquivo entra na peça e passa pelo mesmo processamento do envio.
  • Sem caminho oficial: a peça nasce como peça-link e a assessoria pode anexar o arquivo original. Mídia de terceiro nunca é baixada.
{error ? ( ) : null}
) }