436 seeded Praças (municipality-based; per-TSE-zone in Salvador/Camaçari) become the operational unit; roles renamed to coordinator/advisor/leader with advisors scoped to administered Praças. Leadership is one record per person across many Praças/organizations; vote pledges split leader-declared vs staff-estimated (estimates never serialized to leaders). Adds organizations, demand workflow with staff-only cost/receipts, action-plan results with deputy presence, manual political trend, multi-candidate comparison and the diverging red/white/blue map mode. Migration 20260721_020109_remodel_plazas deliberately resets the campaign vertical in production (public site untouched); test suite ported to the new model (unit 187 / int 306 / e2e 9 green).
67 lines
2 KiB
TypeScript
67 lines
2 KiB
TypeScript
export const plazaDetailTabs = [
|
|
'overview',
|
|
'elections',
|
|
'leaderships',
|
|
'updates',
|
|
'demands',
|
|
] as const
|
|
|
|
export type PlazaDetailTab = (typeof plazaDetailTabs)[number]
|
|
export type PlazaDetailSearchParams = Record<string, string | string[] | undefined>
|
|
|
|
const tabQueryKeys: Record<PlazaDetailTab, readonly string[]> = {
|
|
overview: [],
|
|
elections: ['compare'],
|
|
leaderships: ['leadershipQ', 'leadershipPage'],
|
|
updates: ['updateKind', 'updatePage', 'newUpdate'],
|
|
demands: ['demandStatus'],
|
|
}
|
|
|
|
const firstValue = (value: string | string[] | undefined): string | undefined =>
|
|
Array.isArray(value) ? value[0] : value
|
|
|
|
const appendQueryValue = (
|
|
params: URLSearchParams,
|
|
key: string,
|
|
value: string | string[] | undefined,
|
|
) => {
|
|
for (const item of Array.isArray(value) ? value : [value]) {
|
|
if (item !== undefined) params.append(key, item)
|
|
}
|
|
}
|
|
|
|
export type PlazaDetailRoleKind = 'staff' | 'leader'
|
|
|
|
export const plazaDetailTabsForRole = (roleKind: PlazaDetailRoleKind): PlazaDetailTab[] =>
|
|
roleKind === 'staff'
|
|
? [...plazaDetailTabs]
|
|
: plazaDetailTabs.filter((tab) => tab !== 'leaderships')
|
|
|
|
const isAllowedTab = (
|
|
value: string | undefined,
|
|
roleKind: PlazaDetailRoleKind,
|
|
): value is PlazaDetailTab => plazaDetailTabsForRole(roleKind).includes(value as PlazaDetailTab)
|
|
|
|
export const resolvePlazaDetailTab = (
|
|
searchParams: PlazaDetailSearchParams,
|
|
roleKind: PlazaDetailRoleKind,
|
|
): PlazaDetailTab => {
|
|
if (firstValue(searchParams.newUpdate) === '1') return 'updates'
|
|
|
|
const requestedTab = firstValue(searchParams.tab)
|
|
return isAllowedTab(requestedTab, roleKind) ? requestedTab : 'overview'
|
|
}
|
|
|
|
export const buildPlazaDetailTabHref = (
|
|
plazaSlug: string,
|
|
tab: PlazaDetailTab,
|
|
searchParams: PlazaDetailSearchParams,
|
|
): string => {
|
|
const params = new URLSearchParams()
|
|
for (const key of tabQueryKeys[tab]) {
|
|
appendQueryValue(params, key, searchParams[key])
|
|
}
|
|
params.set('tab', tab)
|
|
|
|
return `/campanha/pracas/${plazaSlug}?${params.toString()}`
|
|
}
|