'use client' import type { LeadershipListSupportStatusResponse } from '@/app/(campaign)/campanha/(app)/liderancas/support-status/types' import { SupportStatusBadge } from '@/components/campaign/leadership/SupportStatusBadge' import { CampaignCellEditOverlay } from '@/components/campaign/shared/CampaignCellEditOverlay' import { useCampaignCellAutosave } from '@/components/campaign/shared/useCampaignCellAutosave' import { Alert, AlertDescription } from '@/components/ui/Alert' import { Field, FieldLabel } from '@/components/ui/field' import { NativeSelect, NativeSelectOption } from '@/components/ui/native-select' import { Spinner } from '@/components/ui/Spinner' import { isSupportStatus, leadershipSupportStatuses, type SupportStatus, } from '@/lib/schemas/leadership' import { supportStatusLabels } from '@/utilities/leadership/leadershipLabels' const STATUS_AUTOSAVE_MS = 150 const SUPPORT_STATUS_ENDPOINT = '/campanha/liderancas/support-status' const SAVE_ERROR_MESSAGE = 'Não foi possível salvar o status. Tente novamente.' const DEFAULT_STATUS: SupportStatus = 'a_abordar' type LeadershipListSupportStatusControlProps = { leadershipID: number status: SupportStatus | null } export const LeadershipListSupportStatusControl = ({ leadershipID, status, }: LeadershipListSupportStatusControlProps) => { const { open, onOpenChange, value, change, isPending, errorMessage, statusMessage } = useCampaignCellAutosave({ value: status ?? DEFAULT_STATUS, equals: (left, right) => left === right, endpoint: SUPPORT_STATUS_ENDPOINT, buildBody: (supportStatus) => ({ leadershipId: leadershipID, supportStatus }), readSaved: (payload) => payload.savedSupportStatus, errorMessage: SAVE_ERROR_MESSAGE, pendingMessage: 'Salvando status de apoio.', }) const handleStatusChange = (raw: string) => { if (!isSupportStatus(raw)) return change(raw, STATUS_AUTOSAVE_MS) } return ( // The leaderships list is table-only, so this stays a Popover at every // viewport — the shell is here for the trigger and content it already owns, // not for a Drawer this surface has nowhere to put (B42). } >
{isPending ? ( ) : null} Status de apoio handleStatusChange(event.target.value)} className="min-h-11 w-full" > {leadershipSupportStatuses.map((option) => ( {supportStatusLabels[option]} ))} {errorMessage ? ( {errorMessage} ) : null}
) }