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 | 3x 3x 223x 223x 223x 223x 223x 44x 19x 19x 223x 168x 168x 168x 4x 164x 223x 4x 4x 4x 4x 223x 3x 3x 3x 223x 223x 223x 223x 223x 223x 223x | /**
* Status Change Dialog Component (Story 5.4 + Story 11.D.4 AC5).
*
* Modal dialog for confirming speaker status changes.
* Features:
* - Optional reason field (max 2000 characters), REQUIRED when `newStatus === 'DECLINED'`.
* - Confirmation and cancel buttons
* - i18n support (10 locales)
* - Validation for reason length
*
* Story 11.D.4 — When the kanban dispatcher classifies a drop as `legal-decline`, this
* dialog opens with `newStatus='DECLINED'` and the confirm button stays disabled until
* `reason.trim().length > 0`. Otherwise (drawer "Override state" popover with a
* non-DECLINED target, or legacy callers), reason remains optional.
*/
import React, { useEffect, useState } from 'react';
import {
Dialog,
DialogTitle,
DialogContent,
DialogActions,
TextField,
Button,
Typography,
} from '@mui/material';
import { useTranslation } from 'react-i18next';
import { useBreakpoints } from '@/hooks/useBreakpoints';
import type { SpeakerWorkflowState } from '@/types/speakerPool.types';
export interface StatusChangeDialogProps {
open: boolean;
speakerName: string;
currentStatus: SpeakerWorkflowState;
newStatus: SpeakerWorkflowState;
onConfirm: (reason?: string) => void;
onCancel: () => void;
}
const MAX_REASON_LENGTH = 2000;
export const StatusChangeDialog: React.FC<StatusChangeDialogProps> = ({
open,
speakerName,
currentStatus,
newStatus,
onConfirm,
onCancel,
}) => {
const { t } = useTranslation(['organizer', 'common']);
const { isMobile } = useBreakpoints();
const [reason, setReason] = useState('');
const [error, setError] = useState('');
// Review patch — clear reason + error when the dialog closes externally (e.g. the
// drawer that hosts this always-mounted dialog is closed via Esc/onClose without
// confirming or cancelling). Without this, opening the dialog for a different
// speaker after such a close shows the previous speaker's reason text.
useEffect(() => {
if (!open) {
setReason('');
setError('');
}
}, [open]);
const handleReasonChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const value = event.target.value;
setReason(value);
if (value.length > MAX_REASON_LENGTH) {
setError(
t('organizer:speakerStatus.reasonTooLong', {
current: value.length,
max: MAX_REASON_LENGTH,
})
);
} else {
setError('');
}
};
const handleConfirm = () => {
Iif (error) return;
onConfirm(reason.trim() || undefined);
setReason('');
setError('');
};
const handleCancel = () => {
setReason('');
setError('');
onCancel();
};
// Story 11.D.4 AC5 — required-reason guard for DECLINED.
// 2026-05-20 — also required for READY → ACCEPTED (organizer-on-behalf path).
const isDeclining = newStatus === 'DECLINED';
const isOnBehalfAccept = currentStatus === 'READY' && newStatus === 'ACCEPTED';
const reasonRequired = isDeclining || isOnBehalfAccept;
const reasonMissing = reasonRequired && reason.trim().length === 0;
const confirmDisabled = !!error || reasonMissing;
const dialogTitle = isDeclining
? t('organizer:kanbanDrag.declineDialog.title', { speakerName })
: isOnBehalfAccept
? t('organizer:kanbanDrag.acceptOnBehalfDialog.title', {
speakerName,
defaultValue: 'Accept {{speakerName}} on behalf',
})
: t('organizer:speakerStatus.changeStatus');
return (
<Dialog
open={open}
onClose={handleCancel}
maxWidth="sm"
fullWidth
fullScreen={isMobile}
data-testid="status-change-dialog"
>
<DialogTitle>{dialogTitle}</DialogTitle>
<DialogContent>
<Typography variant="body2" sx={{ mb: 2 }}>
{t('organizer:speakerStatus.confirmChangeMessage', {
speaker: speakerName,
from: t(`organizer:speakerStatus.${currentStatus}`),
to: t(`organizer:speakerStatus.${newStatus}`),
})}
</Typography>
<TextField
fullWidth
multiline
rows={4}
required={reasonRequired}
label={t('organizer:speakerStatus.changeReason')}
value={reason}
onChange={handleReasonChange}
error={!!error}
helperText={
error ||
(isDeclining
? t('organizer:kanbanDrag.declineDialog.reasonHint')
: isOnBehalfAccept
? t('organizer:kanbanDrag.acceptOnBehalfDialog.reasonHint', {
defaultValue:
'Record why you are accepting on behalf (e.g. "confirmed by email 2026-05-18"). Lands in the audit trail.',
})
: t('organizer:speakerStatus.reasonHelperText', { max: MAX_REASON_LENGTH }))
}
placeholder={t('organizer:speakerStatus.reasonPlaceholder')}
data-testid="status-change-reason"
/>
</DialogContent>
<DialogActions>
<Button onClick={handleCancel} color="secondary" data-testid="status-change-cancel">
{t('common:actions.cancel')}
</Button>
<Button
onClick={handleConfirm}
variant="contained"
color="primary"
disabled={confirmDisabled}
data-testid="status-change-confirm"
>
{t('organizer:speakerStatus.confirmChange')}
</Button>
</DialogActions>
</Dialog>
);
};
export default StatusChangeDialog;
|