teqo-backup/src/utilities/municipality/municipalityRevalidation.ts
Cursor Agent 0aa47f8673
feat(campanha): B147 município v2 shell + faixa de status
Rota paralela /campanha/municipio/<slug>/v2 com selects de nível, tendência e
sinal (modal de motivo opcional), classe territorial e agregado. Soft-dep B134:
motivo opcional no movimento de nível e remoção do campo “voltar atrás” do
write path/lista.

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
2026-08-02 23:29:05 +00:00

38 lines
1.2 KiB
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')
// B147 parallel v2 surface — same municipality, singular path.
revalidatePath(`/campanha/municipio/${detailSlug}/v2`, 'page')
return
}
revalidatePath('/campanha/municipios/[slug]', 'page')
revalidatePath('/campanha/municipio/[slug]/v2', 'page')
}
}