|
| 1 | +/** |
| 2 | + * Copyright (c) 2023 BlockDev AG |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +import { useEffect, useState } from 'react' |
| 9 | +import { useLocation, useNavigate } from 'react-router-dom' |
| 10 | +import styled from 'styled-components' |
| 11 | +import { ConfirmationDialog } from '../../../../Components/ConfirmationDialog/ConfirmationDialog' |
| 12 | + |
| 13 | +const Password = styled.div` |
| 14 | + font-size: ${({ theme }) => theme.common.fontSizeBigger}; |
| 15 | + font-weight: bold; |
| 16 | + color: ${({ theme }) => theme.generatedPassword.textColor}; |
| 17 | +` |
| 18 | + |
| 19 | +const Row = styled.div` |
| 20 | + display: flex; |
| 21 | + align-items: center; |
| 22 | + justify-content: center; |
| 23 | + gap: 6px; |
| 24 | +` |
| 25 | + |
| 26 | +const Warning = styled.div` |
| 27 | + margin-top: 10px; |
| 28 | + font-size: ${({ theme }) => theme.common.fontSizeNormal}; |
| 29 | +` |
| 30 | + |
| 31 | +const Column = styled.div` |
| 32 | + display: flex; |
| 33 | + flex-direction: column; |
| 34 | +` |
| 35 | + |
| 36 | +export const GeneratedPasswordPopUp = () => { |
| 37 | + const [show, setShow] = useState(false) |
| 38 | + const location = useLocation() |
| 39 | + const navigate = useNavigate() |
| 40 | + |
| 41 | + const resolveGeneratedPassword = (): string | undefined => { |
| 42 | + if (typeof location.state !== 'object') { |
| 43 | + return |
| 44 | + } |
| 45 | + const state = location.state as Record<string, string> |
| 46 | + return state?.generatedPassword |
| 47 | + } |
| 48 | + |
| 49 | + const generatedPassword = resolveGeneratedPassword() |
| 50 | + |
| 51 | + useEffect(() => { |
| 52 | + if (generatedPassword) { |
| 53 | + setShow(true) |
| 54 | + } |
| 55 | + }, [generatedPassword]) |
| 56 | + |
| 57 | + if (!generatedPassword) { |
| 58 | + return <></> |
| 59 | + } |
| 60 | + |
| 61 | + return ( |
| 62 | + <ConfirmationDialog |
| 63 | + hideCancel |
| 64 | + disableBackdrop |
| 65 | + show={show} |
| 66 | + message={ |
| 67 | + <Column> |
| 68 | + <Row> |
| 69 | + <Password>{generatedPassword}</Password> |
| 70 | + </Row> |
| 71 | + <Warning>Please write down the password or use it to change to a new password in settings page.</Warning> |
| 72 | + </Column> |
| 73 | + } |
| 74 | + title="Your NodeUI Password" |
| 75 | + onConfirm={() => { |
| 76 | + setShow(false) |
| 77 | + navigate(location.pathname, { replace: true }) |
| 78 | + }} |
| 79 | + ></ConfirmationDialog> |
| 80 | + ) |
| 81 | +} |
0 commit comments