All files / src/features/babies/components BabyHealthFields.tsx

77.77% Statements 7/9
50% Branches 3/6
66.66% Functions 4/6
77.77% Lines 7/9

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                  7x 7x             16x   16x               16x                   128x                               16x                            
import { Controller, type Control } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
 
import { Label } from '@/components/ui/label'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
import { AllergiesTagInput } from '@/shared/components/AllergiesTagInput'
 
import type { BabyFormInput } from '../api/babies.schemas'
 
const BLOOD_TYPES = ['A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-'] as const
const NOT_INFORMED = 'none'
 
interface BabyHealthFieldsProps {
  control: Control<BabyFormInput>
}
 
export function BabyHealthFields({ control }: BabyHealthFieldsProps) {
  const { t } = useTranslation()
 
  return (
    <div className="space-y-6">
      <div>
        <Label htmlFor="bloodType">{t('babies.form.bloodTypeLabel')}</Label>
        <Controller
          control={control}
          name="bloodType"
          render={({ field }) => (
            <Select
              value={field.value ?? NOT_INFORMED}
              onValueChange={(value) => field.onChange(value === NOT_INFORMED ? undefined : value)}
            >
              <SelectTrigger id="bloodType" className="mt-2 w-full">
                <SelectValue />
              </SelectTrigger>
              <SelectContent>
                <SelectItem value={NOT_INFORMED}>{t('babies.form.bloodTypeNotInformed')}</SelectItem>
                {BLOOD_TYPES.map((bloodType) => (
                  <SelectItem key={bloodType} value={bloodType}>
                    {bloodType}
                  </SelectItem>
                ))}
              </SelectContent>
            </Select>
          )}
        />
      </div>
 
      <div>
        <Label htmlFor="allergies">{t('babies.form.allergiesLabel')}</Label>
        <Controller
          control={control}
          name="allergies"
          render={({ field }) => (
            <AllergiesTagInput
              id="allergies"
              value={field.value ?? []}
              onChange={field.onChange}
              placeholder={t('babies.form.allergiesPlaceholder')}
              removeLabel={(item) => t('babies.form.allergiesRemoveAria', { value: item })}
            />
          )}
        />
      </div>
 
    </div>
  )
}