Deduplicate pledge aggregation via loadPlazaListPageBundle, add plazaRevalidation with slug-scoped detail paths after inline saves, and document the fill-in as shipped.
30 lines
773 B
TypeScript
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')
|
|
}
|
|
}
|