2026-07-11 00:34:38 +03:30
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { useTranslations } from 'next-intl';
|
|
|
|
|
import { useAuth } from '@/lib/hooks/useAuth';
|
|
|
|
|
import {
|
|
|
|
|
canViewTasks,
|
|
|
|
|
canViewTreatment,
|
|
|
|
|
} from '@/components/shared/permissions';
|
|
|
|
|
import { ChartCard } from '@/components/today/ChartCard';
|
|
|
|
|
import { TodayBarChart } from '@/components/today/TodayBarChart';
|
2026-07-11 00:53:40 +03:30
|
|
|
import { ChartCardSkeleton } from '@/components/today/TodaySkeleton';
|
2026-07-11 00:34:38 +03:30
|
|
|
import type { TodaySummaryCharts } from '@/types/today';
|
|
|
|
|
|
|
|
|
|
interface TodayChartsSectionProps {
|
|
|
|
|
charts: TodaySummaryCharts;
|
|
|
|
|
loading?: boolean;
|
2026-07-11 00:53:40 +03:30
|
|
|
isInitialLoad?: boolean;
|
|
|
|
|
className?: string;
|
2026-07-11 00:34:38 +03:30
|
|
|
}
|
|
|
|
|
|
2026-07-11 00:53:40 +03:30
|
|
|
export function TodayChartsSection({
|
|
|
|
|
charts,
|
|
|
|
|
loading = false,
|
|
|
|
|
isInitialLoad = false,
|
|
|
|
|
className = '',
|
|
|
|
|
}: TodayChartsSectionProps) {
|
2026-07-11 00:34:38 +03:30
|
|
|
const t = useTranslations('today');
|
|
|
|
|
const { currentOrganization } = useAuth();
|
|
|
|
|
const orgType = currentOrganization?.type;
|
|
|
|
|
|
|
|
|
|
const showTreatmentMix =
|
|
|
|
|
orgType === 'CLINIC' && canViewTreatment(currentOrganization);
|
|
|
|
|
const showTasksByStep =
|
|
|
|
|
orgType === 'LAB' && canViewTasks(currentOrganization);
|
|
|
|
|
|
|
|
|
|
if (!showTreatmentMix && !showTasksByStep) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const treatmentData = charts.treatmentMixWeek ?? [];
|
|
|
|
|
const tasksData = charts.tasksByWorkflowStep ?? [];
|
|
|
|
|
|
2026-07-11 00:53:40 +03:30
|
|
|
if (isInitialLoad) {
|
|
|
|
|
return (
|
|
|
|
|
<div className={`grid grid-cols-1 gap-4 ${className}`}>
|
|
|
|
|
{showTreatmentMix ? <ChartCardSkeleton /> : null}
|
|
|
|
|
{showTasksByStep ? <ChartCardSkeleton /> : null}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const chartCount = (showTreatmentMix ? 1 : 0) + (showTasksByStep ? 1 : 0);
|
|
|
|
|
|
2026-07-11 00:34:38 +03:30
|
|
|
return (
|
2026-07-11 00:53:40 +03:30
|
|
|
<div
|
|
|
|
|
className={`grid grid-cols-1 ${chartCount > 1 ? 'lg:grid-cols-2' : ''} gap-4 ${loading ? 'opacity-70 transition-opacity' : ''} ${className}`}
|
|
|
|
|
>
|
2026-07-11 00:34:38 +03:30
|
|
|
{showTreatmentMix ? (
|
|
|
|
|
<ChartCard
|
|
|
|
|
title={t('chartTreatmentMixTitle')}
|
|
|
|
|
subtitle={t('chartTreatmentMixSubtitle')}
|
2026-07-11 00:53:40 +03:30
|
|
|
isEmpty={treatmentData.length === 0}
|
2026-07-11 00:34:38 +03:30
|
|
|
emptyMessage={t('chartEmpty')}
|
|
|
|
|
>
|
|
|
|
|
<TodayBarChart data={treatmentData} />
|
|
|
|
|
</ChartCard>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{showTasksByStep ? (
|
|
|
|
|
<ChartCard
|
|
|
|
|
title={t('chartTasksByStepTitle')}
|
|
|
|
|
subtitle={t('chartTasksByStepSubtitle')}
|
2026-07-11 00:53:40 +03:30
|
|
|
isEmpty={tasksData.length === 0}
|
2026-07-11 00:34:38 +03:30
|
|
|
emptyMessage={t('chartEmpty')}
|
|
|
|
|
>
|
|
|
|
|
<TodayBarChart data={tasksData} />
|
|
|
|
|
</ChartCard>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|