'use client' import { useRouter } from 'next/navigation' import { startTransition, useActionState, type FormEvent } from 'react' import { registerActivityResultFormAction } from '@/app/(campaign)/campanha/(app)/atividades/[slug]/resultFormActions' import { CampaignFormActionMessage } from '@/components/campaign/shared/CampaignFormActionMessage' import { useCampaignFormSuccessToast } from '@/components/campaign/shared/useCampaignFormSuccessToast' import { Button } from '@/components/ui/button' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Field, FieldDescription, FieldError, FieldLabel } from '@/components/ui/field' import { Spinner } from '@/components/ui/Spinner' import { Textarea } from '@/components/ui/textarea' import { formatBahiaDateTimeLabel } from '@/lib/campaignTime' import { fieldError } from '@/utilities/campaignFormFields' type ActivityResultFormProps = { activityId: number initialSummary: string | null recordedByName: string | null recordedAt: string | null } export const ActivityResultForm = ({ activityId, initialSummary, recordedByName, recordedAt, }: ActivityResultFormProps) => { const router = useRouter() const [state, formAction, pending] = useActionState(registerActivityResultFormAction, {}) useCampaignFormSuccessToast(state, router.refresh) const summaryError = fieldError(state.fieldErrors, 'resultSummary') const recordedLabel = initialSummary ? [ recordedByName ? `Registrado por ${recordedByName}` : 'Registrado', recordedAt ? `em ${formatBahiaDateTimeLabel(recordedAt)}` : null, ] .filter(Boolean) .join(' ') : null // C139 — manual dispatch: React 19 resets uncontrolled fields after any // settled form action, reverting the typed result to `initialSummary` on // a validation error. `startTransition` keeps `pending` correct. const handleSubmit = (event: FormEvent) => { event.preventDefault() startTransition(() => formAction(new FormData(event.currentTarget))) } return ( Resultado da atividade {recordedLabel ?

{recordedLabel}

: null}
{state.status !== 'success' ? ( ) : null} O que aconteceu *