2026-07-11 00:48:35 +03:30
|
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
|
|
import { useTranslations } from 'next-intl';
|
|
|
|
|
|
import { ChevronRight } from 'lucide-react';
|
|
|
|
|
|
import { Link } from '@/i18n/navigation';
|
|
|
|
|
|
import { Card } from '@/components/ui/shared/Card';
|
|
|
|
|
|
import { formatTimeForInput } from '@/components/appointments/appointmentTime';
|
|
|
|
|
|
import { canAccessAppointmentsSection } from '@/components/shared/permissions';
|
|
|
|
|
|
import { useAuth } from '@/lib/hooks/useAuth';
|
2026-07-11 00:53:40 +03:30
|
|
|
|
import { ListRowSkeleton } from '@/components/today/TodaySkeleton';
|
2026-07-11 00:48:35 +03:30
|
|
|
|
import type { TodaySummaryActions } from '@/types/today';
|
|
|
|
|
|
|
|
|
|
|
|
interface TodayUpcomingAppointmentsProps {
|
|
|
|
|
|
actions: TodaySummaryActions;
|
|
|
|
|
|
loading?: boolean;
|
2026-07-11 00:53:40 +03:30
|
|
|
|
isInitialLoad?: boolean;
|
2026-07-11 00:48:35 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function TodayUpcomingAppointments({
|
|
|
|
|
|
actions,
|
|
|
|
|
|
loading = false,
|
2026-07-11 00:53:40 +03:30
|
|
|
|
isInitialLoad = false,
|
2026-07-11 00:48:35 +03:30
|
|
|
|
}: TodayUpcomingAppointmentsProps) {
|
|
|
|
|
|
const t = useTranslations('today');
|
|
|
|
|
|
const { currentOrganization } = useAuth();
|
|
|
|
|
|
|
|
|
|
|
|
if (!canAccessAppointmentsSection(currentOrganization)) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const appointments = actions.upcomingAppointmentsToday ?? [];
|
|
|
|
|
|
|
2026-07-11 00:53:40 +03:30
|
|
|
|
if (isInitialLoad) {
|
2026-07-11 00:48:35 +03:30
|
|
|
|
return (
|
2026-07-11 00:53:40 +03:30
|
|
|
|
<Card className="min-h-[280px]">
|
|
|
|
|
|
<div className="mb-4 space-y-2">
|
|
|
|
|
|
<div className="h-4 w-40 animate-pulse rounded bg-background-secondary/60" />
|
|
|
|
|
|
<div className="h-3 w-56 animate-pulse rounded bg-background-secondary/60" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="space-y-3">
|
2026-07-11 00:48:35 +03:30
|
|
|
|
{[0, 1, 2].map((key) => (
|
2026-07-11 00:53:40 +03:30
|
|
|
|
<ListRowSkeleton key={key} />
|
2026-07-11 00:48:35 +03:30
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2026-07-11 00:53:40 +03:30
|
|
|
|
<Card className={`min-h-[280px] ${loading ? 'opacity-70 transition-opacity' : ''}`}>
|
|
|
|
|
|
<div className="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-3 mb-4">
|
2026-07-11 00:48:35 +03:30
|
|
|
|
<div>
|
|
|
|
|
|
<h2 className="text-base font-semibold text-card-foreground">
|
|
|
|
|
|
{t('upcomingAppointmentsTitle')}
|
|
|
|
|
|
</h2>
|
|
|
|
|
|
<p className="text-xs text-text-muted mt-1">{t('upcomingAppointmentsSubtitle')}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Link
|
|
|
|
|
|
href="/appointments"
|
|
|
|
|
|
className="text-xs font-medium text-primary hover:underline underline-offset-2 shrink-0"
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('viewAllAppointments')}
|
|
|
|
|
|
</Link>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{appointments.length === 0 ? (
|
2026-07-11 00:53:40 +03:30
|
|
|
|
<div className="flex flex-1 min-h-[160px] items-center justify-center rounded-[var(--radius-md)] border border-dashed border-border/50 bg-background-secondary/20 px-4">
|
|
|
|
|
|
<p className="text-sm text-text-muted text-center">{t('noUpcomingAppointments')}</p>
|
|
|
|
|
|
</div>
|
2026-07-11 00:48:35 +03:30
|
|
|
|
) : (
|
|
|
|
|
|
<ul className="divide-y divide-border/40">
|
|
|
|
|
|
{appointments.map((appointment) => {
|
|
|
|
|
|
const start = new Date(appointment.startAt);
|
|
|
|
|
|
const end = new Date(appointment.endAt);
|
|
|
|
|
|
const timeLabel = `${formatTimeForInput(start)} – ${formatTimeForInput(end)}`;
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<li key={appointment.id}>
|
|
|
|
|
|
<Link
|
|
|
|
|
|
href="/appointments"
|
|
|
|
|
|
className="flex items-center justify-between gap-3 py-3 -mx-2 px-2 rounded-[var(--radius-md)] hover:bg-background-secondary/45 transition-colors group"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="min-w-0">
|
|
|
|
|
|
<p className="text-sm font-medium text-text-primary truncate">
|
|
|
|
|
|
{appointment.patientName}
|
|
|
|
|
|
</p>
|
2026-07-11 00:53:40 +03:30
|
|
|
|
<p className="text-xs text-text-muted mt-0.5 truncate">
|
2026-07-11 00:48:35 +03:30
|
|
|
|
{timeLabel}
|
|
|
|
|
|
{appointment.purpose ? (
|
|
|
|
|
|
<span className="text-text-secondary"> · {appointment.purpose}</span>
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<ChevronRight
|
|
|
|
|
|
className="h-4 w-4 shrink-0 text-text-muted opacity-0 group-hover:opacity-100 transition-opacity"
|
|
|
|
|
|
aria-hidden
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Link>
|
|
|
|
|
|
</li>
|
|
|
|
|
|
);
|
|
|
|
|
|
})}
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|