'use client' import { CalendarIcon } from 'lucide-react' import { ptBR } from 'react-day-picker/locale' import { Button } from '@/components/ui/button' import { Calendar } from '@/components/ui/Calendar' import { NativeSelect, NativeSelectOption } from '@/components/ui/native-select' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/Popover' import { floorToMinuteStep, formatBahiaCivilDate, formatBahiaCivilDateTimeLabel, hourOptions, minuteOptionsForStep, parseBahiaDateTimeInput, } from '@/lib/campaignTime' import { cn } from '@/lib/utils' /** * C97 — shadcn day + time picker for the agenda quick create. The value * contract is the civil `YYYY-MM-DDTHH:mm` string the old `datetime-local` * used, so parse/validation on submit is untouched. 24h by construction: * the trigger formats the civil string directly and the selects list * 00–23 / 00–45, so no browser locale or Intl hour cycle can inject AM/PM. * The parent renders the surrounding Field/FieldError; this component is the * control itself (trigger + popover with calendar and step selects). */ export const ActivityDateTimeField = ({ id, value, onValueChange, invalid = false, errorId, }: { id: string value: string onValueChange: (value: string) => void invalid?: boolean /** FieldError id to announce on focus — parity with the input it replaces. */ errorId?: string }) => { const civil = floorToMinuteStep(value) const datePart = civil.slice(0, 10) const timePart = civil.slice(11) const hour = timePart.slice(0, 2) const minute = timePart.slice(3, 5) const setDate = (date: Date | undefined) => { if (!date) return onValueChange(`${formatBahiaCivilDate(date)}T${timePart}`) } const setHour = (next: string) => onValueChange(`${datePart}T${next}:${minute}`) const setMinute = (next: string) => onValueChange(`${datePart}T${hour}:${next}`) const selectedInstant = parseBahiaDateTimeInput(`${datePart}T12:00`) return ( {selectedInstant ? ( ) : null}
Hora setHour(event.target.value)} > {hourOptions.map((option) => ( {option}h ))}
Minuto setMinute(event.target.value)} > {minuteOptionsForStep().map((option) => ( {option} ))}
) }