Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | 3x 3x 3x 6x 6x 6x 3x 3x 2x 2x 2x 2x 2x 1x 3x 2x 1x 1x 6x 6x 3x 3x 3x 6x 3x 6x 6x 6x 1x 6x | /**
* AttentionCard (Epic 14 Phase B — Stories 14.B.2 / 14.B.4; FR9, FR12, UX-DR3, UX-DR16).
*
* One "Needs your attention" card, laid out vertically like the prototype `.task`:
* a severity colour strip, the task name, a meta row (due chip + assignee avatar),
* and — when the card deep-links somewhere — a description line of what pressing it
* does ("Open Speakers & Agenda →").
*
* The WHOLE card is the button: clicking it NAVIGATES only — it never triggers a
* side-effect (NFR1); any consequential action lives behind the destination tab's
* own modal. Cards with no target render as a non-interactive panel. Event-day
* (`live`) cards render in an urgent variant.
*/
import React from 'react';
import { Paper, Box, Typography, Chip, ButtonBase } from '@mui/material';
import { alpha } from '@mui/material/styles';
import { ArrowForward as ArrowForwardIcon } from '@mui/icons-material';
import { useTranslation } from 'react-i18next';
import { OrganizerChip } from '@/components/shared/OrganizerChip';
import type { CockpitCard, CardTarget, CardSeverity } from './cockpitCards';
interface AttentionCardProps {
card: CockpitCard;
onNavigate: (target: CardTarget) => void;
}
const STRIP_COLOR: Record<CardSeverity, string> = {
overdue: 'error.main',
live: 'error.main',
dueSoon: 'warning.main',
upcoming: 'success.main',
};
const CHIP_COLOR: Record<CardSeverity, 'error' | 'warning' | 'success'> = {
overdue: 'error',
live: 'error',
dueSoon: 'warning',
upcoming: 'success',
};
export const AttentionCard: React.FC<AttentionCardProps> = ({ card, onNavigate }) => {
const { t, i18n } = useTranslation('events');
const label = card.taskBacked
? String(card.labelVars?.name ?? '')
: t(`eventPage.cockpit.cards.${card.labelKey}`, card.labelVars);
// Due chip text
let dueText: string;
if (card.severity === 'live') {
// Event-day cards are due ON the event date. Before that day, show the date
// ("Event day · 18 Sep 2026"); on/after it, the event is actually live.
const eventDate = card.dueDate ? new Date(card.dueDate) : null;
if (eventDate && !Number.isNaN(eventDate.getTime())) {
const today = new Date();
today.setHours(0, 0, 0, 0);
const eventDay = new Date(eventDate);
eventDay.setHours(0, 0, 0, 0);
dueText =
eventDay.getTime() > today.getTime()
? t('eventPage.cockpit.due.eventDay', 'Event day · {{date}}', {
date: eventDate.toLocaleDateString(i18n.language, {
day: 'numeric',
month: 'short',
year: 'numeric',
}),
})
: t('eventPage.cockpit.due.live', 'Now · event is live');
} else {
dueText = t('eventPage.cockpit.due.live', 'Now · event is live');
}
} else if (card.dueDays === undefined) {
dueText = t('eventPage.cockpit.due.upcoming', 'Upcoming');
} else if (card.severity === 'overdue') {
dueText = t('eventPage.cockpit.due.overdue', 'Overdue · {{days}} days', {
days: Math.abs(card.dueDays),
});
} else if (Ecard.severity === 'dueSoon') {
dueText = t('eventPage.cockpit.due.dueSoon', 'Due in {{days}} days', { days: card.dueDays });
} else {
dueText = t('eventPage.cockpit.due.upcoming', 'Upcoming');
}
// Action description: tab name for tab targets, generic "Open" for routes.
const target = card.target;
let actionLabel: string | undefined;
if (target?.kind === 'tab') {
actionLabel = t('eventPage.cockpit.attention.open', 'Open {{tab}} →', {
tab: t(
`eventPage.tabs.${target.tab === 'speakers' ? 'speakersAgenda' : target.tab}`,
target.tab
),
});
} else if (Etarget?.kind === 'route') {
actionLabel = t('eventPage.cockpit.attention.go', 'Open →');
}
const cardSx = {
display: 'flex',
alignItems: 'stretch',
gap: 1.5,
p: 2,
width: '100%',
textAlign: 'left' as const,
borderRadius: 1.5,
border: 1,
borderColor: 'divider',
borderLeft: 6,
borderLeftColor: STRIP_COLOR[card.severity],
...(card.pinned
? {
bgcolor: (theme: import('@mui/material').Theme) => alpha(theme.palette.error.main, 0.06),
borderColor: 'error.light',
}
: {}),
};
const content = (
<Box
sx={{
flexGrow: 1,
minWidth: 0,
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
gap: 0.75,
}}
>
<Typography variant="body1" fontWeight={card.pinned ? 700 : 600}>
{label}
</Typography>
<Box sx={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 1 }}>
<Chip size="small" color={CHIP_COLOR[card.severity]} variant="outlined" label={dueText} />
<OrganizerChip
username={card.assignee}
data-testid={`cockpit-attention-assignee-${card.id}`}
/>
</Box>
{target && actionLabel && (
<Typography
variant="body2"
color={card.pinned ? 'error' : 'primary'}
fontWeight={600}
sx={{ display: 'inline-flex', alignItems: 'center', gap: 0.5, mt: 0.25 }}
>
{actionLabel}
<ArrowForwardIcon sx={{ fontSize: 16 }} />
</Typography>
)}
</Box>
);
// The whole card is the button when it deep-links somewhere; otherwise it is a
// static panel (e.g. an unmatched task with no target).
Eif (target) {
return (
<ButtonBase
focusRipple
component="div"
role="button"
onClick={() => onNavigate(target)}
aria-label={actionLabel ? `${label} — ${actionLabel}` : label}
data-testid={`cockpit-attention-card${card.taskBacked ? '-task' : ''}`}
data-card-id={card.id}
sx={{
...cardSx,
transition: (theme) => theme.transitions.create(['box-shadow', 'border-color']),
'&:hover': { borderColor: card.pinned ? 'error.main' : 'primary.light', boxShadow: 2 },
'&:focus-visible': { outline: 2, outlineColor: 'primary.main', outlineOffset: 2 },
}}
>
{content}
</ButtonBase>
);
}
return (
<Paper
variant="outlined"
data-testid={`cockpit-attention-card${card.taskBacked ? '-task' : ''}`}
data-card-id={card.id}
sx={cardSx}
>
{content}
</Paper>
);
};
|