All files / src/features/appointments/components AppointmentCard.tsx

100% Statements 4/4
52.17% Branches 12/23
100% Functions 1/1
100% Lines 4/4

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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109                                            4x 4x 4x 4x                                                                                                                                                                      
import { useTranslation } from 'react-i18next'
import { MapPin, ClipboardList } from 'lucide-react'
import type { Baby } from '@/features/babies/api/babies.schemas'
import { formatDateDisplay, splitScheduledAt } from '@/lib/date'
import { formatCentimeters, formatKilograms } from '@/shared/utils/measurements'
import { AppointmentStatusBadge } from './AppointmentStatusBadge'
import { appointmentGroup } from './appointment-view'
import type { Appointment } from '../api/appointments.schemas'
interface Props {
  appointment: Appointment
  baby?: Baby
  featured?: boolean
  onReschedule: () => void
  onViewDetails: () => void
}
export function AppointmentCard({
  appointment,
  baby,
  featured = false,
  onReschedule,
  onViewDetails,
}: Props) {
  const { t, i18n } = useTranslation()
  const { date, time } = splitScheduledAt(appointment.scheduledAt)
  const group = appointmentGroup(appointment, Date.now())
  return (
    <article
      className={`flex min-w-0 flex-col rounded-2xl border p-5 ${featured ? 'border-violet-300 bg-violet-50/60 dark:border-violet-800 dark:bg-violet-950/30 lg:col-span-2' : 'border-border bg-card'}`}
    >
      {featured && (
        <p className="mb-3 text-xs font-bold uppercase tracking-wide text-violet-800 dark:text-violet-200">
          {t('appointments.page.next')}
        </p>
      )}
      <div className="flex flex-wrap items-start justify-between gap-3">
        <div className="min-w-0">
          <p className="mb-2 font-sans tabular-nums text-sm text-violet-800 dark:text-violet-200">
            {formatDateDisplay(date, i18n.language)} · {time}
          </p>
          <h3 className="break-words text-lg font-bold text-ink">{appointment.doctorName}</h3>
          <p className="mt-1 break-words text-sm text-ink-muted">
            {[baby?.name, appointment.specialty].filter(Boolean).join(' · ')}
          </p>
        </div>
        <AppointmentStatusBadge status={appointment.status} />
      </div>
      {group === 'REVIEW' && (
        <p className="mt-3 rounded-xl bg-amber-50 p-3 text-sm text-amber-900 dark:bg-amber-950/40 dark:text-amber-200">
          {t('appointments.page.reviewHint')}
        </p>
      )}
      <dl className="mt-4 space-y-2 text-sm text-ink-muted">
        {appointment.location && (
          <div className="flex items-start gap-2">
            <MapPin aria-hidden className="mt-0.5 size-4 shrink-0" />
            <dt className="sr-only">{t('appointments.page.location')}</dt>
            <dd className="break-words">{appointment.location}</dd>
          </div>
        )}
        {appointment.reason && (
          <div className="flex items-start gap-2">
            <ClipboardList aria-hidden className="mt-0.5 size-4 shrink-0" />
            <dt className="sr-only">{t('appointments.page.reason')}</dt>
            <dd className="break-words">{appointment.reason}</dd>
          </div>
        )}
      </dl>
      {appointment.status === 'COMPLETED' &&
        (appointment.weightGrams !== null || appointment.heightMillimeters !== null) && (
          <p className="mt-3 font-sans tabular-nums text-sm text-ink-muted">
            {[
              appointment.weightGrams !== null
                ? formatKilograms(appointment.weightGrams, i18n.language)
                : null,
              appointment.heightMillimeters !== null
                ? formatCentimeters(appointment.heightMillimeters, i18n.language)
                : null,
            ]
              .filter(Boolean)
              .join(' · ')}
          </p>
        )}
      {appointment.notes && (
        <p className="mt-3 line-clamp-2 whitespace-pre-wrap break-words rounded-xl bg-muted/50 p-3 text-sm text-ink-muted">
          {appointment.notes}
        </p>
      )}
      <div className="mt-auto flex flex-wrap justify-end gap-2 pt-5">
        {appointment.status === 'SCHEDULED' && (
          <button
            type="button"
            onClick={onReschedule}
            className="min-h-11 rounded-xl border border-border px-4 py-2 text-sm font-semibold text-ink-muted hover:bg-muted"
          >
            {t('appointments.reschedule.action')}
          </button>
        )}
        <button
          type="button"
          onClick={onViewDetails}
          className="min-h-11 rounded-xl bg-violet-700 px-4 py-2 text-sm font-semibold text-white hover:bg-violet-800"
        >
          {t('appointments.detail.action')}
        </button>
      </div>
    </article>
  )
}