ente/src/components/RecoveryKeyModal.tsx

82 lines
2.6 KiB
TypeScript
Raw Normal View History

2021-04-05 07:41:31 +00:00
import React, { useEffect, useState } from 'react';
import { Button, Modal, Spinner } from 'react-bootstrap';
import { downloadAsFile } from 'utils/common';
import { getRecoveryKey } from 'utils/crypto';
import constants from 'utils/strings/constants';
export interface Props {
show: boolean;
onHide: () => void;
}
function RecoveryKeyModal(props: Props) {
const [recoveryKey, setRecoveryKey] = useState(null);
useEffect(() => {
2021-04-05 09:11:06 +00:00
if (!props.show) {
return;
}
2021-04-05 07:41:31 +00:00
const main = async () => {
const recoveryKey = await getRecoveryKey();
setRecoveryKey(recoveryKey);
};
main();
}, [props.show]);
return (
<Modal {...props} size="lg" centered>
<Modal.Body>
<Modal.Title>
<strong>{constants.DOWNLOAD_RECOVERY_KEY}</strong>
</Modal.Title>
<hr />
{constants.PASSPHRASE_DISCLAIMER()}
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: '#1a1919',
height: '150px',
2021-04-05 07:41:31 +00:00
padding: '40px',
color: 'white',
margin: '20px 0',
}}
>
{recoveryKey ? (
<div
style={{
wordWrap: 'break-word',
overflowWrap: 'break-word',
minWidth: '40%',
}}
>
{recoveryKey}
</div>
) : (
<Spinner animation="border" />
)}
</div>
{constants.KEY_NOT_STORED_DISCLAIMER()}
</Modal.Body>
<Modal.Footer style={{ borderTop: 'none' }}>
<Button variant="danger" onClick={props.onHide}>
{constants.SAVE_LATER}
</Button>
<Button
variant="success"
2021-04-05 10:39:58 +00:00
onClick={() => {
2021-04-05 08:28:22 +00:00
downloadAsFile(
constants.RECOVERY_KEY_FILENAME,
recoveryKey
2021-04-05 10:39:58 +00:00
);
props.onHide();
}}
2021-04-05 07:41:31 +00:00
>
{constants.SAVE}
</Button>
</Modal.Footer>
</Modal>
);
}
export default RecoveryKeyModal;