teqo-backup/src/utilities/visit/visitPlannerUrl.ts
Francisco Ignácio Fontoura Solla 4806c417c8 Engineering Pass 3: consolidate patterns and lock them with guards.
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.
2026-07-29 06:11:29 -03:00

26 lines
1.2 KiB
TypeScript

/**
* E13 tour-composer URL contract — one region param, parsed and serialized in
* one place so the detail card's CTA, the Atividades button and the page itself
* cannot spell it three ways.
*
* Client-safe by construction: it only touches the identity-territory name
* table. The B14 lesson applies to serializers too — a client component that
* imports a serializer which imports the catalog drags the catalog into the
* bundle, which is why nothing heavier lives here.
*/
import { isBahiaIdentityTerritory, type BahiaIdentityTerritory } from '@/lib/bahiaTerritories'
import { firstValue, type RawSearchParams } from '@/utilities/campaignListUrl'
export const TOUR_COMPOSER_PATH = '/campanha/atividades/giros'
export type TourComposerState = {
region: BahiaIdentityTerritory | null
}
export const parseTourComposerParams = (params: RawSearchParams): TourComposerState => {
const raw = firstValue(params.region)?.trim()
return { region: raw && isBahiaIdentityTerritory(raw) ? raw : null }
}
export const buildTourComposerHref = ({ region }: TourComposerState): string =>
region ? `${TOUR_COMPOSER_PATH}?region=${encodeURIComponent(region)}` : TOUR_COMPOSER_PATH