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
114 lines
3.7 KiB
TypeScript
114 lines
3.7 KiB
TypeScript
import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-react'
|
|
|
|
import { CampaignTransitionAnchor } from '@/components/campaign/CampaignListPending'
|
|
import { Button } from '@/components/ui/button'
|
|
import {
|
|
Pagination,
|
|
PaginationContent,
|
|
PaginationEllipsis,
|
|
PaginationItem,
|
|
} from '@/components/ui/Pagination'
|
|
import { cn } from '@/lib/utils'
|
|
|
|
export const getPaginationPages = (page: number, totalPages: number): number[] => {
|
|
const pages = new Set([1, totalPages, page - 1, page, page + 1])
|
|
return [...pages]
|
|
.filter((candidate) => candidate >= 1 && candidate <= totalPages)
|
|
.sort((a, b) => a - b)
|
|
}
|
|
|
|
/**
|
|
* Server component: `hrefForPage` never crosses the client boundary. The
|
|
* anchors themselves are `CampaignTransitionAnchor` client leaves so page
|
|
* changes ride the shared list transition (results dim) instead of a dead
|
|
* full-page load.
|
|
*/
|
|
export const CampaignListPagination = ({
|
|
page,
|
|
totalPages,
|
|
hrefForPage,
|
|
}: {
|
|
page: number
|
|
totalPages: number
|
|
hrefForPage: (page: number) => string
|
|
}) => {
|
|
if (totalPages <= 1) return null
|
|
|
|
const visiblePages = getPaginationPages(page, totalPages)
|
|
|
|
return (
|
|
<Pagination>
|
|
<PaginationContent>
|
|
<PaginationItem>
|
|
<Button
|
|
asChild
|
|
variant="ghost"
|
|
size="default"
|
|
className={cn(
|
|
'min-h-11 min-w-11 pl-1.5!',
|
|
page <= 1 ? 'pointer-events-none opacity-50' : undefined,
|
|
)}
|
|
>
|
|
<CampaignTransitionAnchor
|
|
href={hrefForPage(Math.max(1, page - 1))}
|
|
aria-label="Ir para a página anterior"
|
|
aria-disabled={page <= 1}
|
|
data-slot="pagination-link"
|
|
>
|
|
<ChevronLeftIcon data-icon="inline-start" />
|
|
<span className="hidden sm:block">Anterior</span>
|
|
</CampaignTransitionAnchor>
|
|
</Button>
|
|
</PaginationItem>
|
|
{visiblePages.map((pageNumber, index) => {
|
|
const previousPage = visiblePages[index - 1]
|
|
const hasGap = previousPage !== undefined && pageNumber - previousPage > 1
|
|
const isActive = pageNumber === page
|
|
|
|
return (
|
|
<PaginationItem key={pageNumber} className="contents">
|
|
{hasGap ? <PaginationEllipsis /> : null}
|
|
<Button
|
|
asChild
|
|
variant={isActive ? 'outline' : 'ghost'}
|
|
size="icon"
|
|
className="min-h-11 min-w-11"
|
|
>
|
|
<CampaignTransitionAnchor
|
|
href={hrefForPage(pageNumber)}
|
|
aria-label={`Ir para a página ${pageNumber}`}
|
|
aria-current={isActive ? 'page' : undefined}
|
|
data-slot="pagination-link"
|
|
data-active={isActive}
|
|
>
|
|
{pageNumber}
|
|
</CampaignTransitionAnchor>
|
|
</Button>
|
|
</PaginationItem>
|
|
)
|
|
})}
|
|
<PaginationItem>
|
|
<Button
|
|
asChild
|
|
variant="ghost"
|
|
size="default"
|
|
className={cn(
|
|
'min-h-11 min-w-11 pr-1.5!',
|
|
page >= totalPages ? 'pointer-events-none opacity-50' : undefined,
|
|
)}
|
|
>
|
|
<CampaignTransitionAnchor
|
|
href={hrefForPage(Math.min(totalPages, page + 1))}
|
|
aria-label="Ir para a próxima página"
|
|
aria-disabled={page >= totalPages}
|
|
data-slot="pagination-link"
|
|
>
|
|
<span className="hidden sm:block">Próxima</span>
|
|
<ChevronRightIcon data-icon="inline-end" />
|
|
</CampaignTransitionAnchor>
|
|
</Button>
|
|
</PaginationItem>
|
|
</PaginationContent>
|
|
</Pagination>
|
|
)
|
|
}
|