teqo-backup/src/components/campaign/shell/nav.ts
Francisco Solla 59983b33f7 feat(campanha): C15 — FullCalendar em /campanha/agenda
Issue #390 — entrada operacional staff com FullCalendar v7 route-local
(semana/mês/lista), filtros compartilháveis por município/deputado/tag,
criação pelo slot, detalhe por URL e remarcação drag/resize sob RBAC,
transação e lock por atividade.

- /campanha/atividades e giros permanecem como lista/fluxos legados
- Sem migration/collection nova; reutiliza activity de C14
- Fuso Bahia, range exclusivo, erro/revert, loading/empty testados
- Leader negado, advisor limitado pelo access atual
- E2E cobre filtros, drag, mobile 390x844 e slot prefill
- Int specs cobrem RBAC, concorrência e defense-in-depth

Impl: docs/plans/fullcalendar-agenda-campanha-impl.md
2026-08-07 04:37:36 -03:00

88 lines
3.4 KiB
TypeScript

import {
BookOpenIcon,
CalendarDaysIcon,
HandshakeIcon,
HomeIcon,
InboxIcon,
LandmarkIcon,
LayoutDashboardIcon,
MapIcon,
MapPinIcon,
UserCogIcon,
Users2Icon,
UsersIcon,
type LucideIcon,
} from 'lucide-react'
import { CAMPAIGN_AGENDA_HOME, LEADER_CONTACTS_HOME } from '@/lib/campaignPaths'
import { isStaffCampaignRole, isUnrestrictedCampaignRole } from '@/lib/campaignRoles'
import type { CampaignUser } from '@/payload-types'
import { canAccessSupporterArea } from '@/utilities/supporter/supporterUi'
export type CampaignNavItem = {
title: string
href: string
icon: LucideIcon
}
/**
* Named because the sidebar has to recognize this one item to hang B18's saved
* filters under it, and a third spelling that silently no-ops when it drifts is
* the failure mode this codebase keeps paying for.
*/
export const MUNICIPALITY_NAV_HREF = '/campanha/municipios'
const staffNav: CampaignNavItem[] = [
{ title: 'Início', href: '/campanha', icon: HomeIcon },
{ title: 'Quadro', href: '/campanha/quadro', icon: LayoutDashboardIcon },
{ title: 'Municípios', href: MUNICIPALITY_NAV_HREF, icon: MapPinIcon },
{ title: 'Territórios', href: '/campanha/territorios', icon: MapIcon },
{ title: 'Lideranças', href: '/campanha/liderancas', icon: HandshakeIcon },
{ title: 'Organizações', href: '/campanha/organizacoes', icon: LandmarkIcon },
{ title: 'Dobradinhas', href: '/campanha/dobradinhas', icon: Users2Icon },
{ title: 'Agenda', href: CAMPAIGN_AGENDA_HOME, icon: CalendarDaysIcon },
{ title: 'Demandas', href: '/campanha/demandas', icon: InboxIcon },
{ title: 'Apoiadores', href: '/campanha/apoiadores', icon: UsersIcon },
{ title: 'Assessores', href: '/campanha/assessores', icon: UserCogIcon },
]
/**
* Reference material, not a place to work: sits in its own group at the foot
* of the sidebar, below the destinations.
* Staff-only — every documented number is one a `leader` never sees.
*
* The href is a literal, not an import from `campaignIntelligenceConcepts.ts`:
* this module reaches client components (`CampaignSidebar`), and that one
* carries the full glossary content — pulling it in for a single path string
* would put the whole glossary in the client bundle.
*/
const staffSecondaryNav: CampaignNavItem[] = [
{ title: 'Conceitos', href: '/campanha/conceitos', icon: BookOpenIcon },
]
const leaderNav: CampaignNavItem[] = [
{ title: 'Início', href: '/campanha', icon: HomeIcon },
{ title: 'Meus contatos', href: LEADER_CONTACTS_HOME, icon: UsersIcon },
]
export const getCampaignNav = (role: CampaignUser['role']): CampaignNavItem[] => {
if (role === 'leader') return leaderNav
return staffNav.filter((item) => {
if (item.href === '/campanha/apoiadores') return canAccessSupporterArea(role)
if (item.href === '/campanha/assessores') return isUnrestrictedCampaignRole(role)
return true
})
}
export const getCampaignSecondaryNav = (role: CampaignUser['role']): CampaignNavItem[] =>
isStaffCampaignRole(role) ? staffSecondaryNav : []
/** Home matches only exactly; other items also match nested paths. */
export const isCampaignNavActive = (pathname: string, href: string): boolean => {
if (href === '/campanha') {
return pathname === '/campanha' || pathname === '/campanha/'
}
if (href === CAMPAIGN_AGENDA_HOME && pathname.startsWith('/campanha/atividades')) return true
return pathname === href || pathname.startsWith(`${href}/`)
}