mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-27 14:23:05 +00:00
- MunicipalityUpdateFields ganha layout 'labeled'|'list'; polaridade vira ToggleGroup Ruim|Neutra|Boa nas duas resoluções (mesmo dado, hidden input) - layout 'list': labels sr-only, textarea sem borda, divisórias divide-y full-bleed, Urgente/Sinalizar adversário como linha tocável com check à direita - StrictCombobox: prop placeholder (backward-compatible) - Sheet do feed: max-h-dvh (teto no topo, rola por dentro), título sr-only, form lista com placeholders descritivos; desktop preservado - Quick-edit B42 herda o visual no sheet mobile via layout - unit/e2e atualizados para o toggle (radio)
116 lines
3.8 KiB
TypeScript
116 lines
3.8 KiB
TypeScript
'use client'
|
|
|
|
import { useActionState, useId, useState, type ReactNode } from 'react'
|
|
|
|
import { MunicipalityUpdateFields } from '@/components/campaign/municipality/MunicipalityUpdateFields'
|
|
import {
|
|
CampaignCellEditOverlay,
|
|
type CampaignCellEditOverlayVariant,
|
|
} from '@/components/campaign/shared/CampaignCellEditOverlay'
|
|
import { CampaignFormActionMessage } from '@/components/campaign/shared/CampaignFormActionMessage'
|
|
import { useCampaignFormSuccessToast } from '@/components/campaign/shared/useCampaignFormSuccessToast'
|
|
import { Button } from '@/components/ui/button'
|
|
import { DrawerCloseButton } from '@/components/ui/Drawer'
|
|
import { Spinner } from '@/components/ui/Spinner'
|
|
import { cn } from '@/lib/utils'
|
|
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
|
|
import {
|
|
formatMunicipalitySignalAgeLabel,
|
|
municipalitySignalAgeInDays,
|
|
} from '@/utilities/municipality/municipalitySignal'
|
|
|
|
type MunicipalityStaffFormAction = (
|
|
state: CampaignFormActionState,
|
|
formData: FormData,
|
|
) => Promise<CampaignFormActionState>
|
|
|
|
type MunicipalityListUpdateControlProps = {
|
|
municipalityID: number
|
|
municipalitySlug: string
|
|
municipalityName: string
|
|
lastSignalAt: string | null
|
|
variant: CampaignCellEditOverlayVariant
|
|
formAction: MunicipalityStaffFormAction
|
|
isStaff: boolean
|
|
children: ReactNode
|
|
}
|
|
|
|
export const MunicipalityListUpdateControl = ({
|
|
municipalityID,
|
|
municipalitySlug,
|
|
municipalityName,
|
|
lastSignalAt,
|
|
variant,
|
|
formAction,
|
|
isStaff,
|
|
children,
|
|
}: MunicipalityListUpdateControlProps) => {
|
|
const [open, setOpen] = useState(false)
|
|
const [formKey, setFormKey] = useState(0)
|
|
const [state, submitAction, isPending] = useActionState(formAction, {})
|
|
const reactId = useId()
|
|
const idPrefix = `municipality-list-update-${variant}-${municipalityID}-${reactId}`
|
|
const formId = `${idPrefix}-form`
|
|
const isSheet = variant === 'sheet'
|
|
const frescorLabel = formatMunicipalitySignalAgeLabel(municipalitySignalAgeInDays(lastSignalAt))
|
|
|
|
useCampaignFormSuccessToast(state, () => {
|
|
setOpen(false)
|
|
setFormKey((key) => key + 1)
|
|
})
|
|
|
|
const submitButton = (
|
|
<Button type="submit" form={formId} disabled={isPending} className="min-h-11 w-full">
|
|
{isPending ? <Spinner data-icon="inline-start" aria-hidden="true" /> : null}
|
|
Registrar atualização
|
|
</Button>
|
|
)
|
|
|
|
return (
|
|
<CampaignCellEditOverlay
|
|
variant={variant}
|
|
open={open}
|
|
onOpenChange={setOpen}
|
|
title="Registrar atualização"
|
|
description={municipalityName}
|
|
triggerLabel={`Registrar atualização em ${municipalityName} — ${frescorLabel}`}
|
|
triggerBusy={isPending}
|
|
statusMessage={isPending ? 'Registrando atualização…' : ''}
|
|
triggerClassName="min-w-11 text-left"
|
|
contentClassName="w-80"
|
|
sheetBodyClassName={isSheet ? 'px-0 pt-0' : undefined}
|
|
trigger={children}
|
|
footer={
|
|
isSheet && open ? (
|
|
<>
|
|
{submitButton}
|
|
<DrawerCloseButton>Cancelar</DrawerCloseButton>
|
|
</>
|
|
) : undefined
|
|
}
|
|
>
|
|
<form
|
|
key={formKey}
|
|
id={formId}
|
|
action={submitAction}
|
|
className={cn('flex flex-col', !isSheet && 'gap-3')}
|
|
aria-busy={isPending || undefined}
|
|
>
|
|
<input type="hidden" name="municipalityId" value={municipalityID} />
|
|
<input type="hidden" name="municipalitySlug" value={municipalitySlug} />
|
|
<MunicipalityUpdateFields
|
|
idPrefix={idPrefix}
|
|
fieldErrors={state.fieldErrors}
|
|
isStaff={isStaff}
|
|
layout={isSheet ? 'list' : 'labeled'}
|
|
/>
|
|
{state.status !== 'success' && state.message ? (
|
|
<div className={cn(isSheet && 'px-4 pt-3')}>
|
|
<CampaignFormActionMessage state={state} />
|
|
</div>
|
|
) : null}
|
|
{isSheet ? null : submitButton}
|
|
</form>
|
|
</CampaignCellEditOverlay>
|
|
)
|
|
}
|