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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | 2x 2x 2x 2x 2x | /**
* TaskCard Component (Shared)
*
* Reusable task card component used in:
* - TaskWidget (critical tasks sidebar)
* - TaskBoardPage (Kanban board)
*
* Features:
* - Displays task name, event code, due date, assignee
* - Optional complete button
* - Optional trigger state and completion info
* - Configurable styling via sx prop
*/
import React from 'react';
import {
ListItem,
ListItemText,
Typography,
Stack,
Chip,
IconButton,
Tooltip,
} from '@mui/material';
import {
CheckCircle as CheckCircleIcon,
Delete as DeleteIcon,
Edit as EditIcon,
} from '@mui/icons-material';
import { format } from 'date-fns';
import { type Locale } from 'date-fns/locale';
import { useTranslation } from 'react-i18next';
import { OrganizerChip } from '@/components/shared/OrganizerChip';
import { type EventTaskResponse } from '@/services/taskService';
import { type SxProps, type Theme } from '@mui/material/styles';
import type { TFunction } from 'i18next';
export interface TaskCardProps {
task: EventTaskResponse;
locale: Locale;
onComplete?: (taskId: string) => void;
onEdit?: (task: EventTaskResponse) => void;
onDelete?: (task: EventTaskResponse) => void;
showCompleteButton?: boolean;
showEventCode?: boolean;
showTriggerState?: boolean;
showCompletionInfo?: boolean;
sx?: SxProps<Theme>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
t: TFunction<any, undefined>;
// Drag-and-drop props (optional)
draggableRef?: React.Ref<HTMLLIElement>;
draggableStyle?: React.CSSProperties;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
draggableListeners?: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
draggableAttributes?: any;
}
export const TaskCard: React.FC<TaskCardProps> = ({
task,
locale,
onComplete,
onEdit,
onDelete,
showCompleteButton = true,
showEventCode = true,
showTriggerState = false,
showCompletionInfo = false,
sx,
t,
draggableRef,
draggableStyle,
draggableListeners,
draggableAttributes,
}) => {
// The workflow-state labels (`tasks.workflowStates.*`) live in the `events`
// namespace. The `t` passed in is bound to the caller's namespace (e.g.
// `organizer` on the /organizer/tasks board), which lacks those keys — so
// resolve the state chip from `events` directly, regardless of the caller.
const { t: tWorkflowState } = useTranslation('events');
const formattedDueDate = task.dueDate
? format(new Date(task.dueDate), 'dd MMM yyyy HH:mm', { locale })
: null;
const formattedCompletedDate =
showCompletionInfo && task.completedDate
? format(new Date(task.completedDate), 'dd MMM yyyy HH:mm', { locale })
: null;
return (
<ListItem
ref={draggableRef}
style={draggableStyle}
{...draggableListeners}
{...draggableAttributes}
data-testid={`critical-task-${task.id}`}
sx={{
border: 1,
borderColor: 'divider',
borderRadius: 1,
mb: 1,
flexDirection: 'column',
alignItems: 'stretch',
bgcolor: 'background.paper',
...sx,
}}
>
{/* Task Header */}
<Stack direction="row" justifyContent="space-between" alignItems="start" width="100%">
<Typography variant="subtitle2" fontWeight="bold">
{task.taskName}
</Typography>
<Stack direction="row" spacing={0}>
{onEdit && (
<Tooltip title={t('tasks.editTask', 'Edit task')}>
<IconButton
size="small"
onClick={(e) => {
e.stopPropagation();
onEdit(task);
}}
aria-label={t('tasks.editTask', 'Edit task')}
>
<EditIcon fontSize="small" />
</IconButton>
</Tooltip>
)}
{onDelete && (
<Tooltip title={t('tasks.deleteTask', 'Delete task')}>
<IconButton
size="small"
color="error"
onClick={(e) => {
e.stopPropagation();
onDelete(task);
}}
aria-label={t('tasks.deleteTask', 'Delete task')}
>
<DeleteIcon fontSize="small" />
</IconButton>
</Tooltip>
)}
{showCompleteButton && onComplete && task.status !== 'completed' && (
<Tooltip title={t('tasks.markComplete', 'Mark complete')}>
<IconButton
size="small"
onClick={(e) => {
e.stopPropagation();
onComplete(task.id);
}}
aria-label={t('tasks.markComplete', 'Mark complete')}
>
<CheckCircleIcon fontSize="small" />
</IconButton>
</Tooltip>
)}
</Stack>
</Stack>
{/* Task Details */}
<ListItemText
secondaryTypographyProps={{ component: 'div' }}
secondary={
<Stack spacing={0.5} mt={1}>
{/* Event Code */}
{showEventCode && task.eventCode && (
<Chip
label={task.eventCode}
size="small"
color="primary"
sx={{ fontSize: '0.7rem', height: 22, width: 'fit-content', fontWeight: 'bold' }}
/>
)}
{/* Due Date and Assignee */}
{(formattedDueDate || task.assignedOrganizerUsername) && (
<Stack direction="row" spacing={2} flexWrap="wrap">
{formattedDueDate && (
<Typography variant="caption" color="text.secondary">
{t('tasks.due', 'Due')}: {formattedDueDate}
</Typography>
)}
<OrganizerChip
username={task.assignedOrganizerUsername}
data-testid={`task-assignee-${task.id}`}
/>
</Stack>
)}
{/* Trigger State */}
{showTriggerState && task.triggerState && (
<Chip
label={tWorkflowState(
`tasks.workflowStates.${task.triggerState}`,
task.triggerState
)}
size="small"
variant="outlined"
sx={{ fontSize: '0.65rem', height: 20, mt: 0.5, width: 'fit-content' }}
/>
)}
{/* Completion Info */}
{showCompletionInfo && task.status === 'completed' && (
<>
{formattedCompletedDate && (
<Typography variant="caption" color="success.main">
{t('tasks.completedOn', 'Completed on')}: {formattedCompletedDate}
</Typography>
)}
{task.completedByUsername && (
<Typography variant="caption" color="text.secondary">
{t('tasks.completedBy', 'Completed by')}: {task.completedByUsername}
</Typography>
)}
</>
)}
{/* Notes */}
{task.notes && (
<Typography variant="caption" color="text.secondary" sx={{ fontStyle: 'italic' }}>
{task.notes}
</Typography>
)}
</Stack>
}
/>
</ListItem>
);
};
|