'use client'; import { useMemo } from 'react'; import { useTranslations } from 'next-intl'; import { Link } from '@/i18n/navigation'; import { useAuth } from '@/lib/hooks/useAuth'; import { canAccessAppointmentsSection, canViewAppointmentsTab, canViewCases, canViewLabCasesOrTasks, canViewTasks, canViewTreatment, } from '@/components/shared/permissions'; import { formatApiErrorMessage } from '@/components/shared/formatApiError'; import { TodayKpiGrid } from '@/components/today/TodayKpiGrid'; import { TodayChartsSection } from '@/components/today/TodayChartsSection'; import { TodayUpcomingAppointments } from '@/components/today/TodayUpcomingAppointments'; import { TodayLoadErrorBanner } from '@/components/today/TodayLoadErrorBanner'; import { TodaySectionErrorFallback } from '@/components/today/TodaySectionErrorFallback'; import { TodayWidgetErrorBoundary } from '@/components/today/TodayWidgetErrorBoundary'; import { useTodaySummary } from '@/lib/hooks/useTodaySummary'; export default function TodayPage() { const t = useTranslations('today'); const { currentOrganization } = useAuth(); const orgId = currentOrganization?.id; const { data, loading, isInitialLoad, error, reload } = useTodaySummary(orgId); const showNoSubscriptionNotice = Boolean(currentOrganization?.isOwner) && !currentOrganization?.plan; const showUpcoming = currentOrganization?.type === 'CLINIC' && canViewTreatment(currentOrganization); const showCharts = useMemo(() => { const orgType = currentOrganization?.type; if (!orgType) return false; if (orgType === 'CLINIC') { return ( canAccessAppointmentsSection(currentOrganization) || canViewAppointmentsTab(currentOrganization) || canViewTreatment(currentOrganization) ); } return ( canViewCases(currentOrganization) || canViewTasks(currentOrganization) || canViewLabCasesOrTasks(currentOrganization) ); }, [currentOrganization]); const sectionErrorMessage = t('sectionLoadError'); return (
{t('lastUpdated', { time: new Intl.DateTimeFormat(undefined, { hour: 'numeric', minute: '2-digit', }).format(new Date(data.generatedAt)), })}
) : null}{t('noSubscriptionNotice')}{' '} {t('choosePlanLink')} {' '} {t('noSubscriptionCta')}