Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions frontend/src/pages/DigestPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useMemo, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { Radio, Button, message, Tooltip, theme } from 'antd';
import { Radio, Button, message, Tooltip, theme, Row, Col } from 'antd';
import { ReloadOutlined } from '@ant-design/icons';
import { useWorkspaceStore } from '../store/workspace.store';
import { useDigest } from '../hooks/useDigest';
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function DigestPage() {
const navigate = useNavigate();
const { token } = theme.useToken();
const { workspaces, current, setCurrent, load } = useWorkspaceStore();
const [scope, setScope] = useState<DigestScope>('personal');
const [scope, setScope] = useState<DigestScope | null>(null);
const [period, setPeriod] = useState<DigestPeriod>('7d');
const [statusMessage, setStatusMessage] = useState('');

Expand All @@ -64,19 +64,24 @@ export default function DigestPage() {
const role = foundWs?.role;
const isViewer = role === 'VIEWER';

// Default scope: team for managers (Owner/Member), personal for viewers.
// Until user manually picks, follow the role-derived default.
const defaultScope: DigestScope = isViewer ? 'personal' : 'team';
const activeScope: DigestScope = scope ?? defaultScope;

// Derive effective scope synchronously (no useEffect-loop): viewer is always personal.
const effectiveScope: DigestScope = isViewer && scope === 'team' ? 'personal' : scope;
const effectiveScope: DigestScope = isViewer && activeScope === 'team' ? 'personal' : activeScope;

const { data, loading, error, forbiddenTeam, refetch } = useDigest(workspaceId, effectiveScope, period);

// Auto-switch + toast when backend returns 403 (e.g. stale role on client).
useEffect(() => {
if (forbiddenTeam && scope === 'team') {
if (forbiddenTeam && activeScope === 'team') {
message.warning('Командный разрез недоступен (нужна роль Owner или Member). Показываем личные метрики.');
// eslint-disable-next-line react-hooks/set-state-in-effect
setScope('personal');
}
}, [forbiddenTeam, scope]);
}, [forbiddenTeam, activeScope]);

// Announce data refresh for screen readers via a dedicated live region.
useEffect(() => {
Expand Down Expand Up @@ -132,7 +137,7 @@ export default function DigestPage() {
<h1 style={{ margin: 0, fontSize: 24, fontWeight: 600 }}>Дайджест</h1>

<Radio.Group
value={scope}
value={activeScope}
onChange={(e) => handleScopeChange(e.target.value as DigestScope)}
aria-label="Чьи задачи показывать"
size="large"
Expand Down Expand Up @@ -227,19 +232,14 @@ export default function DigestPage() {
</div>
)}

<div
style={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fit, minmax(280px, 1fr))',
gap: 16,
}}
>
<Row gutter={[16, 16]}>
<Col xs={24} md={12}>
<DigestCard
title="Продуктивность"
loading={loading}
error={error}
onRetry={refetch}
minHeight={280}
minHeight={220}
headingId="digest-h-productivity"
skeletonRows={4}
>
Expand Down Expand Up @@ -279,13 +279,14 @@ export default function DigestPage() {
</div>
)}
</DigestCard>

</Col>
<Col xs={24} md={12}>
<DigestCard
title="Своевременность"
loading={loading}
error={error}
onRetry={refetch}
minHeight={200}
minHeight={180}
headingId="digest-h-timeliness"
>
{data && (
Expand All @@ -312,13 +313,14 @@ export default function DigestPage() {
</div>
)}
</DigestCard>

</Col>
<Col xs={24} md={12}>
<DigestCard
title="Гигиена"
loading={loading}
error={error}
onRetry={refetch}
minHeight={260}
minHeight={220}
headingId="digest-h-hygiene"
skeletonRows={5}
>
Expand Down Expand Up @@ -357,13 +359,14 @@ export default function DigestPage() {
</div>
)}
</DigestCard>

</Col>
<Col xs={24} md={12}>
<DigestCard
title="Распределение нагрузки"
loading={loading}
error={error}
onRetry={refetch}
minHeight={320}
minHeight={280}
headingId="digest-h-workload"
skeletonRows={6}
>
Expand All @@ -385,7 +388,8 @@ export default function DigestPage() {
<WorkloadChart wipByAssignee={data.workload.wipByAssignee} wipByStatus={data.workload.wipByStatus} />
)}
</DigestCard>
</div>
</Col>
</Row>
</div>
);
}
Loading