mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-19 08:03:06 +00:00
Fold duplicated campanha access, loaders, list/filter/form shells, and scripts into shared modules; reorganize utilities by domain; stabilize e2e; and document prevention-first audit workflow so the same smells cannot creep back in.
35 lines
989 B
TypeScript
35 lines
989 B
TypeScript
import 'server-only'
|
|
|
|
import { revalidatePath } from 'next/cache'
|
|
|
|
// The cache tag moved to `municipalityCatalogCache.ts` (P3-E) — import it from
|
|
// there; this module owns only the revalidatePath side.
|
|
|
|
type MunicipalityListRevalidateScope = 'list' | 'detail' | 'both'
|
|
|
|
const municipalitySlugPathPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
|
|
type RevalidateMunicipalityListPathsOptions = {
|
|
slug?: string
|
|
scope?: MunicipalityListRevalidateScope
|
|
}
|
|
|
|
export const revalidateMunicipalityListPaths = ({
|
|
slug,
|
|
scope = 'both',
|
|
}: RevalidateMunicipalityListPathsOptions = {}) => {
|
|
const detailSlug = slug && municipalitySlugPathPattern.test(slug) ? slug : undefined
|
|
|
|
if (scope === 'list' || scope === 'both') {
|
|
revalidatePath('/campanha/municipios', 'page')
|
|
}
|
|
|
|
if (scope === 'detail' || scope === 'both') {
|
|
if (detailSlug) {
|
|
revalidatePath(`/campanha/municipios/${detailSlug}`, 'page')
|
|
return
|
|
}
|
|
|
|
revalidatePath('/campanha/municipios/[slug]', 'page')
|
|
}
|
|
}
|