Skip to content

feat: add password hide show logic for init server #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 38 additions & 16 deletions ui/src/pages/Install/components/FourthStep/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
* under the License.
*/

import { FC, FormEvent } from 'react';
import { FC, FormEvent, useState } from 'react';
import { Form, Button } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';

import type { FormDataType } from '@/common/interface';
import Pattern from '@/common/pattern';
import Progress from '../Progress';
import { Icon } from '@/components';

interface Props {
data: FormDataType;
Expand All @@ -34,6 +35,8 @@ interface Props {
const Index: FC<Props> = ({ visible, data, changeCallback, nextCallback }) => {
const { t } = useTranslation('translation', { keyPrefix: 'install' });

const [showPassword, setShowPassword] = useState(false);

const checkValidated = (): boolean => {
let bol = true;
const { site_name, site_url, contact_email, name, password, email } = data;
Expand Down Expand Up @@ -295,21 +298,40 @@ const Index: FC<Props> = ({ visible, data, changeCallback, nextCallback }) => {

<Form.Group controlId="password" className="mb-3">
<Form.Label>{t('admin_password.label')}</Form.Label>
<Form.Control
required
type="password"
value={data.password.value}
isInvalid={data.password.isInvalid}
onChange={(e) => {
changeCallback({
password: {
value: e.target.value,
isInvalid: false,
errorMsg: '',
},
});
}}
/>
<div className="position-relative">
<Form.Control
required
type={showPassword ? 'text' : 'password'}
value={data.password.value}
isInvalid={data.password.isInvalid}
style={{ paddingRight: '45px' }}
onChange={(e) => {
changeCallback({
password: {
value: e.target.value,
isInvalid: false,
errorMsg: '',
},
});
}}
/>
<button
type="button"
className="position-absolute top-50 translate-middle-y bg-transparent border-0 p-1"
style={{
right: '12px',
}}
aria-label={showPassword ? t('hide_password') : t('show_password')}
onMouseDown={() => setShowPassword(true)}
onMouseUp={() => setShowPassword(false)}
onMouseLeave={() => setShowPassword(false)}>
{showPassword ? (
<Icon name="eye" className="text-secondary" size="18" />
) : (
<Icon name="eye-slash" className="text-secondary" size="18" />
)}
</button>
</div>
<Form.Text>{t('admin_password.text')}</Form.Text>
<Form.Control.Feedback type="invalid">
{data.password.errorMsg}
Expand Down