From c845550cdbfc67f0d84b8c4f7c9ae93f04f19da5 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 2 Aug 2026 00:55:24 +0000 Subject: [PATCH 1/3] =?UTF-8?q?B121=20=E2=80=94=20wizard=20lideran=C3=A7a:?= =?UTF-8?q?=20edi=C3=A7=C3=A3o=20r=C3=A1pida=20status=20+=20votos=20declar?= =?UTF-8?q?ados?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Estende WizardLeadershipTileViewModel com declaredVotes - Batch load de votePledge no loadWizardLeadershipTiles - Drawers de status (auto-save) e votos (Salvar) no grid B70 - declareVotesWizardFormAction com revalidate do wizard - Unit tests do mapeamento pledge→tile Co-authored-by: Francisco Solla --- .../acoes/wizardLeadershipFormActions.ts | 35 +- .../leadership/WizardLeadershipStep.tsx | 391 ++++++++++++++++-- src/lib/campaignWizardCopy.ts | 18 + src/lib/wizardLeadershipContract.ts | 15 + src/utilities/leadership/leadershipData.ts | 38 +- ...wizardLeadershipDeclaredVotes.unit.spec.ts | 31 ++ 6 files changed, 498 insertions(+), 30 deletions(-) create mode 100644 tests/unit/wizardLeadershipDeclaredVotes.unit.spec.ts diff --git a/src/app/(campaign)/campanha/(app)/acoes/wizardLeadershipFormActions.ts b/src/app/(campaign)/campanha/(app)/acoes/wizardLeadershipFormActions.ts index 55d4682d..668eeb9f 100644 --- a/src/app/(campaign)/campanha/(app)/acoes/wizardLeadershipFormActions.ts +++ b/src/app/(campaign)/campanha/(app)/acoes/wizardLeadershipFormActions.ts @@ -1,11 +1,22 @@ 'use server' +import { revalidatePath } from 'next/cache' + import { leadershipStaffEditSafeMessages } from '@/app/(campaign)/campanha/(app)/liderancas/leadershipStaffEditMessages' import { createLeadershipWizard, updateLeadershipWizard, } from '@/app/(campaign)/campanha/actions/leadership' -import { optionalFormText, requiredFormText, requiredRelationshipFormValue } from '@/lib/formData' +import { declareVotes } from '@/app/(campaign)/campanha/actions/votePledge' +import { + optionalFormText, + requiredFormText, + requiredIntegerFormValue, + requiredRelationshipFormValue, +} from '@/lib/formData' +import { MAX_VOTE_COUNT } from '@/lib/schemas/primitives' +import { WIZARD_LEADERSHIP_VOTES_SAVED } from '@/lib/campaignWizardCopy' +import { VOTE_PLEDGE_DECLARE_SAFE_MESSAGES } from '@/lib/schemas/votePledge' import { LEADERSHIP_DUPLICATE_MESSAGE, LEADERSHIP_INVALID_CONTACT_MESSAGE, @@ -87,3 +98,25 @@ export const updateLeadershipWizardFormAction = async ( safeMessages, genericMessage: 'Não foi possível salvar a liderança. Verifique os dados e tente novamente.', }) + +export const declareVotesWizardFormAction = async ( + _state: CampaignFormActionState, + formData: FormData, +): Promise => + runCampaignFormAction({ + execute: async () => { + const municipality = requiredRelationshipFormValue(formData, 'municipalityId') + const leadership = requiredRelationshipFormValue(formData, 'leadershipId') + const declaredVotes = requiredIntegerFormValue(formData, 'declaredVotes', { + minimum: 0, + maximum: MAX_VOTE_COUNT, + }) + + await declareVotes({ municipality, leadership, declaredVotes }) + revalidatePath('/campanha/acoes/atualizar-lideranca', 'page') + return { message: WIZARD_LEADERSHIP_VOTES_SAVED } + }, + safeMessages: VOTE_PLEDGE_DECLARE_SAFE_MESSAGES, + genericMessage: + 'Não foi possível registrar a declaração. Verifique seu acesso e tente novamente.', + }) diff --git a/src/components/campaign/leadership/WizardLeadershipStep.tsx b/src/components/campaign/leadership/WizardLeadershipStep.tsx index 445ba04e..3779b413 100644 --- a/src/components/campaign/leadership/WizardLeadershipStep.tsx +++ b/src/components/campaign/leadership/WizardLeadershipStep.tsx @@ -1,14 +1,18 @@ 'use client' -import { InfoIcon, PlusIcon } from 'lucide-react' +import { CheckIcon, InfoIcon, PlusIcon, TriangleAlertIcon } from 'lucide-react' import { useRouter } from 'next/navigation' -import { useCallback, useMemo, useState, useTransition } from 'react' +import { useActionState, useCallback, useEffect, useMemo, useRef, useState, useTransition } from 'react' import { toast } from 'sonner' +import type { LeadershipListSupportStatusResponse } from '@/app/(campaign)/campanha/(app)/liderancas/support-status/types' +import { declareVotesWizardFormAction } from '@/app/(campaign)/campanha/(app)/acoes/wizardLeadershipFormActions' import { SupportStatusBadge } from '@/components/campaign/leadership/SupportStatusBadge' import { WizardLeadershipForm } from '@/components/campaign/leadership/WizardLeadershipForm' +import { CampaignFormActionMessage } from '@/components/campaign/shared/CampaignFormActionMessage' import { CampaignWizardNavLink } from '@/components/campaign/shared/CampaignWizardNavLink' import { CampaignWizardShell } from '@/components/campaign/shared/CampaignWizardShell' +import { Alert, AlertDescription } from '@/components/ui/Alert' import { Badge } from '@/components/ui/Badge' import { Button } from '@/components/ui/button' import { @@ -18,22 +22,40 @@ import { DrawerHeader, DrawerTitle, } from '@/components/ui/Drawer' +import { Field, FieldError, FieldLabel } from '@/components/ui/field' +import { Input } from '@/components/ui/input' +import { Spinner } from '@/components/ui/Spinner' import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip' import type { CampaignWizardActionId } from '@/lib/campaignActionRoutes' +import { postCampaignJson } from '@/lib/campaignJsonRequest' import { recordLastActedMunicipality } from '@/lib/campaignLastActedMunicipality' import { WIZARD_LEADERSHIP_ADD_TILE_LABEL, WIZARD_LEADERSHIP_CONTINUE_LABEL, + WIZARD_LEADERSHIP_DECLARE_VOTES_LABEL, WIZARD_LEADERSHIP_EMPTY_GRID, WIZARD_LEADERSHIP_EMPTY_NOTES, WIZARD_LEADERSHIP_FORM_CREATE_TITLE, WIZARD_LEADERSHIP_FORM_EDIT_TITLE, WIZARD_LEADERSHIP_GRID_TITLE, WIZARD_LEADERSHIP_SAVED_TOAST, + WIZARD_LEADERSHIP_STATUS_DRAWER_TITLE, + WIZARD_LEADERSHIP_STATUS_PENDING, + WIZARD_LEADERSHIP_STATUS_SAVE_ERROR, + WIZARD_LEADERSHIP_VOTES_DRAWER_TITLE, + WIZARD_LEADERSHIP_VOTES_PENDING, + WIZARD_LEADERSHIP_VOTES_SAVED, wizardFlowTitleForSlug, } from '@/lib/campaignWizardCopy' import { truncateNameAtWordBoundary } from '@/lib/leadershipNameTruncate' +import { + isSupportStatus, + leadershipSupportStatuses, + type SupportStatus, +} from '@/lib/schemas/leadership' import { cn } from '@/lib/utils' +import { fieldError } from '@/utilities/campaignFormFields' +import { supportStatusLabels } from '@/utilities/leadership/leadershipLabels' import { resolveWizardChainEntry, wizardChainContinueHref, @@ -45,6 +67,9 @@ import { type WizardLeadershipTileViewModel, } from '@/lib/wizardLeadershipContract' +const SUPPORT_STATUS_ENDPOINT = '/campanha/liderancas/support-status' +const DEFAULT_STATUS: SupportStatus = 'a_abordar' + type WizardLeadershipStepProps = { actionSlug: string municipalityId: number @@ -66,6 +91,9 @@ const notesLabel = (notes: string | null): string => const secondaryContact = (tile: WizardLeadershipTileViewModel): string | null => tile.phone?.trim() || tile.email?.trim() || null +const drawerContextLabel = (tile: WizardLeadershipTileViewModel, municipalityName: string): string => + `${tile.name} · ${municipalityName}` + export const WizardLeadershipStep = ({ actionSlug, municipalityId, @@ -87,7 +115,14 @@ export const WizardLeadershipStep = ({ }, [initialLeadershipId, initialTiles]) const [mode, setMode] = useState(initialMode) const [dirty, setDirty] = useState(false) + const [tiles, setTiles] = useState(initialTiles) const [infoTile, setInfoTile] = useState(null) + const [statusTile, setStatusTile] = useState(null) + const [votesTile, setVotesTile] = useState(null) + + useEffect(() => { + setTiles(initialTiles) + }, [initialTiles]) const skipConfig = resolveWizardLeadershipSkip(entryAction, municipalitySlug, returnPath) const chainContinueHref = wizardChainContinueHref( @@ -110,18 +145,44 @@ export const WizardLeadershipStep = ({ ) : undefined - const handleSaved = useCallback(() => { + const markDirtyAndRefresh = useCallback(() => { recordLastActedMunicipality(municipalitySlug) setDirty(true) - setMode({ kind: 'grid' }) router.refresh() - toast.success(WIZARD_LEADERSHIP_SAVED_TOAST) }, [municipalitySlug, router]) const handlePopFormLayer = useCallback(() => { setMode({ kind: 'grid' }) }, []) + const handleSaved = useCallback(() => { + markDirtyAndRefresh() + setMode({ kind: 'grid' }) + toast.success(WIZARD_LEADERSHIP_SAVED_TOAST) + }, [markDirtyAndRefresh]) + + const handleStatusSaved = useCallback( + (leadershipId: number, supportStatus: SupportStatus) => { + setTiles((current) => + current.map((tile) => (tile.id === leadershipId ? { ...tile, supportStatus } : tile)), + ) + setStatusTile(null) + markDirtyAndRefresh() + }, + [markDirtyAndRefresh], + ) + + const handleVotesSaved = useCallback( + (leadershipId: number, declaredVotes: number) => { + setTiles((current) => + current.map((tile) => (tile.id === leadershipId ? { ...tile, declaredVotes } : tile)), + ) + setVotesTile(null) + markDirtyAndRefresh() + }, + [markDirtyAndRefresh], + ) + const handleContinue = () => { startContinueTransition(() => { router.replace(chainContinueHref) @@ -157,16 +218,18 @@ export const WizardLeadershipStep = ({ ) : (
- {initialTiles.length === 0 ? ( + {tiles.length === 0 ? (

{WIZARD_LEADERSHIP_EMPTY_GRID}

) : null}
    - {initialTiles.map((tile) => ( + {tiles.map((tile) => (
  • setMode({ kind: 'form', leadership: tile })} onInfo={() => setInfoTile(tile)} + onStatus={() => setStatusTile(tile)} + onVotes={() => setVotesTile(tile)} />
  • ))} @@ -206,6 +269,21 @@ export const WizardLeadershipStep = ({
+ + setStatusTile(null)} + onSaved={handleStatusSaved} + /> + + setVotesTile(null)} + onSaved={handleVotesSaved} + /> ) } @@ -214,32 +292,96 @@ type LeadershipTileButtonProps = { tile: WizardLeadershipTileViewModel onOpen: () => void onInfo: () => void + onStatus: () => void + onVotes: () => void } -const LeadershipTileButton = ({ tile, onOpen, onInfo }: LeadershipTileButtonProps) => { +const LeadershipTileButton = ({ + tile, + onOpen, + onInfo, + onStatus, + onVotes, +}: LeadershipTileButtonProps) => { const secondary = secondaryContact(tile) const noteText = notesLabel(tile.notes) + const status = tile.supportStatus ?? DEFAULT_STATUS + const showDeclareVotesWarning = tile.declaredVotes === 0 return (
- +
-
+ +
+ +
+
- + + {noteText} - ) } + +type WizardLeadershipStatusDrawerProps = { + tile: WizardLeadershipTileViewModel | null + municipalityName: string + onClose: () => void + onSaved: (leadershipId: number, supportStatus: SupportStatus) => void +} + +const WizardLeadershipStatusDrawer = ({ + tile, + municipalityName, + onClose, + onSaved, +}: WizardLeadershipStatusDrawerProps) => { + const [pendingStatus, setPendingStatus] = useState(null) + const [errorMessage, setErrorMessage] = useState(null) + + useEffect(() => { + if (tile === null) { + setPendingStatus(null) + setErrorMessage(null) + } + }, [tile]) + + const currentStatus = tile?.supportStatus ?? DEFAULT_STATUS + + const handleSelect = async (nextStatus: SupportStatus) => { + if (tile === null || nextStatus === currentStatus || pendingStatus !== null) return + + setPendingStatus(nextStatus) + setErrorMessage(null) + + const { ok, payload } = await postCampaignJson( + SUPPORT_STATUS_ENDPOINT, + { leadershipId: tile.id, supportStatus: nextStatus }, + ) + + if (!ok || payload.status !== 'success') { + setPendingStatus(null) + setErrorMessage( + payload.status === 'error' ? payload.message : WIZARD_LEADERSHIP_STATUS_SAVE_ERROR, + ) + return + } + + if (!isSupportStatus(payload.savedSupportStatus)) { + setPendingStatus(null) + setErrorMessage(WIZARD_LEADERSHIP_STATUS_SAVE_ERROR) + return + } + + onSaved(tile.id, payload.savedSupportStatus) + setPendingStatus(null) + } + + const statusMessage = errorMessage + ? errorMessage + : pendingStatus !== null + ? WIZARD_LEADERSHIP_STATUS_PENDING + : '' + + return ( + !open && onClose()}> + + + {WIZARD_LEADERSHIP_STATUS_DRAWER_TITLE} + + {tile ? drawerContextLabel(tile, municipalityName) : null} + + +
+

+ {statusMessage} +

+
    + {leadershipSupportStatuses.map((option) => { + const isCurrent = option === currentStatus + const isPending = pendingStatus === option + return ( +
  • + +
  • + ) + })} +
+ {errorMessage ? ( + + {errorMessage} + + ) : null} +
+
+
+ ) +} + +type WizardLeadershipVotesDrawerProps = { + tile: WizardLeadershipTileViewModel | null + municipalityId: number + municipalityName: string + onClose: () => void + onSaved: (leadershipId: number, declaredVotes: number) => void +} + +const WizardLeadershipVotesDrawer = ({ + tile, + municipalityId, + municipalityName, + onClose, + onSaved, +}: WizardLeadershipVotesDrawerProps) => { + const [state, submitAction, isPending] = useActionState(declareVotesWizardFormAction, {}) + const [inputValue, setInputValue] = useState('') + const handledMessageRef = useRef(undefined) + + useEffect(() => { + if (tile !== null) { + setInputValue(tile.declaredVotes > 0 ? String(tile.declaredVotes) : '') + handledMessageRef.current = undefined + } + }, [tile]) + + useEffect(() => { + if ( + tile === null || + !state.message || + state.message === handledMessageRef.current || + state.fieldErrors + ) { + return + } + + if (state.message === WIZARD_LEADERSHIP_VOTES_SAVED) { + handledMessageRef.current = state.message + const parsed = Number.parseInt(inputValue, 10) + if (!Number.isNaN(parsed)) { + onSaved(tile.id, parsed) + } + } + }, [inputValue, onSaved, state.fieldErrors, state.message, tile]) + + return ( + !open && onClose()}> + + + {WIZARD_LEADERSHIP_VOTES_DRAWER_TITLE} + + {tile ? drawerContextLabel(tile, municipalityName) : null} + + +
+ + {tile !== null ? : null} +

+ {isPending ? WIZARD_LEADERSHIP_VOTES_PENDING : (state.message ?? '')} +

+ + Votos declarados + setInputValue(event.target.value)} + className="min-h-11" + disabled={isPending} + /> + {fieldError(state.fieldErrors, 'declaredVotes') ? ( + {fieldError(state.fieldErrors, 'declaredVotes')} + ) : null} + + + + +
+
+ ) +} diff --git a/src/lib/campaignWizardCopy.ts b/src/lib/campaignWizardCopy.ts index 2227e671..672a563d 100644 --- a/src/lib/campaignWizardCopy.ts +++ b/src/lib/campaignWizardCopy.ts @@ -91,3 +91,21 @@ export const WIZARD_LEADERSHIP_EMPTY_GRID = 'Nenhuma liderança cadastrada neste município ainda.' as const export const WIZARD_LEADERSHIP_SAVED_TOAST = 'Liderança salva.' as const + +export const WIZARD_LEADERSHIP_STATUS_DRAWER_TITLE = 'Status de apoio' as const + +export const WIZARD_LEADERSHIP_VOTES_DRAWER_TITLE = 'Votos declarados' as const + +export const WIZARD_LEADERSHIP_DECLARE_VOTES_LABEL = 'Declarar votos' as const + +export const WIZARD_LEADERSHIP_STATUS_SAVE_ERROR = + 'Não foi possível salvar o status. Tente novamente.' as const + +export const WIZARD_LEADERSHIP_VOTES_SAVE_ERROR = + 'Não foi possível registrar a declaração. Verifique seu acesso e tente novamente.' as const + +export const WIZARD_LEADERSHIP_STATUS_PENDING = 'Salvando status de apoio.' as const + +export const WIZARD_LEADERSHIP_VOTES_PENDING = 'Salvando declaração de votos.' as const + +export const WIZARD_LEADERSHIP_VOTES_SAVED = 'Declaração registrada.' as const diff --git a/src/lib/wizardLeadershipContract.ts b/src/lib/wizardLeadershipContract.ts index 283734c8..8981b255 100644 --- a/src/lib/wizardLeadershipContract.ts +++ b/src/lib/wizardLeadershipContract.ts @@ -12,6 +12,21 @@ export type WizardLeadershipTileViewModel = { supportStatus: SupportStatus | null exclusive: boolean notes: string | null + /** Declared votes for leadership × wizard municipality; 0 when no pledge. */ + declaredVotes: number +} + +/** Maps pledge rows to leadership id → declaredVotes (absent leadership → omitted). */ +export const declaredVotesByLeadershipFromPledges = ( + pledges: ReadonlyArray<{ leadership: number | { id: number }; declaredVotes?: number | null }>, +): Map => { + const map = new Map() + for (const pledge of pledges) { + const leadershipId = + typeof pledge.leadership === 'number' ? pledge.leadership : pledge.leadership.id + map.set(leadershipId, pledge.declaredVotes ?? 0) + } + return map } export type WizardLeadershipSkipAction = { diff --git a/src/utilities/leadership/leadershipData.ts b/src/utilities/leadership/leadershipData.ts index f3aa5c95..59e67d55 100644 --- a/src/utilities/leadership/leadershipData.ts +++ b/src/utilities/leadership/leadershipData.ts @@ -5,7 +5,10 @@ import type { Payload } from 'payload' import { relationshipId } from '@/lib/relationship' import type { SupportStatus } from '@/lib/schemas/leadership' import { isSupportStatus } from '@/lib/schemas/leadership' -import type { WizardLeadershipTileViewModel } from '@/lib/wizardLeadershipContract' +import { + declaredVotesByLeadershipFromPledges, + type WizardLeadershipTileViewModel, +} from '@/lib/wizardLeadershipContract' import type { CampaignUser, Leadership } from '@/payload-types' import { isCampaignStaff } from '@/utilities/campaignAccess' import { @@ -73,7 +76,10 @@ const findMunicipalityLeadershipDocs = async ( return result.docs as Leadership[] } -const toWizardLeadershipTile = (doc: Leadership): WizardLeadershipTileViewModel => { +const toWizardLeadershipTile = ( + doc: Leadership, + declaredVotes: number, +): WizardLeadershipTileViewModel => { const contact = contactSummary(doc.contact) return { id: doc.id, @@ -83,6 +89,7 @@ const toWizardLeadershipTile = (doc: Leadership): WizardLeadershipTileViewModel supportStatus: isSupportStatus(doc.supportStatus) ? doc.supportStatus : null, exclusive: doc.exclusive ?? true, notes: doc.notes ?? null, + declaredVotes, } } @@ -155,8 +162,33 @@ export const loadWizardLeadershipTiles = async ( municipalityID: number, ): Promise => { const docs = await findMunicipalityLeadershipDocs(payload, user, municipalityID) + const leadershipIDs = docs.map((doc) => doc.id) + + const declaredVotesByLeadership = + leadershipIDs.length === 0 + ? new Map() + : declaredVotesByLeadershipFromPledges( + ( + await payload.find({ + collection: 'votePledge', + where: { + and: [ + { municipality: { equals: municipalityID } }, + { leadership: { in: leadershipIDs } }, + ], + }, + depth: 0, + limit: 0, + pagination: false, + select: { leadership: true, declaredVotes: true }, + user, + overrideAccess: false, + }) + ).docs, + ) + return docs - .map(toWizardLeadershipTile) + .map((doc) => toWizardLeadershipTile(doc, declaredVotesByLeadership.get(doc.id) ?? 0)) .sort((left, right) => left.name.localeCompare(right.name, 'pt-BR')) } diff --git a/tests/unit/wizardLeadershipDeclaredVotes.unit.spec.ts b/tests/unit/wizardLeadershipDeclaredVotes.unit.spec.ts new file mode 100644 index 00000000..662fd084 --- /dev/null +++ b/tests/unit/wizardLeadershipDeclaredVotes.unit.spec.ts @@ -0,0 +1,31 @@ +import { describe, expect, it } from 'vitest' + +import { declaredVotesByLeadershipFromPledges } from '@/lib/wizardLeadershipContract' + +describe('declaredVotesByLeadershipFromPledges', () => { + it('maps leadership id to declared votes', () => { + const map = declaredVotesByLeadershipFromPledges([ + { leadership: 7, declaredVotes: 120 }, + { leadership: { id: 9 }, declaredVotes: 45 }, + ]) + + expect(map.get(7)).toBe(120) + expect(map.get(9)).toBe(45) + expect(map.get(99)).toBeUndefined() + }) + + it('treats null declaredVotes as zero', () => { + const map = declaredVotesByLeadershipFromPledges([{ leadership: 3, declaredVotes: null }]) + + expect(map.get(3)).toBe(0) + }) + + it('last pledge wins when duplicate leadership ids appear', () => { + const map = declaredVotesByLeadershipFromPledges([ + { leadership: 5, declaredVotes: 10 }, + { leadership: 5, declaredVotes: 20 }, + ]) + + expect(map.get(5)).toBe(20) + }) +}) From 9d8dcbbea40ff77ede60b78a35251d113165edbc Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 2 Aug 2026 00:56:29 +0000 Subject: [PATCH 2/3] =?UTF-8?q?B121=20=E2=80=94=20remove=20unused=20copy?= =?UTF-8?q?=20constant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Francisco Solla --- src/lib/campaignWizardCopy.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib/campaignWizardCopy.ts b/src/lib/campaignWizardCopy.ts index 672a563d..53060098 100644 --- a/src/lib/campaignWizardCopy.ts +++ b/src/lib/campaignWizardCopy.ts @@ -101,9 +101,6 @@ export const WIZARD_LEADERSHIP_DECLARE_VOTES_LABEL = 'Declarar votos' as const export const WIZARD_LEADERSHIP_STATUS_SAVE_ERROR = 'Não foi possível salvar o status. Tente novamente.' as const -export const WIZARD_LEADERSHIP_VOTES_SAVE_ERROR = - 'Não foi possível registrar a declaração. Verifique seu acesso e tente novamente.' as const - export const WIZARD_LEADERSHIP_STATUS_PENDING = 'Salvando status de apoio.' as const export const WIZARD_LEADERSHIP_VOTES_PENDING = 'Salvando declaração de votos.' as const From bf042c3217d2adba0f8abe4b85abf1a011319652 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 2 Aug 2026 00:57:11 +0000 Subject: [PATCH 3/3] =?UTF-8?q?B121=20=E2=80=94=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acoes/wizardLeadershipFormActions.ts | 6 ++--- .../leadership/WizardLeadershipStep.tsx | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/app/(campaign)/campanha/(app)/acoes/wizardLeadershipFormActions.ts b/src/app/(campaign)/campanha/(app)/acoes/wizardLeadershipFormActions.ts index 668eeb9f..8d8ee7ac 100644 --- a/src/app/(campaign)/campanha/(app)/acoes/wizardLeadershipFormActions.ts +++ b/src/app/(campaign)/campanha/(app)/acoes/wizardLeadershipFormActions.ts @@ -8,21 +8,21 @@ import { updateLeadershipWizard, } from '@/app/(campaign)/campanha/actions/leadership' import { declareVotes } from '@/app/(campaign)/campanha/actions/votePledge' +import { WIZARD_LEADERSHIP_VOTES_SAVED } from '@/lib/campaignWizardCopy' import { optionalFormText, requiredFormText, requiredIntegerFormValue, requiredRelationshipFormValue, } from '@/lib/formData' -import { MAX_VOTE_COUNT } from '@/lib/schemas/primitives' -import { WIZARD_LEADERSHIP_VOTES_SAVED } from '@/lib/campaignWizardCopy' -import { VOTE_PLEDGE_DECLARE_SAFE_MESSAGES } from '@/lib/schemas/votePledge' import { LEADERSHIP_DUPLICATE_MESSAGE, LEADERSHIP_INVALID_CONTACT_MESSAGE, LEADERSHIP_MUNICIPALITY_SCOPE_MESSAGE, isSupportStatus, } from '@/lib/schemas/leadership' +import { MAX_VOTE_COUNT } from '@/lib/schemas/primitives' +import { VOTE_PLEDGE_DECLARE_SAFE_MESSAGES } from '@/lib/schemas/votePledge' import { runCampaignFormAction, type CampaignFormActionState, diff --git a/src/components/campaign/leadership/WizardLeadershipStep.tsx b/src/components/campaign/leadership/WizardLeadershipStep.tsx index 3779b413..f40d272d 100644 --- a/src/components/campaign/leadership/WizardLeadershipStep.tsx +++ b/src/components/campaign/leadership/WizardLeadershipStep.tsx @@ -2,11 +2,19 @@ import { CheckIcon, InfoIcon, PlusIcon, TriangleAlertIcon } from 'lucide-react' import { useRouter } from 'next/navigation' -import { useActionState, useCallback, useEffect, useMemo, useRef, useState, useTransition } from 'react' +import { + useActionState, + useCallback, + useEffect, + useMemo, + useRef, + useState, + useTransition, +} from 'react' import { toast } from 'sonner' -import type { LeadershipListSupportStatusResponse } from '@/app/(campaign)/campanha/(app)/liderancas/support-status/types' import { declareVotesWizardFormAction } from '@/app/(campaign)/campanha/(app)/acoes/wizardLeadershipFormActions' +import type { LeadershipListSupportStatusResponse } from '@/app/(campaign)/campanha/(app)/liderancas/support-status/types' import { SupportStatusBadge } from '@/components/campaign/leadership/SupportStatusBadge' import { WizardLeadershipForm } from '@/components/campaign/leadership/WizardLeadershipForm' import { CampaignFormActionMessage } from '@/components/campaign/shared/CampaignFormActionMessage' @@ -54,8 +62,6 @@ import { type SupportStatus, } from '@/lib/schemas/leadership' import { cn } from '@/lib/utils' -import { fieldError } from '@/utilities/campaignFormFields' -import { supportStatusLabels } from '@/utilities/leadership/leadershipLabels' import { resolveWizardChainEntry, wizardChainContinueHref, @@ -66,6 +72,8 @@ import { resolveWizardLeadershipSkip, type WizardLeadershipTileViewModel, } from '@/lib/wizardLeadershipContract' +import { fieldError } from '@/utilities/campaignFormFields' +import { supportStatusLabels } from '@/utilities/leadership/leadershipLabels' const SUPPORT_STATUS_ENDPOINT = '/campanha/liderancas/support-status' const DEFAULT_STATUS: SupportStatus = 'a_abordar' @@ -91,8 +99,10 @@ const notesLabel = (notes: string | null): string => const secondaryContact = (tile: WizardLeadershipTileViewModel): string | null => tile.phone?.trim() || tile.email?.trim() || null -const drawerContextLabel = (tile: WizardLeadershipTileViewModel, municipalityName: string): string => - `${tile.name} · ${municipalityName}` +const drawerContextLabel = ( + tile: WizardLeadershipTileViewModel, + municipalityName: string, +): string => `${tile.name} · ${municipalityName}` export const WizardLeadershipStep = ({ actionSlug,