aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/components/errorPage/CertificateDetails.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/renderer/src/components/errorPage/CertificateDetails.tsx')
-rw-r--r--packages/renderer/src/components/errorPage/CertificateDetails.tsx92
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
21import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
22import WarningAmberIcon from '@mui/icons-material/WarningAmber';
23import Accordion from '@mui/material/Accordion';
24import AccordionDetails from '@mui/material/AccordionDetails';
25import AccordionSummary from '@mui/material/AccordionSummary';
26import Box from '@mui/material/Box';
27import Button from '@mui/material/Button';
28import Typography from '@mui/material/Typography';
29import { observer } from 'mobx-react-lite';
30import React from 'react';
31import { useTranslation } from 'react-i18next';
32
33import type Service from '../../stores/Service';
34
35const SUMMARY_ID = 'Sophie-CertificateDetails-header';
36const DETAILS_ID = 'Sophie-CertificateDetails-content';
37
38function 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
92export default observer(CertificateDetails);