diff --git a/src/components/Common/SensitiveInput/index.tsx b/src/components/Common/SensitiveInput/index.tsx new file mode 100644 index 000000000..56619c28d --- /dev/null +++ b/src/components/Common/SensitiveInput/index.tsx @@ -0,0 +1,54 @@ +import { EyeIcon, EyeOffIcon } from '@heroicons/react/solid'; +import { Field } from 'formik'; +import React, { useState } from 'react'; + +interface CustomInputProps extends React.ComponentProps<'input'> { + as?: 'input'; +} + +interface CustomFieldProps extends React.ComponentProps { + as?: 'field'; +} + +type SensitiveInputProps = CustomInputProps | CustomFieldProps; + +const SensitiveInput: React.FC = ({ + as = 'input', + ...props +}) => { + const [isHidden, setHidden] = useState(true); + const Component = as === 'input' ? 'input' : Field; + const componentProps = + as === 'input' + ? props + : { + ...props, + as: props.type === 'textarea' && !isHidden ? 'textarea' : undefined, + }; + return ( + <> + + + + ); +}; + +export default SensitiveInput; diff --git a/src/components/ResetPassword/index.tsx b/src/components/ResetPassword/index.tsx index 94005ab1d..2dc9bfb07 100644 --- a/src/components/ResetPassword/index.tsx +++ b/src/components/ResetPassword/index.tsx @@ -1,5 +1,5 @@ import axios from 'axios'; -import { Field, Form, Formik } from 'formik'; +import { Form, Formik } from 'formik'; import Link from 'next/link'; import { useRouter } from 'next/router'; import React, { useState } from 'react'; @@ -7,6 +7,7 @@ import { defineMessages, useIntl } from 'react-intl'; import * as Yup from 'yup'; import Button from '../Common/Button'; import ImageFader from '../Common/ImageFader'; +import SensitiveInput from '../Common/SensitiveInput'; import LanguagePicker from '../Layout/LanguagePicker'; const messages = defineMessages({ @@ -116,7 +117,8 @@ const ResetPassword: React.FC = () => {
- {
- {
- {
- @@ -434,7 +437,8 @@ const NotificationsEmail: React.FC = () => {
- {
- {
- = ({
- {
- = ({
- {
- {
- {
- {
-