|
@@ -4,6 +4,9 @@ import { Form } from 'react-bootstrap';
|
|
import { Formik, FormikHelpers } from 'formik';
|
|
import { Formik, FormikHelpers } from 'formik';
|
|
import * as Yup from 'yup';
|
|
import * as Yup from 'yup';
|
|
import SubmitButton from './SubmitButton';
|
|
import SubmitButton from './SubmitButton';
|
|
|
|
+import styled from 'styled-components';
|
|
|
|
+import Visibility from './icons/Visibility';
|
|
|
|
+import VisibilityOff from './icons/VisibilityOff';
|
|
|
|
|
|
interface formValues {
|
|
interface formValues {
|
|
passphrase: string;
|
|
passphrase: string;
|
|
@@ -15,8 +18,24 @@ interface Props {
|
|
buttonText: string;
|
|
buttonText: string;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+const Group = styled.div`
|
|
|
|
+ display: flex;
|
|
|
|
+`;
|
|
|
|
+
|
|
|
|
+const Button = styled.button`
|
|
|
|
+ background: transparent;
|
|
|
|
+ border: none;
|
|
|
|
+ width: 36px;
|
|
|
|
+ height: 36px;
|
|
|
|
+ margin-left: -36px;
|
|
|
|
+ display: flex;
|
|
|
|
+ align-items: center;
|
|
|
|
+`;
|
|
|
|
+
|
|
export default function SingleInputForm(props: Props) {
|
|
export default function SingleInputForm(props: Props) {
|
|
const [loading, SetLoading] = useState(false);
|
|
const [loading, SetLoading] = useState(false);
|
|
|
|
+ const [showPassword, setShowPassword] = useState(false);
|
|
|
|
+
|
|
const submitForm = async (
|
|
const submitForm = async (
|
|
values: formValues,
|
|
values: formValues,
|
|
{ setFieldError }: FormikHelpers<formValues>,
|
|
{ setFieldError }: FormikHelpers<formValues>,
|
|
@@ -40,17 +59,25 @@ export default function SingleInputForm(props: Props) {
|
|
}) => (
|
|
}) => (
|
|
<Form noValidate onSubmit={handleSubmit}>
|
|
<Form noValidate onSubmit={handleSubmit}>
|
|
<Form.Group>
|
|
<Form.Group>
|
|
- <Form.Control
|
|
|
|
- type={props.fieldType}
|
|
|
|
- placeholder={props.placeholder}
|
|
|
|
- value={values.passphrase}
|
|
|
|
- onChange={handleChange('passphrase')}
|
|
|
|
- isInvalid={Boolean(
|
|
|
|
- touched.passphrase && errors.passphrase,
|
|
|
|
- )}
|
|
|
|
- disabled={loading}
|
|
|
|
- autoFocus
|
|
|
|
- />
|
|
|
|
|
|
+ <Group>
|
|
|
|
+ <Form.Control
|
|
|
|
+ type={showPassword ? 'text' : props.fieldType}
|
|
|
|
+ placeholder={props.placeholder}
|
|
|
|
+ value={values.passphrase}
|
|
|
|
+ onChange={handleChange('passphrase')}
|
|
|
|
+ isInvalid={Boolean(
|
|
|
|
+ touched.passphrase && errors.passphrase,
|
|
|
|
+ )}
|
|
|
|
+ disabled={loading}
|
|
|
|
+ autoFocus
|
|
|
|
+ />
|
|
|
|
+ {
|
|
|
|
+ props.fieldType === 'password' &&
|
|
|
|
+ <Button type='button' onClick={() => setShowPassword(!showPassword)}>
|
|
|
|
+ {showPassword ? <VisibilityOff /> : <Visibility />}
|
|
|
|
+ </Button>
|
|
|
|
+ }
|
|
|
|
+ </Group>
|
|
<Form.Control.Feedback type="invalid">
|
|
<Form.Control.Feedback type="invalid">
|
|
{errors.passphrase}
|
|
{errors.passphrase}
|
|
</Form.Control.Feedback>
|
|
</Form.Control.Feedback>
|