mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 15:13:07 +00:00
Registra catálogo staff no drawer B79 para /campanha/municipios e /campanha/municipios/[slug]: lista espelha Início (sem prefill); detalhe prefill ?municipio= nos wizards A1–A5 e omite Ver esquecidos. Closes #16 Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import {
|
|
homeActionsForRole,
|
|
resolveStaffHomeQuickActions,
|
|
toHomeActionButtonProps,
|
|
type ResolvedCampaignHomeAction,
|
|
} from '@/lib/campaignHomeActions'
|
|
import type { CampaignQuickActionContext } from '@/lib/campaignQuickActionContext'
|
|
import type { CampaignRole } from '@/lib/campaignRoles'
|
|
import { isStaffCampaignRole } from '@/lib/campaignRoles'
|
|
|
|
const MUNICIPALITIES_LIST_PATH = '/campanha/municipios' as const
|
|
|
|
const municipalityDetailPathPattern = /^\/campanha\/municipios\/([^/]+)(?:\/|$)/
|
|
|
|
export const isMunicipalitiesListPath = (pathname: string): boolean =>
|
|
pathname === MUNICIPALITIES_LIST_PATH || pathname === `${MUNICIPALITIES_LIST_PATH}/`
|
|
|
|
export const parseMunicipalityDetailSlug = (pathname: string): string | undefined => {
|
|
const match = pathname.match(municipalityDetailPathPattern)
|
|
return match?.[1]
|
|
}
|
|
|
|
export const resolveMunicipalityListQuickActions = (
|
|
role: CampaignRole,
|
|
): readonly ResolvedCampaignHomeAction[] => resolveStaffHomeQuickActions(role)
|
|
|
|
export const resolveMunicipalityDetailQuickActions = (
|
|
role: CampaignRole,
|
|
municipalitySlug: string,
|
|
): readonly ResolvedCampaignHomeAction[] => {
|
|
if (!isStaffCampaignRole(role)) return []
|
|
|
|
const actions = homeActionsForRole(role).filter(
|
|
(action) => action.id !== 'uncovered-municipalities',
|
|
)
|
|
return toHomeActionButtonProps(actions, { municipalitySlug })
|
|
}
|
|
|
|
export const resolveMunicipalityQuickActionsForPath = (
|
|
pathname: string,
|
|
role: CampaignRole,
|
|
context: CampaignQuickActionContext,
|
|
): readonly ResolvedCampaignHomeAction[] => {
|
|
if (isMunicipalitiesListPath(pathname)) {
|
|
return resolveMunicipalityListQuickActions(role)
|
|
}
|
|
|
|
const slug = context.municipalitySlug ?? parseMunicipalityDetailSlug(pathname)
|
|
if (slug) {
|
|
return resolveMunicipalityDetailQuickActions(role, slug)
|
|
}
|
|
|
|
return []
|
|
}
|