mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-27 14:23:05 +00:00
- campaignDemand.responsibles (hasMany → campaignUser, staff elegível) com hook beforeValidate que descarta ids não-staff (fail-closed) - canRead/UpdateCampaignDemand por membership: assessor só vê demandas onde é responsável; unrestricted/admin sempre; leader nunca (fim do escopo municipal de demandas) - criador entra automaticamente como responsável no hook de criação (form, wizard, rascunhos C90); migration com backfill created_by_id → responsável - UI: picker multi-select na criação (nova + wizard) e card de gestão no detalhe com save full-replace + advisory lock; sugestões = assessores do município; rótulo 'Visível para: Responsáveis · Candidato · Coordenador' - int tests reescritos para a regra nova + 5 casos novos; e2e novo de visibilidade (lista/URL/gestão); fixture e2e com createCampaignDemand - impl plan + changelog; importMap regenerado com S3_* dummy (OPS69)
100 lines
3.7 KiB
TypeScript
100 lines
3.7 KiB
TypeScript
'use client'
|
|
|
|
import { useRouter } from 'next/navigation'
|
|
import { useActionState, useCallback, useState } from 'react'
|
|
|
|
import { createWizardDemandFormAction } from '@/app/(campaign)/campanha/(app)/acoes/formActions'
|
|
import { searchDemandActivityOptions } from '@/app/(campaign)/campanha/(app)/demandas/activitySearchActions'
|
|
import { searchDemandResponsibleOptions } from '@/app/(campaign)/campanha/(app)/demandas/responsibleSearchActions'
|
|
import { DemandFields, type DemandActivityValue } from '@/components/campaign/demand/DemandFields'
|
|
import { CampaignFormActionMessage } from '@/components/campaign/shared/CampaignFormActionMessage'
|
|
import { CampaignWizardShell } from '@/components/campaign/shared/CampaignWizardShell'
|
|
import { useCampaignFormSuccessToast } from '@/components/campaign/shared/useCampaignFormSuccessToast'
|
|
import { WizardStepFormChrome } from '@/components/campaign/shared/WizardStepFormChrome'
|
|
import { wizardPreviousHref, wizardReturnHref } from '@/lib/campaignActionRoutes'
|
|
import { recordLastActedMunicipality } from '@/lib/campaignLastActedMunicipality'
|
|
import { WIZARD_DEMAND_PENDING_ARIA, wizardFlowTitleForSlug } from '@/lib/campaignWizardCopy'
|
|
import { CAMPAIGN_DEMAND_SUBMIT_LABEL } from '@/lib/schemas/campaignDemand'
|
|
|
|
type WizardRegisterDemandStepProps = {
|
|
actionSlug: string
|
|
municipalityId: number
|
|
municipalityName: string
|
|
municipalitySlug: string
|
|
returnPath?: string
|
|
currentUser?: { id: number; name: string } | null
|
|
}
|
|
|
|
/**
|
|
* Final step of the "Registrar pedido" wizard (A5/B195): the demand form
|
|
* inside the wizard shell — municipality in the app header (no step title, no
|
|
* municipality selector), single free-text field, save → toast → origin.
|
|
*/
|
|
export const WizardRegisterDemandStep = ({
|
|
actionSlug,
|
|
municipalityId,
|
|
municipalityName,
|
|
municipalitySlug,
|
|
returnPath,
|
|
currentUser = null,
|
|
}: WizardRegisterDemandStepProps) => {
|
|
const router = useRouter()
|
|
const [state, submitAction, isPending] = useActionState(createWizardDemandFormAction, {})
|
|
const [activity, setActivity] = useState<DemandActivityValue | null>(null)
|
|
|
|
const searchActivities = useCallback(
|
|
(query: string) => searchDemandActivityOptions(query, municipalityId),
|
|
[municipalityId],
|
|
)
|
|
const searchResponsibles = useCallback(
|
|
(query: string) => searchDemandResponsibleOptions(query, municipalityId),
|
|
[municipalityId],
|
|
)
|
|
|
|
useCampaignFormSuccessToast(state, () => {
|
|
recordLastActedMunicipality(municipalitySlug)
|
|
router.push(wizardReturnHref(returnPath))
|
|
})
|
|
|
|
return (
|
|
<CampaignWizardShell
|
|
flowTitle={wizardFlowTitleForSlug(actionSlug)}
|
|
isEntryStep={false}
|
|
previousHref={wizardPreviousHref({
|
|
actionSlug,
|
|
stepKind: 'register-demand',
|
|
municipalitySlug,
|
|
returnPath,
|
|
})}
|
|
dismissHref={wizardReturnHref(returnPath)}
|
|
municipalityLabel={municipalityName}
|
|
contentFocus="none"
|
|
>
|
|
<WizardStepFormChrome
|
|
action={submitAction}
|
|
isPending={isPending}
|
|
pendingAnnouncement={WIZARD_DEMAND_PENDING_ARIA}
|
|
ctaLabel={CAMPAIGN_DEMAND_SUBMIT_LABEL}
|
|
ctaClassName="min-w-[8rem]"
|
|
>
|
|
<input type="hidden" name="municipalityId" value={municipalityId} />
|
|
|
|
<DemandFields
|
|
idPrefix="wizard-demand"
|
|
disabled={isPending}
|
|
state={state}
|
|
activity={activity}
|
|
onActivityChange={setActivity}
|
|
searchActivities={searchActivities}
|
|
responsibles={{
|
|
currentUser,
|
|
search: searchResponsibles,
|
|
layout: 'stacked',
|
|
}}
|
|
/>
|
|
|
|
{state.status !== 'success' ? <CampaignFormActionMessage state={state} /> : null}
|
|
</WizardStepFormChrome>
|
|
</CampaignWizardShell>
|
|
)
|
|
}
|