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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | 3x 8x 8x 3x 3x 3x 3x 3x 3x 52x 36x 36x 36x 30x 3x 12x 12x 12x 12x 3x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 48x 26x 26x 26x 26x 26x 26x 26x 18x 18x 18x 18x 18x 8x 26x 26x 26x 26x 26x 122x 9x 9x 9x 9x 1x 9x 1x 9x 9x 7x 7x 7x 7x 7x 1x 7x 7x 1x 7x 9x 9x 122x 9x 3x 6x 6x 6x 6x 9x 6x 6x 6x 3x 3x 3x 3x 3x 3x 3x 1x 1x 3x 1x 1x 3x 6x 122x 122x 122x 6x 122x 2x 2x 2x 2x 2x 1x 1x 1x 2x 122x 10x 10x 10x 5x 5x 5x 5x 5x 5x 5x 122x 3x 3x 3x 2x 2x 2x 2x 2x 2x 2x 122x 6x 6x 122x 24x 98x 1x 1x 1x 1x 3x 10x 6x 8x 2x | /**
* SessionEditModal Component
*
* Modal for editing session details (title, abstract, duration)
* Features:
* - Edit session title (required)
* - Edit session abstract (optional, max 1000 chars)
* - Edit session duration in minutes
* - Form validation
* - i18n support (German/English)
*/
import React, { useState, useEffect } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import {
Dialog,
DialogTitle,
DialogContent,
DialogActions,
TextField,
Button,
Box,
Typography,
Alert,
CircularProgress,
Tabs,
Tab,
List,
ListItem,
ListItemText,
ListItemIcon,
ListItemSecondaryAction,
IconButton,
Link,
useMediaQuery,
useTheme,
} from '@mui/material';
import DownloadIcon from '@mui/icons-material/Download';
import DeleteIcon from '@mui/icons-material/Delete';
import {
Description as DescriptionIcon,
PictureAsPdf as PdfIcon,
VideoLibrary as VideoIcon,
Slideshow as PresentationIcon,
} from '@mui/icons-material';
import { useTranslation } from 'react-i18next';
import { AxiosError } from 'axios';
import type { SessionUI, SessionMaterial } from '@/types/event.types';
import { FileUpload, type UploadedFile } from '@/components/shared/FileUpload/FileUpload';
import { sessionApiClient } from '@/services/api/sessionApiClient';
import { SessionSpeakersTab } from './SessionSpeakersTab';
// Helper function to get file type icon based on mime type
const getFileTypeIcon = (mimeType: string | undefined): React.ReactNode => {
Eif (!mimeType) {
return <DescriptionIcon />;
}
if (
mimeType.startsWith('application/vnd.openxmlformats-officedocument.presentationml') ||
mimeType.startsWith('application/vnd.ms-powerpoint')
) {
return <PresentationIcon />;
}
if (mimeType === 'application/pdf') {
return <PdfIcon />;
}
if (mimeType.startsWith('video/')) {
return <VideoIcon />;
}
return <DescriptionIcon />;
};
interface SessionEditModalProps {
open: boolean;
onClose: () => void;
session: SessionUI | null;
eventDate: string; // ISO 8601 date for time conversion
onSave: (sessionSlug: string, updates: SessionUpdateData) => Promise<void>;
initialTab?: number; // 0 = Details (default), 1 = Materials, 2 = Speakers
}
export interface SessionUpdateData {
title: string;
description?: string;
durationMinutes?: number;
startTime?: string; // ISO 8601 timestamp
endTime?: string; // ISO 8601 timestamp
}
interface SpeakerConflict {
speakerName: string;
sessionTitle: string;
startTime: string;
endTime: string;
}
interface RoomConflict {
roomName: string;
sessionTitle: string;
startTime: string;
endTime: string;
}
const MAX_ABSTRACT_LENGTH = 1000;
const MIN_SESSION_DURATION = 15; // minutes
const MAX_SESSION_DURATION = 480; // 8 hours
// Helper: Map MIME type to material type enum
const getMaterialTypeFromMimeType = (mimeType: string): string => {
if (mimeType.startsWith('video/')) {
return 'VIDEO';
} else if (
mimeType.includes('powerpoint') ||
mimeType.includes('presentation') ||
mimeType.includes('keynote')
) {
return 'PRESENTATION';
} else if (
mimeType === 'application/pdf' ||
mimeType.includes('document') ||
mimeType === 'text/plain'
) {
return 'DOCUMENT';
} else if (mimeType.includes('zip') || mimeType.includes('gzip') || mimeType.includes('tar')) {
return 'ARCHIVE';
} else {
return 'OTHER';
}
};
// Helper: Extract file extension from filename (without dot)
const getFileExtension = (fileName: string): string => {
const lastDot = fileName.lastIndexOf('.');
if (lastDot === -1) return '';
return fileName.substring(lastDot + 1).toLowerCase();
};
// Extract HH:mm from ISO 8601 timestamp
const extractTimeFromISO = (isoString: string | null | undefined): string => {
if (!isoString) return '';
try {
const date = new Date(isoString);
if (isNaN(date.getTime())) return '';
return date.toTimeString().substring(0, 5); // "14:30"
} catch {
return '';
}
};
// Combine event date + HH:mm time → ISO 8601 timestamp
const combineEventDateAndTime = (eventDate: string, timeString: string): string => {
const date = new Date(eventDate);
const [hours, minutes] = timeString.split(':').map(Number);
date.setHours(hours, minutes, 0, 0);
return date.toISOString();
};
export const SessionEditModal: React.FC<SessionEditModalProps> = ({
open,
onClose,
session,
eventDate,
onSave,
initialTab = 0,
}) => {
const { t } = useTranslation('events');
const queryClient = useQueryClient();
const theme = useTheme();
// Phones / small tablets get a full-screen dialog; otherwise centered md width.
const isFullScreen = useMediaQuery(theme.breakpoints.down('md'));
const [title, setTitle] = useState('');
const [abstract, setAbstract] = useState('');
const [duration, setDuration] = useState<number>(60); // Default 60 minutes
const [startTime, setStartTime] = useState<string>(''); // HH:mm format
const [endTime, setEndTime] = useState<string>(''); // HH:mm format
const [errors, setErrors] = useState<{
title?: string;
abstract?: string;
duration?: string;
startTime?: string;
endTime?: string;
}>({});
const [saving, setSaving] = useState(false);
const [saveError, setSaveError] = useState<string | null>(null);
// Story 5.9: Materials tab state
const [activeTab, setActiveTab] = useState<number>(initialTab); // 0 = Details, 1 = Materials
const [uploadedMaterials, setUploadedMaterials] = useState<UploadedFile[]>([]);
const [existingMaterials, setExistingMaterials] = useState<SessionMaterial[]>([]);
const [deletingMaterialId, setDeletingMaterialId] = useState<string | null>(null);
const [deleteMaterialError, setDeleteMaterialError] = useState<string | null>(null);
// Initialize form when session changes
useEffect(() => {
if (session) {
setTitle(session.title || '');
setAbstract(session.description || '');
// Extract times from session
const extractedStartTime = extractTimeFromISO(session.startTime);
const extractedEndTime = extractTimeFromISO(session.endTime);
setStartTime(extractedStartTime);
setEndTime(extractedEndTime);
// Calculate duration from startTime and endTime if available
if (session.startTime && session.endTime) {
const start = new Date(session.startTime);
const end = new Date(session.endTime);
const durationMs = end.getTime() - start.getTime();
const durationMin = Math.round(durationMs / (1000 * 60));
setDuration(durationMin || 60);
} else {
setDuration(60);
}
setErrors({});
setSaveError(null);
// Story 5.9: Initialize materials from session
setExistingMaterials(session.materials || []);
setUploadedMaterials([]);
setActiveTab(initialTab); // Use initialTab prop (AC2: Materials button opens Materials tab)
}
}, [session, initialTab]);
const validateForm = (): boolean => {
const newErrors: typeof errors = {};
const isStructural = ['moderation', 'break', 'lunch', 'aperitif'].includes(
session?.sessionType ?? ''
);
const minDuration = isStructural ? 1 : MIN_SESSION_DURATION;
if (!title.trim()) {
newErrors.title = t('sessionEdit.errors.titleRequired', 'Title is required');
}
if (abstract.length > MAX_ABSTRACT_LENGTH) {
newErrors.abstract = t('sessionEdit.errors.abstractTooLong', {
max: MAX_ABSTRACT_LENGTH,
defaultValue: `Abstract must be ${MAX_ABSTRACT_LENGTH} characters or less`,
});
}
Iif (duration < minDuration || duration > MAX_SESSION_DURATION) {
newErrors.duration = t('sessionEdit.errors.invalidDuration', {
min: minDuration,
max: MAX_SESSION_DURATION,
defaultValue: `Duration must be between ${minDuration} and ${MAX_SESSION_DURATION} minutes`,
});
}
// Time validation (if times are provided)
if (startTime && endTime) {
const [startHours, startMinutes] = startTime.split(':').map(Number);
const [endHours, endMinutes] = endTime.split(':').map(Number);
const startTotalMinutes = startHours * 60 + startMinutes;
const endTotalMinutes = endHours * 60 + endMinutes;
if (endTotalMinutes <= startTotalMinutes) {
newErrors.endTime = t('sessionEdit.errors.endTimeBeforeStart', {
defaultValue: 'End time must be after start time',
});
}
const calculatedDuration = endTotalMinutes - startTotalMinutes;
if (calculatedDuration < minDuration) {
newErrors.duration = t('sessionEdit.errors.durationTooShort', {
min: minDuration,
defaultValue: `Session duration must be at least ${minDuration} minutes`,
});
}
Iif (calculatedDuration > MAX_SESSION_DURATION) {
newErrors.duration = t('sessionEdit.errors.durationTooLong', {
max: MAX_SESSION_DURATION,
defaultValue: `Session duration must be at most ${MAX_SESSION_DURATION} minutes`,
});
}
}
setErrors(newErrors);
return Object.keys(newErrors).length === 0;
};
const handleSave = async () => {
if (!session || !validateForm()) {
return;
}
setSaving(true);
setSaveError(null);
try {
const updates: SessionUpdateData = {
title: title.trim(),
description: abstract.trim() || undefined,
durationMinutes: duration,
};
// Include time updates if times are set
if (startTime && endTime) {
updates.startTime = combineEventDateAndTime(eventDate, startTime);
updates.endTime = combineEventDateAndTime(eventDate, endTime);
}
await onSave(session.sessionSlug, updates);
// Story 5.9: Save uploaded materials if any
Iif (uploadedMaterials.length > 0) {
const materials = uploadedMaterials.map((file) => ({
uploadId: file.uploadId,
materialType: getMaterialTypeFromMimeType(file.fileType),
fileName: file.fileName,
fileExtension: getFileExtension(file.fileName),
fileSize: file.fileSize,
mimeType: file.fileType,
}));
await sessionApiClient.associateMaterials(session.eventCode, session.sessionSlug, {
materials,
});
// Invalidate event cache to reload sessions with new materials
queryClient.invalidateQueries({ queryKey: ['event', session.eventCode] });
}
// Clear uploaded materials after successful save
setUploadedMaterials([]);
onClose();
} catch (error) {
// Handle 409 conflict errors (speaker/room conflicts)
if (error instanceof AxiosError && error.response?.status === 409) {
const conflictData = error.response.data;
const conflictMessages: string[] = [];
if (conflictData.speakerConflicts && conflictData.speakerConflicts.length > 0) {
conflictData.speakerConflicts.forEach((conflict: SpeakerConflict) => {
conflictMessages.push(
t('sessionEdit.errors.speakerConflict', {
speaker: conflict.speakerName,
session: conflict.sessionTitle,
time: `${conflict.startTime} - ${conflict.endTime}`,
defaultValue: `Speaker ${conflict.speakerName} is already scheduled for "${conflict.sessionTitle}" at ${conflict.startTime} - ${conflict.endTime}`,
})
);
});
}
if (conflictData.roomConflicts && conflictData.roomConflicts.length > 0) {
conflictData.roomConflicts.forEach((conflict: RoomConflict) => {
conflictMessages.push(
t('sessionEdit.errors.roomConflict', {
room: conflict.roomName,
session: conflict.sessionTitle,
time: `${conflict.startTime} - ${conflict.endTime}`,
defaultValue: `Room ${conflict.roomName} is already booked for "${conflict.sessionTitle}" at ${conflict.startTime} - ${conflict.endTime}`,
})
);
});
}
setSaveError(
conflictMessages.length > 0
? conflictMessages.join('\n')
: t('sessionEdit.errors.timingConflict', 'Timing conflict detected')
);
} else E{
setSaveError(
error instanceof Error
? error.message
: t('sessionEdit.errors.saveFailed', 'Failed to save session')
);
}
} finally {
setSaving(false);
}
};
const handleClose = () => {
if (!saving) {
onClose();
}
};
// Story 5.9: Materials tab handlers
const handleFileUploadSuccess = (data: {
uploadId: string;
tempFileUrl?: string;
fileName?: string;
fileSize?: number;
fileType?: string;
}) => {
const uploadedFile: UploadedFile = {
uploadId: data.uploadId,
fileName: data.fileName ?? 'Unknown',
fileSize: data.fileSize ?? 0,
fileType: data.fileType ?? 'application/octet-stream',
};
setUploadedMaterials((prev) => [...prev, uploadedFile]);
};
const handleTabChange = (_event: React.SyntheticEvent, newValue: number) => {
setActiveTab(newValue);
};
const handleDeleteMaterial = async (materialId: string) => {
Iif (!session) return;
setDeletingMaterialId(materialId);
setDeleteMaterialError(null);
try {
await sessionApiClient.deleteMaterial(session.eventCode, session.sessionSlug, materialId);
setExistingMaterials((prev) => prev.filter((m) => m.id !== materialId));
queryClient.invalidateQueries({ queryKey: ['event', session.eventCode] });
} catch (error) {
setDeleteMaterialError(
error instanceof Error
? error.message
: t('sessionEdit.materials.deleteError', 'Failed to delete material')
);
} finally {
setDeletingMaterialId(null);
}
};
// Auto-calculation handlers per AC2
const handleStartTimeChange = (newStartTime: string) => {
setStartTime(newStartTime);
Iif (errors.startTime) {
setErrors({ ...errors, startTime: undefined });
}
// Auto-recalculate endTime based on current duration
if (newStartTime && duration > 0) {
const [hours, minutes] = newStartTime.split(':').map(Number);
const startTotalMinutes = hours * 60 + minutes;
const endTotalMinutes = startTotalMinutes + duration;
const endHours = Math.floor(endTotalMinutes / 60) % 24;
const endMinutes = endTotalMinutes % 60;
const calculatedEndTime = `${String(endHours).padStart(2, '0')}:${String(endMinutes).padStart(2, '0')}`;
setEndTime(calculatedEndTime);
}
};
const handleDurationChange = (newDuration: number) => {
setDuration(newDuration);
Iif (errors.duration) {
setErrors({ ...errors, duration: undefined });
}
// Auto-recalculate endTime based on current startTime
if (startTime && newDuration > 0) {
const [hours, minutes] = startTime.split(':').map(Number);
const startTotalMinutes = hours * 60 + minutes;
const endTotalMinutes = startTotalMinutes + newDuration;
const endHours = Math.floor(endTotalMinutes / 60) % 24;
const endMinutes = endTotalMinutes % 60;
const calculatedEndTime = `${String(endHours).padStart(2, '0')}:${String(endMinutes).padStart(2, '0')}`;
setEndTime(calculatedEndTime);
}
};
const handleEndTimeChange = (newEndTime: string) => {
setEndTime(newEndTime);
Iif (errors.endTime) {
setErrors({ ...errors, endTime: undefined });
}
// Note: Duration does NOT auto-update when endTime is manually changed (per AC2)
};
if (!session) {
return null;
}
return (
<Dialog open={open} onClose={handleClose} maxWidth="md" fullWidth fullScreen={isFullScreen}>
<DialogTitle>{t('sessionEdit.title', 'Edit Session')}</DialogTitle>
{/* Story 5.9: Tabs for Details and Materials */}
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs
value={activeTab}
onChange={handleTabChange}
aria-label={t('sessionEdit.tabs.ariaLabel')}
>
<Tab label={t('sessionEdit.tabs.details', 'Details')} />
<Tab label={t('sessionEdit.tabs.materials', 'Materials')} />
<Tab label={t('common:navigation.speakers')} />
</Tabs>
</Box>
<DialogContent>
{/* Details Tab */}
{activeTab === 0 && (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, mt: 1 }}>
{/* Session Title */}
<TextField
label={t('sessionEdit.titleLabel', 'Session Title')}
value={title}
onChange={(e) => {
setTitle(e.target.value);
Iif (errors.title) {
setErrors({ ...errors, title: undefined });
}
}}
error={!!errors.title}
helperText={errors.title}
required
fullWidth
autoFocus
disabled={saving}
/>
{/* Session Abstract */}
<Box>
<TextField
label={t('sessionEdit.abstractLabel', 'Session Abstract')}
value={abstract}
onChange={(e) => {
setAbstract(e.target.value);
Iif (errors.abstract) {
setErrors({ ...errors, abstract: undefined });
}
}}
error={!!errors.abstract}
helperText={
errors.abstract ||
t('sessionEdit.charactersRemaining', {
count: MAX_ABSTRACT_LENGTH - abstract.length,
defaultValue: `{{count}} characters remaining`,
})
}
multiline
rows={6}
fullWidth
disabled={saving}
/>
<Typography variant="caption" color="text.secondary" sx={{ mt: 0.5 }}>
{abstract.length} / {MAX_ABSTRACT_LENGTH}{' '}
{t('qualityReview.characters', 'characters')}
</Typography>
</Box>
{/* Session Duration */}
<TextField
label={t('sessionEdit.durationLabel', 'Duration (minutes)')}
type="number"
value={duration}
onChange={(e) => handleDurationChange(Number(e.target.value))}
error={!!errors.duration}
helperText={errors.duration}
inputProps={{ step: 5 }}
fullWidth
disabled={saving}
/>
{/* Start Time */}
<TextField
label={t('sessionEdit.startTimeLabel', 'Start Time')}
type="time"
value={startTime}
onChange={(e) => handleStartTimeChange(e.target.value)}
error={!!errors.startTime}
helperText={errors.startTime}
fullWidth
disabled={saving}
InputLabelProps={{
shrink: true,
}}
/>
{/* End Time */}
<TextField
label={t('sessionEdit.endTimeLabel', 'End Time')}
type="time"
value={endTime}
onChange={(e) => handleEndTimeChange(e.target.value)}
error={!!errors.endTime}
helperText={errors.endTime}
fullWidth
disabled={saving}
InputLabelProps={{
shrink: true,
}}
/>
{/* Save Error */}
{saveError && (
<Alert severity="error" onClose={() => setSaveError(null)}>
{saveError}
</Alert>
)}
</Box>
)}
{/* Speakers Tab */}
{activeTab === 2 && <SessionSpeakersTab session={session} />}
{/* Materials Tab (Story 5.9) */}
{activeTab === 1 && (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, mt: 1 }}>
{/* File Upload Component */}
<Box>
<Typography variant="subtitle1" gutterBottom>
{t('sessionEdit.materials.uploadTitle', 'Upload Session Materials')}
</Typography>
<Typography variant="body2" color="text.secondary" gutterBottom>
{t(
'sessionEdit.materials.uploadDescription',
'Upload presentations, documents, or videos (max 100MB per file, up to 10 files)'
)}
</Typography>
<FileUpload
onUploadSuccess={handleFileUploadSuccess}
allowedTypes={[
// Presentations (AC6 - Story 5.9)
'application/vnd.ms-powerpoint', // .ppt
'application/vnd.openxmlformats-officedocument.presentationml.presentation', // .pptx
'application/vnd.apple.keynote', // .key
'application/vnd.oasis.opendocument.presentation', // .odp
// Documents (AC6 - Story 5.9)
'application/pdf', // .pdf
'application/msword', // .doc
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', // .docx
'text/plain', // .txt
// Videos (AC6 - Story 5.9)
'video/mp4', // .mp4
'video/quicktime', // .mov
'video/x-msvideo', // .avi
'video/x-matroska', // .mkv
'video/webm', // .webm
// Archives (AC6 - Story 5.9)
'application/zip', // .zip
'application/gzip', // .tar.gz
'application/x-gzip', // .tar.gz
'application/x-tar', // .tar
]}
maxFileSize={100 * 1024 * 1024} // 100MB
multiple={true}
maxFiles={10}
uploadedFiles={uploadedMaterials}
uploadEndpoint="/materials/presigned-url" // Story 5.9: Use materials endpoint
/>
</Box>
{/* Existing Materials List (Story 5.9: Only show after save & reopen) */}
{existingMaterials.length > 0 && (
<Box>
<Typography variant="subtitle2" gutterBottom>
{t('sessionEdit.materials.existingTitle', 'Existing Materials')}
</Typography>
{deleteMaterialError && (
<Alert
severity="error"
onClose={() => setDeleteMaterialError(null)}
sx={{ mb: 1 }}
>
{deleteMaterialError}
</Alert>
)}
<List dense>
{existingMaterials.map((material) => (
<ListItem key={material.id}>
<ListItemIcon>{getFileTypeIcon(material.mimeType)}</ListItemIcon>
<ListItemText
primary={
<Link
component="button"
onClick={async (e) => {
e.preventDefault();
try {
// Fetch presigned download URL
const response = await sessionApiClient.getMaterialDownloadUrl(
session!.eventCode,
session!.sessionSlug,
material.id
);
// Open in new tab
window.open(response.downloadUrl, '_blank', 'noopener,noreferrer');
} catch (error) {
console.error('Failed to get download URL:', error);
alert(
t(
'sessionEdit.materials.downloadError',
'Failed to download material'
)
);
}
}}
underline="hover"
sx={{
display: 'flex',
alignItems: 'center',
gap: 0.5,
cursor: 'pointer',
}}
>
{material.fileName}
<DownloadIcon fontSize="small" />
</Link>
}
secondary={`${(material.fileSize / 1024 / 1024).toFixed(2)} MB • ${material.materialType}`}
/>
<ListItemSecondaryAction>
<IconButton
edge="end"
aria-label={t('sessionEdit.materials.delete', 'Delete material')}
onClick={() => handleDeleteMaterial(material.id)}
disabled={deletingMaterialId === material.id}
size="small"
color="error"
>
{deletingMaterialId === material.id ? (
<CircularProgress size={18} />
) : (
<DeleteIcon fontSize="small" />
)}
</IconButton>
</ListItemSecondaryAction>
</ListItem>
))}
</List>
</Box>
)}
</Box>
)}
</DialogContent>
<DialogActions>
<Button onClick={handleClose} disabled={saving}>
{t('common:actions.cancel')}
</Button>
<Button
onClick={handleSave}
variant="contained"
disabled={saving}
startIcon={saving ? <CircularProgress size={20} /> : undefined}
>
{saving ? t('common:actions.saving') : t('common:actions.save')}
</Button>
</DialogActions>
</Dialog>
);
};
|