teqo/src/components/campaign/CampaignListPagination.tsx
Francisco Ignácio Fontoura Solla 9fdbae05d7 Add C6 scale/DRY for supporters: bulk import, KPI aggregate, shared shells.
Phase 1 UX: StrictCombobox municipality in SupporterForm, AlertDialog in
RemoveSupporterDataButton. Phase 2 DRY: campaignListUrl + CampaignListPagination
+ campaignFormFields + mapCampaignFormActionError shared across nuclei,
supporters and action plans. Phase 3: single SQL aggregate for supporter list
KPIs via drizzle in the Payload txn. Phase 4: bulk drizzle insert for CSV import
inside the existing Payload txn with ON CONFLICT DO NOTHING, plus a fail-closed
skipContactPhoneInvariant context flag. Phase 5: HMAC-signed single-use import
token backed by a new supporterImportBatch staging collection so the full ok-row
set never crosses the Server Action boundary twice.
2026-07-18 22:17:31 -03:00

68 lines
2 KiB
TypeScript

import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from '@/components/ui/Pagination'
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)
}
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>
<PaginationPrevious
href={hrefForPage(Math.max(1, page - 1))}
aria-disabled={page <= 1}
className={page <= 1 ? 'pointer-events-none opacity-50' : undefined}
/>
</PaginationItem>
{visiblePages.map((pageNumber, index) => {
const previousPage = visiblePages[index - 1]
const hasGap = previousPage !== undefined && pageNumber - previousPage > 1
return (
<PaginationItem key={pageNumber} className="contents">
{hasGap ? <PaginationEllipsis /> : null}
<PaginationLink
href={hrefForPage(pageNumber)}
isActive={pageNumber === page}
aria-label={`Ir para a página ${pageNumber}`}
>
{pageNumber}
</PaginationLink>
</PaginationItem>
)
})}
<PaginationItem>
<PaginationNext
href={hrefForPage(Math.min(totalPages, page + 1))}
aria-disabled={page >= totalPages}
className={page >= totalPages ? 'pointer-events-none opacity-50' : undefined}
/>
</PaginationItem>
</PaginationContent>
</Pagination>
)
}