mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-28 15:00:59 -05:00
fix(frontend): add error prop to password input
Signed-off-by: Avinash <avinash.kumar.cs92@gmail.com>
This commit is contained in:
parent
58819f6018
commit
dae3b9d8dc
4 changed files with 24 additions and 8 deletions
|
@ -8,4 +8,5 @@ import type { ChangeEvent } from 'react'
|
|||
export interface CommonFieldProps {
|
||||
onChange: (event: ChangeEvent<HTMLInputElement>) => void
|
||||
value: string
|
||||
hasError?: boolean
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import { Trans, useTranslation } from 'react-i18next'
|
|||
* @param onChange Hook that is called when the entered password changes.
|
||||
* @param value The currently entered password.
|
||||
*/
|
||||
export const NewPasswordField: React.FC<CommonFieldProps> = ({ onChange, value }) => {
|
||||
export const NewPasswordField: React.FC<CommonFieldProps> = ({ onChange, value, hasError = false }) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const isValid = useMemo(() => {
|
||||
|
@ -30,6 +30,7 @@ export const NewPasswordField: React.FC<CommonFieldProps> = ({ onChange, value }
|
|||
type='password'
|
||||
size='sm'
|
||||
isValid={isValid}
|
||||
isInvalid={hasError}
|
||||
onChange={onChange}
|
||||
placeholder={t('login.auth.password') ?? undefined}
|
||||
className='bg-dark text-light'
|
||||
|
|
|
@ -19,16 +19,21 @@ interface PasswordAgainFieldProps extends CommonFieldProps {
|
|||
* @param value The currently entered retype of the password.
|
||||
* @param password The password entered into the password input field.
|
||||
*/
|
||||
export const PasswordAgainField: React.FC<PasswordAgainFieldProps> = ({ onChange, value, password }) => {
|
||||
export const PasswordAgainField: React.FC<PasswordAgainFieldProps> = ({
|
||||
onChange,
|
||||
value,
|
||||
password,
|
||||
hasError = false
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const isInvalid = useMemo(() => {
|
||||
return value !== '' && password !== value
|
||||
}, [password, value])
|
||||
return value !== '' && password !== value && hasError
|
||||
}, [password, value, hasError])
|
||||
|
||||
const isValid = useMemo(() => {
|
||||
return password !== '' && password === value
|
||||
}, [password, value])
|
||||
return password !== '' && password === value && !hasError
|
||||
}, [password, value, hasError])
|
||||
|
||||
return (
|
||||
<Form.Group>
|
||||
|
|
|
@ -69,6 +69,10 @@ export const RegisterPage: NextPage = () => {
|
|||
)
|
||||
}, [username, password, displayName, passwordAgain])
|
||||
|
||||
const isWeakPassword = useMemo(() => {
|
||||
return error === RegisterErrorType.PASSWORD_TOO_WEAK
|
||||
}, [error])
|
||||
|
||||
const onUsernameChange = useOnInputChange(setUsername)
|
||||
const onDisplayNameChange = useOnInputChange(setDisplayName)
|
||||
const onPasswordChange = useOnInputChange(setPassword)
|
||||
|
@ -95,8 +99,13 @@ export const RegisterPage: NextPage = () => {
|
|||
<Form onSubmit={doRegisterSubmit}>
|
||||
<UsernameField onChange={onUsernameChange} value={username} />
|
||||
<DisplayNameField onChange={onDisplayNameChange} value={displayName} />
|
||||
<NewPasswordField onChange={onPasswordChange} value={password} />
|
||||
<PasswordAgainField password={password} onChange={onPasswordAgainChange} value={passwordAgain} />
|
||||
<NewPasswordField onChange={onPasswordChange} value={password} hasError={isWeakPassword} />
|
||||
<PasswordAgainField
|
||||
password={password}
|
||||
onChange={onPasswordAgainChange}
|
||||
value={passwordAgain}
|
||||
hasError={isWeakPassword}
|
||||
/>
|
||||
|
||||
<RegisterInfos />
|
||||
|
||||
|
|
Loading…
Reference in a new issue