import { useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useTranslation } from 'react-i18next'; import { selectUploadTasks, dismissUploadTask } from '../upload/uploadSlice'; import ChevronDown from '../assets/chevron-down.svg'; import CheckCircleFilled from '../assets/check-circle-filled.svg'; import WarnIcon from '../assets/warn.svg'; const PROGRESS_RADIUS = 10; const PROGRESS_CIRCUMFERENCE = 2 * Math.PI * PROGRESS_RADIUS; export default function UploadToast() { const [collapsedTasks, setCollapsedTasks] = useState>( {}, ); const toggleTaskCollapse = (taskId: string) => { setCollapsedTasks((prev) => ({ ...prev, [taskId]: !prev[taskId], })); }; const { t } = useTranslation(); const dispatch = useDispatch(); const uploadTasks = useSelector(selectUploadTasks); const getStatusHeading = (status: string) => { switch (status) { case 'preparing': return t('modals.uploadDoc.progress.wait'); case 'uploading': return t('modals.uploadDoc.progress.upload'); case 'training': return t('modals.uploadDoc.progress.upload'); case 'completed': return t('modals.uploadDoc.progress.completed'); case 'failed': return t('attachments.uploadFailed'); default: return t('modals.uploadDoc.progress.preparing'); } }; return (
{uploadTasks .filter((task) => !task.dismissed) .map((task) => { const shouldShowProgress = [ 'preparing', 'uploading', 'training', ].includes(task.status); const rawProgress = Math.min(Math.max(task.progress ?? 0, 0), 100); const formattedProgress = Math.round(rawProgress); const progressOffset = PROGRESS_CIRCUMFERENCE * (1 - rawProgress / 100); const isCollapsed = collapsedTasks[task.id] ?? false; return (

{getStatusHeading(task.status)}

{task.fileName}

{shouldShowProgress && ( )} {task.status === 'completed' && ( )} {task.status === 'failed' && ( )}
{task.status === 'failed' && task.errorMessage && ( {task.errorMessage} )}
); })}
); }