mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-15 02:23:07 +00:00
- Pure helpers: advisorEditingScope, rowEditingAllowed in campaignAdvisorProfile.ts - gate: 'writable' in requireCampaignPageActor for route-level enforcement - Shared cells accept readOnly prop: CampaignInlineEditableCell, MunicipalityRelationEditor, PhonesFieldEditor, DemandDescriptionEditor, etc. - Municipality pages compute editingScope via resolveMunicipalityWriteScope and thread it to list/detail/edit surfaces - Home actions, FAB mount rule, quick actions registry accept editingScope parameter - Demands, activities, supporters, organizations create buttons gated - E2E spec: campaignPermissionProfile.e2e.spec.ts covering 3 profiles - Unit tests: campaignAdvisorProfile, accessShared, campaignComponents updated - gate:fast passed (tsc, lint, format, knip, cycles, unit)
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import { Plus } from 'lucide-react'
|
|
|
|
import type { AdvisorEditingScope } from '@/lib/campaignAdvisorProfile'
|
|
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,
|
|
editingScope: AdvisorEditingScope = 'tudo',
|
|
): readonly CampaignQuickAction[] => {
|
|
if (!matchesDobradinhasQuickActionSurface(pathname) || !isStaffCampaignRole(role)) {
|
|
return []
|
|
}
|
|
|
|
const staffActions = resolveStaffHomeQuickActions(role, editingScope, pathname)
|
|
|
|
if (isStateDeputyListPath(pathname)) {
|
|
return [newStateDeputyAction(), ...staffActions]
|
|
}
|
|
|
|
return staffActions
|
|
}
|