mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-24 18:13:06 +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)
105 lines
4.2 KiB
TypeScript
105 lines
4.2 KiB
TypeScript
import { PlusIcon } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
|
|
import { SupportStatusBadge } from '@/components/campaign/leadership/SupportStatusBadge'
|
|
import { DeclareVotesForm } from '@/components/campaign/votePledge/DeclareVotesForm'
|
|
import { Badge } from '@/components/ui/Badge'
|
|
import { Button } from '@/components/ui/button'
|
|
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
|
|
import type { LeadershipRowViewModel } from '@/utilities/leadership/leadershipData'
|
|
import type { StaffPledgeRow } from '@/utilities/votePledgeViews'
|
|
|
|
type MunicipalityLeadershipsPanelProps = {
|
|
municipalityID: number
|
|
leaderships: LeadershipRowViewModel[]
|
|
pledges: StaffPledgeRow[]
|
|
declareFormAction: (
|
|
state: CampaignFormActionState,
|
|
formData: FormData,
|
|
) => Promise<CampaignFormActionState>
|
|
/** C142 — read-only presentation (advisor with Edição `somente_leitura`): no create link, no declare form. */
|
|
readOnly?: boolean
|
|
}
|
|
|
|
/** Staff-only: leaderships linked to this municipality + declare-on-behalf form. */
|
|
export const MunicipalityLeadershipsPanel = ({
|
|
municipalityID,
|
|
leaderships,
|
|
pledges,
|
|
declareFormAction,
|
|
readOnly = false,
|
|
}: MunicipalityLeadershipsPanelProps) => {
|
|
const pledgeByLeadership = new Map(pledges.map((pledge) => [pledge.leadershipID, pledge]))
|
|
|
|
return (
|
|
<section aria-labelledby="municipality-leaderships-title" className="flex flex-col gap-4">
|
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
<div className="flex flex-col gap-1">
|
|
<h2 id="municipality-leaderships-title" className="text-base font-medium">
|
|
Lideranças deste município
|
|
</h2>
|
|
<p className="text-sm text-muted-foreground">
|
|
Uma liderança pode atuar em vários municípios e organizações.
|
|
</p>
|
|
</div>
|
|
{readOnly ? null : (
|
|
<Button asChild className="min-h-11">
|
|
<Link href={`/campanha/liderancas/nova?municipality=${municipalityID}`}>
|
|
<PlusIcon data-icon="inline-start" aria-hidden="true" />
|
|
Nova liderança
|
|
</Link>
|
|
</Button>
|
|
)}
|
|
</div>
|
|
|
|
{leaderships.length ? (
|
|
<ul className="flex flex-col gap-4">
|
|
{leaderships.map((leadership) => {
|
|
const pledge = pledgeByLeadership.get(leadership.id)
|
|
return (
|
|
<li key={leadership.id} className="flex flex-col gap-3 rounded-xl border p-4">
|
|
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
<div className="flex flex-col gap-1">
|
|
<Link
|
|
href={`/campanha/liderancas/${leadership.id}`}
|
|
className="min-h-11 content-center font-medium text-primary underline-offset-4 hover:underline"
|
|
>
|
|
{leadership.name}
|
|
</Link>
|
|
<div className="flex flex-wrap gap-1">
|
|
{leadership.supportStatus ? (
|
|
<SupportStatusBadge status={leadership.supportStatus} />
|
|
) : null}
|
|
{leadership.organizationNames.map((name) => (
|
|
<Badge key={name} variant="outline">
|
|
{name}
|
|
</Badge>
|
|
))}
|
|
</div>
|
|
</div>
|
|
{leadership.municipalityIDs.length > 1 ? (
|
|
<span className="text-sm text-muted-foreground">
|
|
Atua em {leadership.municipalityIDs.length} municípios
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
{readOnly ? null : (
|
|
<DeclareVotesForm
|
|
municipalityID={municipalityID}
|
|
leadershipID={leadership.id}
|
|
currentDeclaredVotes={pledge?.declaredVotes ?? null}
|
|
formAction={declareFormAction}
|
|
/>
|
|
)}
|
|
</li>
|
|
)
|
|
})}
|
|
</ul>
|
|
) : (
|
|
<p className="rounded-xl border px-4 py-6 text-sm text-muted-foreground">
|
|
Nenhuma liderança vinculada a este município ainda.
|
|
</p>
|
|
)}
|
|
</section>
|
|
)
|
|
}
|