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 | 1x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 1x 1x 1x 1x 1x 32x 1x 1x 11x 8x 62x 62x 62x 2x 32x 32x | /**
* Speaker Brainstorming Panel Component (Story 5.2 - AC9-13)
*
* Speaker pool management during event planning:
* - Add potential speakers (name, company, expertise)
* - Assign speakers to organizers for outreach
* - Add notes for each speaker
* - View speaker pool list
* - Initial status: IDENTIFIED
*/
import React, { useState } from 'react';
import {
Paper,
Typography,
Box,
TextField,
Button,
List,
ListItem,
ListItemText,
Chip,
Alert,
Divider,
} from '@mui/material';
import { Add as AddIcon } from '@mui/icons-material';
import { useTranslation } from 'react-i18next';
import { BATbernLoader } from '@components/shared/BATbernLoader';
import { useSpeakerPool, useAddSpeakerToPool } from '@/hooks/useSpeakerPool';
import type { AddSpeakerToPoolRequest, SpeakerPoolEntry } from '@/types/speakerPool.types';
import { OrganizerSelect } from '@/components/shared/OrganizerSelect';
import { PromoteSpeakerDialog } from './PromoteSpeakerDialog';
export interface SpeakerBrainstormingPanelProps {
eventCode: string;
organizers?: Array<{ id: string; name: string }>; // List of available organizers
onContinue?: () => void; // Callback when workflow should continue
showPoolList?: boolean; // Whether to show the speaker pool list (default: true)
showHeader?: boolean; // Whether to show Paper wrapper and header (default: true)
}
export const SpeakerBrainstormingPanel: React.FC<SpeakerBrainstormingPanelProps> = ({
eventCode,
organizers = [],
onContinue,
showPoolList = true,
showHeader = true,
}) => {
const { t } = useTranslation('organizer');
// Form state
const [speakerName, setSpeakerName] = useState('');
const [company, setCompany] = useState('');
const [expertise, setExpertise] = useState('');
const [assignedOrganizerId, setAssignedOrganizerId] = useState<string>('');
const [notes, setNotes] = useState('');
// Story 11.D.1 — Promote modal state
const [promoteSpeaker, setPromoteSpeaker] = useState<SpeakerPoolEntry | null>(null);
// Fetch speaker pool
const { data: speakerPool, isLoading, isError } = useSpeakerPool(eventCode);
// Mutation for adding speaker
const addSpeakerMutation = useAddSpeakerToPool();
const handleAddSpeaker = () => {
Iif (!speakerName.trim()) {
return;
}
console.log('Form state:', {
speakerName,
company,
expertise,
assignedOrganizerId,
notes,
});
const request: AddSpeakerToPoolRequest = {
speakerName: speakerName.trim(),
company: company.trim() || undefined,
expertise: expertise.trim() || undefined,
assignedOrganizerId: assignedOrganizerId || undefined,
notes: notes.trim() || undefined,
};
console.log('Request payload:', request);
addSpeakerMutation.mutate(
{ eventCode, request },
{
onSuccess: () => {
// Clear form on success
setSpeakerName('');
setCompany('');
setExpertise('');
setAssignedOrganizerId('');
setNotes('');
},
}
);
};
const formContent = (
<>
{/* Add Speaker Form */}
<Box
component="form"
sx={{ display: 'flex', flexDirection: 'column', gap: 2, mb: 3 }}
onSubmit={(e) => {
e.preventDefault();
handleAddSpeaker();
}}
>
<TextField
required
fullWidth
size="small"
label={t('speakerBrainstorm.form.speakerName', 'Speaker Name')}
value={speakerName}
onChange={(e) => setSpeakerName(e.target.value)}
disabled={addSpeakerMutation.isPending}
inputProps={{ 'data-testid': 'speaker-name-field' }}
/>
<TextField
fullWidth
size="small"
label={t('speakerBrainstorm.form.company', 'Company')}
value={company}
onChange={(e) => setCompany(e.target.value)}
disabled={addSpeakerMutation.isPending}
inputProps={{ 'data-testid': 'speaker-company-field' }}
/>
<TextField
fullWidth
size="small"
label={t('speakerBrainstorm.form.expertise', 'Expertise')}
value={expertise}
onChange={(e) => setExpertise(e.target.value)}
disabled={addSpeakerMutation.isPending}
inputProps={{ 'data-testid': 'speaker-expertise-field' }}
/>
<OrganizerSelect
value={assignedOrganizerId}
onChange={(organizerId) => setAssignedOrganizerId(organizerId)}
organizers={organizers.length > 0 ? organizers : undefined}
label={t('speakerBrainstorm.form.assignOrganizer', 'Assign to Organizer (Optional)')}
size="small"
fullWidth
disabled={addSpeakerMutation.isPending}
includeUnassigned={true}
includeAllOption={false}
data-testid="speaker-organizer-select"
/>
<TextField
fullWidth
multiline
rows={2}
size="small"
label={t('speakerBrainstorm.form.notes', 'Notes (Optional)')}
value={notes}
onChange={(e) => setNotes(e.target.value)}
disabled={addSpeakerMutation.isPending}
inputProps={{ 'data-testid': 'speaker-notes-field' }}
/>
<Button
type="submit"
variant="contained"
color="primary"
startIcon={<AddIcon />}
disabled={!speakerName.trim() || addSpeakerMutation.isPending}
data-testid="add-to-pool-button"
>
{addSpeakerMutation.isPending
? t('speakerBrainstorm.form.adding', 'Adding...')
: t('speakerBrainstorm.form.addButton', 'Add to Pool')}
</Button>
{addSpeakerMutation.isError && (
<Alert severity="error">
{t('speakerBrainstorm.form.error', 'Failed to add speaker')}:{' '}
{addSpeakerMutation.error?.message}
</Alert>
)}
</Box>
{showPoolList && (
<>
<Divider sx={{ my: 2 }} />
{/* Speaker Pool List */}
<Typography variant="subtitle1" gutterBottom>
{t('speakerBrainstorm.pool.title', 'Speaker Pool')} ({speakerPool?.length || 0})
</Typography>
{isLoading && (
<Box display="flex" justifyContent="center" alignItems="center" minHeight={100}>
<BATbernLoader size={96} />
</Box>
)}
{isError && (
<Alert severity="error">
{t('speakerBrainstorm.pool.error', 'Failed to load speaker pool')}
</Alert>
)}
{speakerPool && speakerPool.length === 0 && (
<Typography variant="body2" color="text.secondary" sx={{ textAlign: 'center', py: 2 }}>
{t('speakerBrainstorm.pool.empty', 'No speakers in pool yet. Add some above!')}
</Typography>
)}
{speakerPool && speakerPool.length > 0 && (
<List>
{speakerPool.map((speaker) => {
// Story 11.D.1: status values flow through unchanged from the API
// (UPPER_CASE on the wire, normalised here). Promote button shows on
// CONTACTED only — IDENTIFIED still needs outreach; READY+ is past
// this gate.
const statusUpper = (speaker.status ?? '').toString().toUpperCase();
const isContacted = statusUpper === 'CONTACTED';
return (
<ListItem
key={speaker.id}
sx={{
border: 1,
borderColor: 'divider',
borderRadius: 1,
mb: 1,
}}
secondaryAction={
isContacted ? (
<Button
variant="contained"
color="primary"
size="small"
onClick={() => setPromoteSpeaker(speaker)}
data-testid={`promote-button-${speaker.id}`}
>
{t('speakerBrainstorm.actions.promoteToSpeaker', 'Promote to speaker')}
</Button>
) : null
}
>
<ListItemText
primary={
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<Typography variant="subtitle2">{speaker.speakerName}</Typography>
{speaker.status && (
<Chip
label={speaker.status}
size="small"
color={statusUpper === 'IDENTIFIED' ? 'default' : 'primary'}
/>
)}
</Box>
}
secondary={
<>
{speaker.company && (
<Typography component="span" variant="body2" color="text.secondary">
{speaker.company}
</Typography>
)}
{speaker.expertise && (
<>
<br />
<Typography component="span" variant="body2" color="text.secondary">
{t('speakerBrainstorm.pool.expertise', 'Expertise')}:{' '}
{speaker.expertise}
</Typography>
</>
)}
{speaker.assignedOrganizerId && (
<>
<br />
<Typography component="span" variant="body2" color="text.secondary">
{t('speakerBrainstorm.pool.assigned', 'Assigned to')}:{' '}
{organizers.find((o) => o.id === speaker.assignedOrganizerId)
?.name || speaker.assignedOrganizerId}
</Typography>
</>
)}
{speaker.notes && (
<>
<br />
<Typography component="span" variant="body2" color="text.secondary">
{t('common:labels.notes')}: {speaker.notes}
</Typography>
</>
)}
</>
}
/>
</ListItem>
);
})}
</List>
)}
{promoteSpeaker && (
<PromoteSpeakerDialog
key={promoteSpeaker.id}
open={true}
eventCode={eventCode}
speaker={promoteSpeaker}
onClose={() => setPromoteSpeaker(null)}
/>
)}
</>
)}
{/* Action Buttons */}
{onContinue && (
<Box sx={{ mt: 3, display: 'flex', gap: 2, justifyContent: 'flex-end' }}>
<Button variant="outlined" onClick={() => onContinue()} data-testid="skip-for-now-button">
{t('speakerBrainstorm.actions.skipForNow', 'Skip for Now')}
</Button>
<Button
variant="contained"
onClick={() => onContinue()}
disabled={!speakerPool || speakerPool.length === 0}
data-testid="proceed-to-outreach-button"
>
{t('speakerBrainstorm.actions.continue', 'Continue to Outreach')}
</Button>
</Box>
)}
</>
);
Iif (!showHeader) {
return formContent;
}
return (
<Paper sx={{ p: 3 }}>
<Typography variant="h6" gutterBottom>
{t('speakerBrainstorm.title', 'Speaker Brainstorming')}
</Typography>
<Typography variant="body2" color="text.secondary" paragraph>
{t(
'speakerBrainstorm.subtitle',
'Add potential speakers to the event pool and assign them to organizers for outreach'
)}
</Typography>
{formContent}
</Paper>
);
};
export default SpeakerBrainstormingPanel;
|