'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 { AsyncSearchCombobox } from '@/components/campaign/shared/AsyncSearchCombobox' import { CampaignFormActionMessage } from '@/components/campaign/shared/CampaignFormActionMessage' import { CampaignWizardShell } from '@/components/campaign/shared/CampaignWizardShell' import { useCampaignFormSuccessToast } from '@/components/campaign/shared/useCampaignFormSuccessToast' import { Button } from '@/components/ui/button' import { Field, FieldDescription, FieldError, FieldLabel } from '@/components/ui/field' import { NativeSelect, NativeSelectOption } from '@/components/ui/native-select' import { Spinner } from '@/components/ui/Spinner' import { Textarea } from '@/components/ui/textarea' import { wizardPreviousHref, wizardReturnHref } from '@/lib/campaignActionRoutes' import { recordLastActedMunicipality } from '@/lib/campaignLastActedMunicipality' import { WIZARD_DEMAND_PENDING_ARIA, wizardFlowTitleForSlug } from '@/lib/campaignWizardCopy' import { CAMPAIGN_DEMAND_ACTIVITY_DESCRIPTION, CAMPAIGN_DEMAND_ACTIVITY_DIALOG_DESCRIPTION, CAMPAIGN_DEMAND_ACTIVITY_EMPTY_LABEL, CAMPAIGN_DEMAND_ACTIVITY_LABEL, CAMPAIGN_DEMAND_BODY_DESCRIPTION, CAMPAIGN_DEMAND_BODY_LABEL, CAMPAIGN_DEMAND_BODY_MAX_LENGTH, CAMPAIGN_DEMAND_BODY_PLACEHOLDER, CAMPAIGN_DEMAND_KIND_LABEL, CAMPAIGN_DEMAND_SUBMIT_LABEL, campaignDemandKindLabels, campaignDemandKinds, } from '@/lib/schemas/campaignDemand' type WizardRegisterDemandStepProps = { actionSlug: string municipalityId: number municipalityName: string municipalitySlug: string returnPath?: string } /** * 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, }: WizardRegisterDemandStepProps) => { const router = useRouter() const [state, submitAction, isPending] = useActionState(createWizardDemandFormAction, {}) const [activity, setActivity] = useState<{ id: number; label: string } | null>(null) const searchActivities = useCallback( (query: string) => searchDemandActivityOptions(query, municipalityId), [municipalityId], ) useCampaignFormSuccessToast(state, () => { recordLastActedMunicipality(municipalitySlug) router.push(wizardReturnHref(returnPath)) }) return (
{CAMPAIGN_DEMAND_KIND_LABEL} {campaignDemandKinds.map((kind) => ( {campaignDemandKindLabels[kind]} ))} {CAMPAIGN_DEMAND_ACTIVITY_LABEL} {CAMPAIGN_DEMAND_ACTIVITY_DESCRIPTION} {state.fieldErrors?.activity ? ( {state.fieldErrors.activity} ) : null} {CAMPAIGN_DEMAND_BODY_LABEL} {CAMPAIGN_DEMAND_BODY_DESCRIPTION}