import { useEffect, useMemo } from 'react';
import { CopyFeedbackButton } from '../common/CopyFeedbackButton';
import { PlatformInfoBlock } from '../common/PlatformInfoBlock';
import { UnifiedModal } from '../common/UnifiedModal';
import { useCopyFeedback } from '../common/useCopyFeedback';
export type PlatformErrorDialogPayload = {
source: string;
message: string;
};
type PlatformErrorDialogProps = {
error: PlatformErrorDialogPayload | null;
onClose: () => void;
overlayClassName?: string;
panelClassName?: string;
};
function buildPlatformErrorReport(error: PlatformErrorDialogPayload) {
return [`来源:${error.source}`, `错误:${error.message}`].join('\n');
}
function isBlacklistedPlatformError(error: PlatformErrorDialogPayload | null) {
// 中文注释:入口关闭是平台开关状态,不作为全局错误弹窗打扰用户。
return Boolean(error?.message.includes('creation_entry_disabled'));
}
export function PlatformErrorDialog({
error,
onClose,
overlayClassName = 'platform-theme platform-theme--light !items-center',
panelClassName = 'platform-remap-surface rounded-[1.5rem]',
}: PlatformErrorDialogProps) {
const { copyState, copyText, resetCopyState } = useCopyFeedback();
const dialogError = isBlacklistedPlatformError(error) ? null : error;
const reportText = useMemo(
() => (dialogError ? buildPlatformErrorReport(dialogError) : ''),
[dialogError],
);
useEffect(() => {
resetCopyState();
}, [dialogError?.source, dialogError?.message, resetCopyState]);
const copyError = () => {
if (!reportText) {
return;
}
void copyText(reportText);
};
return (
}
>
{dialogError ? (
<>
{dialogError.source}
{dialogError.message}
>
) : null}
);
}