teqo/src/utilities/plazaRevalidation.ts
Francisco Ignácio Fontoura Solla 0dcef662e7 Deliver A9+ shared Praças list loader and scoped revalidation.
Deduplicate pledge aggregation via loadPlazaListPageBundle, add plazaRevalidation with slug-scoped detail paths after inline saves, and document the fill-in as shipped.
2026-07-21 13:22:12 -03:00

30 lines
773 B
TypeScript

import { revalidatePath } from 'next/cache'
export type PlazaListRevalidateScope = 'list' | 'detail' | 'both'
const plazaSlugPathPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
type RevalidatePlazaListPathsOptions = {
slug?: string
scope?: PlazaListRevalidateScope
}
export const revalidatePlazaListPaths = ({
slug,
scope = 'both',
}: RevalidatePlazaListPathsOptions = {}) => {
const detailSlug = slug && plazaSlugPathPattern.test(slug) ? slug : undefined
if (scope === 'list' || scope === 'both') {
revalidatePath('/campanha/pracas', 'page')
}
if (scope === 'detail' || scope === 'both') {
if (detailSlug) {
revalidatePath(`/campanha/pracas/${detailSlug}`, 'page')
return
}
revalidatePath('/campanha/pracas/[slug]', 'page')
}
}