teqo-backup/src/lib/campaignQuickActionDobradinhas.ts
Francisco Ignácio Fontoura Solla 4a90fb19ec C86+ — pathname de lista das ações rápidas em fonte única (isListPath)
Extrai isListPath + normalizePathname exportados em campaignQuickActionPaths.ts
e migra os 9 wrappers (7 públicos + 2 privados) + a 3a cópia de normalize em
campaignPageChrome.ts. Refactor estrutural sem mudança de comportamento;
derivação de regex de detalhe numérico adiada (gatilho: 3o vertical [id]).
Inclui docs/plans/escala-dry-pos-acoes-rapidas-impl.md e o fix de format
pré-existente de docs/plans/liderancas-coluna-municipios.md (bloqueava format:check).
2026-08-04 01:14:35 -03:00

53 lines
1.9 KiB
TypeScript

import { Plus } from 'lucide-react'
import { resolveStaffHomeQuickActions } from '@/lib/campaignHomeActions'
import { isListPath } from '@/lib/campaignQuickActionPaths'
import type { CampaignQuickAction } from '@/lib/campaignQuickActionTypes'
import { isStaffCampaignRole, type CampaignRole } from '@/lib/campaignRoles'
const STATE_DEPUTY_LIST_PATH = '/campanha/dobradinhas' as const
const STATE_DEPUTY_CREATE_PATH = '/campanha/dobradinhas/nova' as const
const STATE_DEPUTY_PATH_PREFIX = `${STATE_DEPUTY_LIST_PATH}/` as const
const isStateDeputyListPath = (pathname: string): boolean =>
isListPath(pathname, STATE_DEPUTY_LIST_PATH)
const isStateDeputyCreatePath = (pathname: string): boolean => pathname === STATE_DEPUTY_CREATE_PATH
export const parseStateDeputyDetailSlug = (pathname: string): string | undefined => {
if (!pathname.startsWith(STATE_DEPUTY_PATH_PREFIX)) return undefined
const slug = pathname.slice(STATE_DEPUTY_PATH_PREFIX.length)
if (!slug || slug.includes('/') || slug === 'nova') return undefined
return slug
}
export const matchesDobradinhasQuickActionSurface = (pathname: string): boolean =>
isStateDeputyListPath(pathname) ||
isStateDeputyCreatePath(pathname) ||
parseStateDeputyDetailSlug(pathname) !== undefined
const newStateDeputyAction = (): CampaignQuickAction => ({
id: 'new-state-deputy',
label: 'Nova dobradinha',
icon: Plus,
description: 'Cadastrar um deputado estadual parceiro da campanha',
href: STATE_DEPUTY_CREATE_PATH,
})
/** B83 — `/dobradinhas` list, detail and create surfaces. */
export const resolveDobradinhasQuickActions = (
pathname: string,
role: CampaignRole,
): readonly CampaignQuickAction[] => {
if (!matchesDobradinhasQuickActionSurface(pathname) || !isStaffCampaignRole(role)) {
return []
}
const staffActions = resolveStaffHomeQuickActions(role, pathname)
if (isStateDeputyListPath(pathname)) {
return [newStateDeputyAction(), ...staffActions]
}
return staffActions
}