2026-04-30 18:15:40 +03:30
|
|
|
'use client';
|
|
|
|
|
|
2026-07-11 00:53:40 +03:30
|
|
|
import { useMemo } from 'react';
|
2026-06-20 14:51:43 +03:30
|
|
|
import { useTranslations } from 'next-intl';
|
2026-06-20 12:37:38 +03:30
|
|
|
import { Link } from '@/i18n/navigation';
|
2026-04-30 18:15:40 +03:30
|
|
|
import { useAuth } from '@/lib/hooks/useAuth';
|
2026-07-11 00:53:40 +03:30
|
|
|
import { formatApiErrorMessage } from '@/components/shared/formatApiError';
|
2026-07-11 22:32:37 +03:30
|
|
|
import { TodayDashboard } from '@/components/today/TodayDashboard';
|
2026-07-11 00:53:40 +03:30
|
|
|
import { TodayLoadErrorBanner } from '@/components/today/TodayLoadErrorBanner';
|
|
|
|
|
import { TodaySectionErrorFallback } from '@/components/today/TodaySectionErrorFallback';
|
|
|
|
|
import { TodayWidgetErrorBoundary } from '@/components/today/TodayWidgetErrorBoundary';
|
2026-07-11 00:07:48 +03:30
|
|
|
import { useTodaySummary } from '@/lib/hooks/useTodaySummary';
|
2026-04-30 18:15:40 +03:30
|
|
|
|
2026-04-23 15:33:11 +03:30
|
|
|
export default function TodayPage() {
|
2026-06-20 14:51:43 +03:30
|
|
|
const t = useTranslations('today');
|
2026-04-30 18:15:40 +03:30
|
|
|
const { currentOrganization } = useAuth();
|
2026-07-11 00:53:40 +03:30
|
|
|
const orgId = currentOrganization?.id;
|
|
|
|
|
const { data, loading, isInitialLoad, error, reload } = useTodaySummary(orgId);
|
|
|
|
|
|
2026-07-11 22:32:37 +03:30
|
|
|
const showNoSubscriptionNotice = useMemo(
|
|
|
|
|
() => Boolean(currentOrganization?.isOwner) && !currentOrganization?.plan,
|
|
|
|
|
[currentOrganization],
|
|
|
|
|
);
|
2026-07-11 00:53:40 +03:30
|
|
|
|
|
|
|
|
const sectionErrorMessage = t('sectionLoadError');
|
|
|
|
|
|
2026-04-23 15:33:11 +03:30
|
|
|
return (
|
2026-07-11 00:07:48 +03:30
|
|
|
<div className="space-y-6">
|
2026-07-11 00:53:40 +03:30
|
|
|
<div className="flex flex-col gap-1 sm:flex-row sm:items-end sm:justify-between">
|
|
|
|
|
<h1 className="text-2xl font-semibold">{t('welcomeBack')}</h1>
|
|
|
|
|
{data?.generatedAt && !isInitialLoad ? (
|
|
|
|
|
<p className="text-xs text-text-muted">
|
|
|
|
|
{t('lastUpdated', {
|
|
|
|
|
time: new Intl.DateTimeFormat(undefined, {
|
|
|
|
|
hour: 'numeric',
|
|
|
|
|
minute: '2-digit',
|
|
|
|
|
}).format(new Date(data.generatedAt)),
|
|
|
|
|
})}
|
|
|
|
|
</p>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
2026-04-23 15:33:11 +03:30
|
|
|
|
2026-04-30 18:15:40 +03:30
|
|
|
{showNoSubscriptionNotice && (
|
2026-07-11 00:07:48 +03:30
|
|
|
<div className="rounded-[var(--radius-md)] border border-amber-500/30 bg-amber-500/10 p-4">
|
2026-04-30 18:15:40 +03:30
|
|
|
<p className="text-sm text-amber-200">
|
2026-06-20 14:51:43 +03:30
|
|
|
{t('noSubscriptionNotice')}{' '}
|
2026-04-30 18:15:40 +03:30
|
|
|
<Link href="/settings/subscriptions" className="font-medium underline underline-offset-2">
|
2026-06-20 14:51:43 +03:30
|
|
|
{t('choosePlanLink')}
|
2026-04-30 18:15:40 +03:30
|
|
|
</Link>{' '}
|
2026-06-20 14:51:43 +03:30
|
|
|
{t('noSubscriptionCta')}
|
2026-04-30 18:15:40 +03:30
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-07-11 00:07:48 +03:30
|
|
|
{error ? (
|
2026-07-11 00:53:40 +03:30
|
|
|
<TodayLoadErrorBanner
|
|
|
|
|
message={formatApiErrorMessage(error, t('loadError'))}
|
|
|
|
|
retryLabel={t('retryLoad')}
|
|
|
|
|
onRetry={() => void reload()}
|
|
|
|
|
isRetrying={loading && Boolean(data)}
|
|
|
|
|
/>
|
2026-07-11 00:07:48 +03:30
|
|
|
) : null}
|
|
|
|
|
|
2026-07-11 00:53:40 +03:30
|
|
|
<TodayWidgetErrorBoundary
|
|
|
|
|
fallback={<TodaySectionErrorFallback message={sectionErrorMessage} />}
|
|
|
|
|
>
|
2026-07-11 22:32:37 +03:30
|
|
|
<TodayDashboard
|
2026-07-11 00:53:40 +03:30
|
|
|
widgets={data?.widgets ?? {}}
|
2026-07-11 22:32:37 +03:30
|
|
|
charts={data?.charts ?? {}}
|
|
|
|
|
actions={data?.actions ?? {}}
|
|
|
|
|
subscription={data?.subscription}
|
2026-07-11 00:53:40 +03:30
|
|
|
loading={loading}
|
|
|
|
|
isInitialLoad={isInitialLoad}
|
|
|
|
|
hasError={Boolean(error)}
|
|
|
|
|
/>
|
|
|
|
|
</TodayWidgetErrorBoundary>
|
2026-04-23 15:33:11 +03:30
|
|
|
</div>
|
|
|
|
|
);
|
2026-06-20 14:51:43 +03:30
|
|
|
}
|