diff options
Diffstat (limited to 'packages/renderer/src/components/errorPage/CertificateDetails.tsx')
-rw-r--r-- | packages/renderer/src/components/errorPage/CertificateDetails.tsx | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/packages/renderer/src/components/errorPage/CertificateDetails.tsx b/packages/renderer/src/components/errorPage/CertificateDetails.tsx new file mode 100644 index 0000000..044cb5c --- /dev/null +++ b/packages/renderer/src/components/errorPage/CertificateDetails.tsx | |||
@@ -0,0 +1,92 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com> | ||
3 | * | ||
4 | * This file is part of Sophie. | ||
5 | * | ||
6 | * Sophie is free software: you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU Affero General Public License as | ||
8 | * published by the Free Software Foundation, version 3. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | * | ||
18 | * SPDX-License-Identifier: AGPL-3.0-only | ||
19 | */ | ||
20 | |||
21 | import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; | ||
22 | import WarningAmberIcon from '@mui/icons-material/WarningAmber'; | ||
23 | import Accordion from '@mui/material/Accordion'; | ||
24 | import AccordionDetails from '@mui/material/AccordionDetails'; | ||
25 | import AccordionSummary from '@mui/material/AccordionSummary'; | ||
26 | import Box from '@mui/material/Box'; | ||
27 | import Button from '@mui/material/Button'; | ||
28 | import Typography from '@mui/material/Typography'; | ||
29 | import { observer } from 'mobx-react-lite'; | ||
30 | import React from 'react'; | ||
31 | import { useTranslation } from 'react-i18next'; | ||
32 | |||
33 | import type Service from '../../stores/Service'; | ||
34 | |||
35 | const SUMMARY_ID = 'Sophie-CertificateDetails-header'; | ||
36 | const DETAILS_ID = 'Sophie-CertificateDetails-content'; | ||
37 | |||
38 | function CertificateDetails({ | ||
39 | service, | ||
40 | }: { | ||
41 | service: Service; | ||
42 | }): JSX.Element | null { | ||
43 | const { t } = useTranslation(undefined, { | ||
44 | keyPrefix: 'error.certificateError.details', | ||
45 | }); | ||
46 | |||
47 | const { state } = service; | ||
48 | const { type: errorType } = state; | ||
49 | |||
50 | if (errorType !== 'certificateError') { | ||
51 | // eslint-disable-next-line unicorn/no-null -- React requires `null` to skip rendering. | ||
52 | return null; | ||
53 | } | ||
54 | |||
55 | const { certificate, trust } = state; | ||
56 | |||
57 | return ( | ||
58 | <Accordion | ||
59 | disableGutters | ||
60 | variant="outlined" | ||
61 | sx={{ '&::before': { display: 'none' }, borderRadius: 1 }} | ||
62 | > | ||
63 | <AccordionSummary | ||
64 | id={SUMMARY_ID} | ||
65 | aria-controls={DETAILS_ID} | ||
66 | expandIcon={<ExpandMoreIcon />} | ||
67 | > | ||
68 | <Typography>{t('title')}</Typography> | ||
69 | </AccordionSummary> | ||
70 | <AccordionDetails> | ||
71 | <Typography sx={{ wordWrap: 'break-word' }}> | ||
72 | {JSON.stringify(certificate)} | ||
73 | </Typography> | ||
74 | <Typography mt={2}> | ||
75 | <WarningAmberIcon fontSize="small" /> <strong>{t('warning')}</strong> | ||
76 | </Typography> | ||
77 | <Box mt={1}> | ||
78 | <Button | ||
79 | disabled={trust !== 'pending'} | ||
80 | onClick={() => service.temporarilyTrustCurrentCertificate()} | ||
81 | color="error" | ||
82 | variant="outlined" | ||
83 | > | ||
84 | {t(`acceptButton.${trust}`)} | ||
85 | </Button> | ||
86 | </Box> | ||
87 | </AccordionDetails> | ||
88 | </Accordion> | ||
89 | ); | ||
90 | } | ||
91 | |||
92 | export default observer(CertificateDetails); | ||