mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-12 22:13:05 +00:00
The "Municípios" column was dead text; it is now chips that navigate to the município, with a territory chip when a leadership covers a whole TI, and it is editable in place. What picks inline vs. Drawer is the `pointer:` media query, not viewport width: on a fine pointer the editor is always mounted (the "×" sits at the chip's corner, revealed on hover/focus) and on a coarse pointer a tap anywhere in the cell opens a Drawer with 44 px targets. `AdvisorMunicipalityCell` is promoted to `shared/MunicipalityPortfolioCell` and /campanha/assessores migrates onto it in the same change, so the second call site is born with the first. One batch action only; the single-id advisor twin is deleted with its int tests migrated. The anti-goal on always-mounted list inputs is amended for chip-based relations on fine pointers, not reopened. Also fixes a latent bug: `CampaignTableHead`'s `description` seam broke any RSC caller, because its two helpers lived in a 'use client' module.
54 lines
2.3 KiB
TypeScript
54 lines
2.3 KiB
TypeScript
'use server'
|
|
|
|
import { leadershipStaffEditSafeMessages } from '@/app/(campaign)/campanha/(app)/liderancas/leadershipStaffEditMessages'
|
|
import { createLeadership } from '@/app/(campaign)/campanha/actions/leadership'
|
|
import { optionalFormText, repeatedRelationshipFormValues, requiredFormText } from '@/lib/formData'
|
|
import {
|
|
LEADERSHIP_MUNICIPALITY_SCOPE_MESSAGE,
|
|
leadershipSectors,
|
|
leadershipSupportStatuses,
|
|
} from '@/lib/schemas/leadership'
|
|
import {
|
|
runCampaignRedirectFormAction,
|
|
type CampaignFormActionState,
|
|
} from '@/utilities/campaignFormActionError'
|
|
|
|
const safeMessages = [
|
|
'Esta pessoa já está cadastrada como liderança. Edite a ficha existente para vincular novos municípios.',
|
|
LEADERSHIP_MUNICIPALITY_SCOPE_MESSAGE,
|
|
...leadershipStaffEditSafeMessages,
|
|
'Existe mais de um contato com este celular. Resolva a duplicidade no admin antes de continuar.',
|
|
] as const
|
|
|
|
export const createLeadershipFormAction = async (
|
|
_state: CampaignFormActionState,
|
|
formData: FormData,
|
|
): Promise<CampaignFormActionState> =>
|
|
runCampaignRedirectFormAction({
|
|
execute: () => {
|
|
const sector = optionalFormText(formData, 'sector')
|
|
const supportStatus = optionalFormText(formData, 'supportStatus')
|
|
|
|
return createLeadership({
|
|
name: requiredFormText(formData, 'name'),
|
|
phone: requiredFormText(formData, 'phone'),
|
|
email: optionalFormText(formData, 'email'),
|
|
municipalities: repeatedRelationshipFormValues(formData, 'municipalities'),
|
|
organizations: repeatedRelationshipFormValues(formData, 'organizations'),
|
|
stateDeputies: repeatedRelationshipFormValues(formData, 'stateDeputies'),
|
|
sector: leadershipSectors.includes(sector as (typeof leadershipSectors)[number])
|
|
? (sector as (typeof leadershipSectors)[number])
|
|
: undefined,
|
|
supportStatus: leadershipSupportStatuses.includes(
|
|
supportStatus as (typeof leadershipSupportStatuses)[number],
|
|
)
|
|
? (supportStatus as (typeof leadershipSupportStatuses)[number])
|
|
: 'a_abordar',
|
|
notes: optionalFormText(formData, 'notes'),
|
|
consentNote: optionalFormText(formData, 'consentNote'),
|
|
})
|
|
},
|
|
redirectTo: (leadership) => `/campanha/liderancas/${leadership.id}`,
|
|
safeMessages,
|
|
genericMessage: 'Não foi possível cadastrar a liderança. Verifique os dados e tente novamente.',
|
|
})
|