mirror of
https://git.um-react.app/um/um-react.git
synced 2026-11-27 23:56:59 +00:00
feat: friendly way to inform user there's an error (#12)
This commit is contained in:
1 parent
4aff3b7a07
commit
52d86e4601
8 files changed
+99
-19
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { chakra, Box, Button, Collapse, Text, useDisclosure } from '@chakra-ui/react';
|
||||
import { DecryptErrorType } from '~/decrypt-worker/util/DecryptError';
|
||||
|
||||
export interface FileErrorProps {
|
||||
error: null | string;
|
||||
code: null | string;
|
||||
}
|
||||
|
||||
const errorMap = new Map<string | null | DecryptErrorType, string>([
|
||||
[DecryptErrorType.UNSUPPORTED_FILE, '尚未支持的文件格式'],
|
||||
]);
|
||||
|
||||
export function FileError({ error, code }: FileErrorProps) {
|
||||
const { isOpen, onToggle } = useDisclosure();
|
||||
const errorSummary = errorMap.get(code) ?? '未知错误';
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Text>
|
||||
<chakra.span>解密错误:{errorSummary}</chakra.span>
|
||||
{error && (
|
||||
<Button ml="2" onClick={onToggle} type="button">
|
||||
详细
|
||||
</Button>
|
||||
)}
|
||||
</Text>
|
||||
{error && (
|
||||
<Collapse in={isOpen} animateOpacity>
|
||||
<Box as="pre" display="inline-block" mt="2" px="4" py="2" bg="red.300" rounded="md">
|
||||
{error}
|
||||
</Box>
|
||||
</Collapse>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user