teqo/src/components/CampaignContentCard.tsx
Francisco Solla a638a8acae feat(S3): seção de conteúdos da home de campanha inclui os posts do Instagram
Board "Acompanhe de perto" (S1+S2) ganha o feed automático do perfil oficial:
loader irmão src/utilities/socialFeed/instagramFeed.ts (Graph API /media com
children p/ carrossel + username, unstable_cache tag social-feed + revalidate
300, snapshot cru pré-exclusão persistido via SQL direto, refresh de token
automático com retry 1x — refresh endpoint só renova tokens de Instagram
Login, page tokens caem no fail-closed), global SocialFeedSettings estendida
(instagramEnabled/AccessToken/UserId/MaxItems + snapshot hidden; excludedItems
já cobria a plataforma desde a S2). Requisito nº 1 — picker de exclusão no
admin (primeiro componente custom do repo, campo ui + importmap): lista os
posts do snapshot com thumbnail e toggle "Não exibir" que escreve em
excludedItems. Card com coverAspect square (1:1 do rascunho), badge
Instagram, título = legenda com fallback para post sem legenda, clique no
permalink (noopener), link "Seguir no Instagram →" derivado do username.
Os feeds externos mudam para o subfolder socialFeed/ (pin da S2 previa).
Migration 20260818_192948_add_instagram_social_feed_fields (não destrutiva).
Stub IG no webServer (porta dev+2000, helper socialStub.ts) + 3 e2e novos no
describe serial + kill switch estendido + smoke do picker no admin.
Closes #20
2026-08-18 20:29:50 -03:00

86 lines
2.9 KiB
TypeScript

import Image from 'next/image'
import Link from 'next/link'
export type CampaignContentCardData = {
id: string | number
href: string
title: string
badgeLabel: string
meta: string
coverUrl?: string
coverAlt?: string
subtitle?: string
/** Cover ratio: 16:9 for articles/videos, 1:1 for Instagram posts. */
coverAspect?: 'video' | 'square'
/** External target (e.g. a YouTube video): opens in a new tab with noopener. */
external?: boolean
}
type CampaignContentCardProps = {
card: CampaignContentCardData
featured?: boolean
}
const cardClassName = (featured: boolean) =>
`group flex h-full flex-col rounded-xl border border-(--campaign-line) bg-white p-3 shadow-sm transition-shadow hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--pt-red) ${
featured ? 'gap-3' : 'gap-2'
}`
/**
* Presentational content card for the campaign home content bento/carousel —
* one spelling for every source (article, YouTube, Instagram in S3). Internal
* targets use `Link`; external ones open on the platform in a new tab with
* `noopener` (no inline player, per the approved wireframe).
*/
export const CampaignContentCard = ({ card, featured = false }: CampaignContentCardProps) => {
const inner = (
<>
<div
className={`relative w-full shrink-0 overflow-hidden rounded-lg bg-(--campaign-band) ${
card.coverAspect === 'square' ? 'aspect-square' : 'aspect-video'
}`}
>
{card.coverUrl ? (
<Image
src={card.coverUrl}
alt={card.coverAlt ?? card.title}
fill
sizes={featured ? '(min-width: 768px) 44vw, 92vw' : '(min-width: 768px) 22vw, 92vw'}
className="object-cover transition-transform duration-300 group-hover:scale-[1.03] motion-reduce:transition-none motion-reduce:group-hover:scale-100"
/>
) : null}
<span className="absolute top-2 left-2 rounded-full bg-(--pt-red-dark) px-2 py-0.5 text-[10px] font-bold tracking-wider text-white uppercase">
{card.badgeLabel}
</span>
</div>
<div className="flex flex-1 flex-col gap-1">
<h3
className={`leading-snug font-bold text-(--campaign-ink) group-hover:underline ${
featured ? 'text-base' : 'text-sm'
}`}
>
{card.title}
</h3>
{featured && card.subtitle ? (
<p className="text-xs leading-relaxed text-(--campaign-muted)">{card.subtitle}</p>
) : null}
<span className="mt-auto text-xs text-(--campaign-muted)">{card.meta}</span>
</div>
</>
)
return card.external ? (
<a
href={card.href}
target="_blank"
rel="noopener noreferrer"
className={cardClassName(featured)}
>
{inner}
</a>
) : (
<Link href={card.href} className={cardClassName(featured)}>
{inner}
</Link>
)
}