Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 6x 6x 6x 6x | import type { FieldErrors, UseFormRegister } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { fieldErrorKey } from '@/shared/utils/zod-error'
import type { AppointmentFormInput } from '../api/appointments.schemas'
interface AppointmentMeasurementFieldsProps {
register: UseFormRegister<AppointmentFormInput>
errors: FieldErrors<AppointmentFormInput>
}
/**
* Peso e altura da visita — mostrados só quando a consulta é um fato.
*
* A API recusa medida em consulta que ainda não aconteceu, e a razão não é
* arrumação: estas duas colunas são a série de crescimento, e um ponto preso a
* uma visita futura seria plotado no futuro sem nada que o distinga de uma
* medição real. Esconder os campos ao agendar não é decoração da regra — é a
* única leitura em que o formulário não oferece o que o servidor recusa.
*
* `type="text"` com `inputMode="decimal"`, e não `type="number"`: o teclado
* numérico brasileiro oferece vírgula, e um campo numérico descarta o valor
* inteiro ao ver uma — a pessoa vê o peso sumir no blur, sem erro nenhum que
* explique. A vírgula é aceita e convertida em `measurements.ts`.
*/
export function AppointmentMeasurementFields({ register, errors }: AppointmentMeasurementFieldsProps) {
const { t } = useTranslation()
const weightErrorKey = fieldErrorKey(errors.weightKg)
const heightErrorKey = fieldErrorKey(errors.heightCm)
return (
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
<div>
<Label htmlFor="weightKg">{t('appointments.form.weightLabel')}</Label>
<Input
id="weightKg"
inputMode="decimal"
placeholder={t('appointments.form.weightPlaceholder')}
aria-invalid={!!errors.weightKg}
aria-describedby={weightErrorKey ? 'weightKg-error' : undefined}
className="mt-2 font-sans tabular-nums"
{...register('weightKg')}
/>
{weightErrorKey && (
<p id="weightKg-error" className="text-destructive mt-1 text-sm">
{t(weightErrorKey)}
</p>
)}
</div>
<div>
<Label htmlFor="heightCm">{t('appointments.form.heightLabel')}</Label>
<Input
id="heightCm"
inputMode="decimal"
placeholder={t('appointments.form.heightPlaceholder')}
aria-invalid={!!errors.heightCm}
aria-describedby={heightErrorKey ? 'heightCm-error' : undefined}
className="mt-2 font-sans tabular-nums"
{...register('heightCm')}
/>
{heightErrorKey && (
<p id="heightCm-error" className="text-destructive mt-1 text-sm">
{t(heightErrorKey)}
</p>
)}
</div>
</div>
)
}
|