teqo-backup/src/components/campaign/nav.ts
Francisco Ignácio Fontoura Solla 52c402c049 Fix the three leader-flow bugs the e2e suite pinned + RSC prop contracts
E2E-driven fixes (the suite now passes 9/9; two journeys remain
latency-flaky on cold dev compiles and pass on retry):

- leader home crashed with Forbidden since the remodel:
  loadLeaderContactsPageData loaded municipality options through the
  staff-scoped loader (leaders are denied municipality reads); their scope
  now derives from the engaged leadership's linked municipalities
- leaders saw 'Contato — —' instead of their supporters' names:
  getAccessibleContactIds now mirrors canReadSupporter for leaders
  (contacts of supporters they created)
- leader nav had two items with the same /campanha href (duplicate React
  keys); the leader home IS the contact tool — one entry
- RSC serialization contracts: CampaignListPagination is a server component
  again (hrefForPage stays server-side; CampaignTransitionAnchor client leaf
  intercepts clicks with serializable props); CampaignSearchForm takes
  basePath instead of a function prop
- hasAnyEstimate moved from the 'use client' PledgeEstimateForm to
  voteEstimate.ts — server components may not call client-module exports
- playwright.config honors TEQO_TEST_DATABASE_URL (parity with
  vitest.setup.ts) and uses a fixed .next/e2e dist dir so Next stops
  appending per-PID entries to tsconfig include; report artifacts
  eslint-ignored
2026-07-24 00:38:40 -03:00

65 lines
2.2 KiB
TypeScript

import {
CalendarDaysIcon,
HandshakeIcon,
HomeIcon,
InboxIcon,
MapPinIcon,
Users2Icon,
UsersIcon,
type LucideIcon,
} from 'lucide-react'
import type { CampaignUser } from '@/payload-types'
import { isCampaignStaff } from '@/utilities/campaignAccess'
import { canAccessSupporterArea } from '@/utilities/supporterUi'
export type CampaignNavItem = {
title: string
href: string
icon: LucideIcon
}
const staffNav: CampaignNavItem[] = [
{ title: 'Início', href: '/campanha', icon: HomeIcon },
{ title: 'Municípios', href: '/campanha/municipios', icon: MapPinIcon },
{ title: 'Lideranças', href: '/campanha/liderancas', icon: HandshakeIcon },
{ title: 'Dobradinhas', href: '/campanha/dobradinhas', icon: Users2Icon },
{ title: 'Planos', href: '/campanha/planos', icon: CalendarDaysIcon },
{ title: 'Demandas', href: '/campanha/demandas', icon: InboxIcon },
{ title: 'Apoiadores', href: '/campanha/apoiadores', icon: UsersIcon },
]
const leaderNav: CampaignNavItem[] = [
// The leader home IS the contact tool — one entry, one href (duplicate
// hrefs previously produced duplicate React keys in the sidebar).
{ title: 'Meus contatos', href: '/campanha', icon: UsersIcon },
]
export const getCampaignNav = (role: CampaignUser['role']): CampaignNavItem[] => {
if (role === 'leader') return leaderNav
return staffNav.filter(
(item) => item.href !== '/campanha/apoiadores' || canAccessSupporterArea(role),
)
}
/**
* Compact set for the mobile bottom bar (max 5 items with a home slot).
*/
export const getCampaignBottomNav = (role: CampaignUser['role']): CampaignNavItem[] => {
const nav = getCampaignNav(role)
if (role === 'leader') return nav
return nav.filter((item) => item.href !== '/campanha/apoiadores').slice(0, 5)
}
/** 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/'
}
return pathname === href || pathname.startsWith(`${href}/`)
}
export const isCampaignStaffRole = (role: CampaignUser['role']): boolean =>
isCampaignStaff({ collection: 'campaignUser', role } as CampaignUser)