fixes for register form (#188)

This commit is contained in:
Arkadzi Rakouski 2023-08-21 14:11:18 +03:00 committed by GitHub
parent 52d8a01a50
commit a6cae1abb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 34 deletions

View File

@ -80,31 +80,7 @@ export const ForgotPasswordForm = () => {
<div> <div>
<h4>{t('Forgot password?')}</h4> <h4>{t('Forgot password?')}</h4>
<div class={styles.authSubtitle}>{t('Everything is ok, please give us your email address')}</div> <div class={styles.authSubtitle}>{t('Everything is ok, please give us your email address')}</div>
<Show when={submitError()}>
<div class={styles.authInfo}>
<ul>
<li class={styles.warn}>{submitError()}</li>
</ul>
</div>
</Show>
<Show when={isUserNotFount()}>
<div class={styles.authSubtitle}>
{/*TODO: text*/}
{t("We can't find you, check email or")}{' '}
<a
href="#"
onClick={(event) => {
event.preventDefault()
changeSearchParam('mode', 'register')
}}
>
{t('register')}
</a>
</div>
</Show>
<Show when={validationErrors().email}>
<div class={styles.validationError}>{validationErrors().email}</div>
</Show>
<div <div
class={clsx('pretty-form__item', { class={clsx('pretty-form__item', {
'pretty-form__item--error': validationErrors().email 'pretty-form__item--error': validationErrors().email
@ -123,6 +99,34 @@ export const ForgotPasswordForm = () => {
<label for="email">{t('Email')}</label> <label for="email">{t('Email')}</label>
</div> </div>
<Show when={submitError()}>
<div class={styles.authInfo}>
<ul>
<li class={styles.warn}>{submitError()}</li>
</ul>
</div>
</Show>
<Show when={isUserNotFount()}>
<div class={styles.authSubtitle}>
{/*TODO: text*/}
{t("We can't find you, check email or")}{' '}
<a
href="#"
onClick={(event) => {
event.preventDefault()
changeSearchParam('mode', 'register')
}}
>
{t('register')}
</a>
</div>
</Show>
<Show when={validationErrors().email}>
<div class={styles.validationError}>{validationErrors().email}</div>
</Show>
<div> <div>
<button class={clsx('button', styles.submitButton)} disabled={isSubmitting()} type="submit"> <button class={clsx('button', styles.submitButton)} disabled={isSubmitting()} type="submit">
{isSubmitting() ? '...' : t('Restore password')} {isSubmitting() ? '...' : t('Restore password')}

View File

@ -13,6 +13,7 @@ import { register } from '../../../stores/auth'
import { useLocalize } from '../../../context/localize' import { useLocalize } from '../../../context/localize'
import { validateEmail } from '../../../utils/validateEmail' import { validateEmail } from '../../../utils/validateEmail'
import { AuthModalHeader } from './AuthModalHeader' import { AuthModalHeader } from './AuthModalHeader'
import { Icon } from '../../_shared/Icon'
type FormFields = { type FormFields = {
fullName: string fullName: string
@ -31,13 +32,13 @@ export const RegisterForm = () => {
const [fullName, setFullName] = createSignal('') const [fullName, setFullName] = createSignal('')
const [password, setPassword] = createSignal('') const [password, setPassword] = createSignal('')
const [isSubmitting, setIsSubmitting] = createSignal(false) const [isSubmitting, setIsSubmitting] = createSignal(false)
const [showPassword, setShowPassword] = createSignal(false)
const [isSuccess, setIsSuccess] = createSignal(false) const [isSuccess, setIsSuccess] = createSignal(false)
const [validationErrors, setValidationErrors] = createSignal<ValidationErrors>({}) const [validationErrors, setValidationErrors] = createSignal<ValidationErrors>({})
const authFormRef: { current: HTMLFormElement } = { current: null } const authFormRef: { current: HTMLFormElement } = { current: null }
const handleEmailInput = (newEmail: string) => { const handleEmailInput = (newEmail: string) => {
setValidationErrors(({ email: _notNeeded, ...rest }) => rest)
setEmail(newEmail) setEmail(newEmail)
} }
@ -65,23 +66,25 @@ export const RegisterForm = () => {
} }
const handlePasswordInput = (newPassword: string) => { const handlePasswordInput = (newPassword: string) => {
const passwordError = isValidPassword(newPassword)
if (passwordError) {
setValidationErrors((errors) => ({ ...errors, password: passwordError }))
} else {
setValidationErrors(({ password: _notNeeded, ...rest }) => rest)
}
setPassword(newPassword) setPassword(newPassword)
} }
const handleNameInput = (newPasswordCopy: string) => { const handleNameInput = (newPasswordCopy: string) => {
setValidationErrors(({ fullName: _notNeeded, ...rest }) => rest)
setFullName(newPasswordCopy) setFullName(newPasswordCopy)
} }
const handleSubmit = async (event: Event) => { const handleSubmit = async (event: Event) => {
event.preventDefault() event.preventDefault()
const passwordError = isValidPassword(password())
if (passwordError) {
setValidationErrors((errors) => ({ ...errors, password: passwordError }))
} else {
setValidationErrors(({ password: _notNeeded, ...rest }) => rest)
}
setValidationErrors(({ email: _notNeeded, ...rest }) => rest)
setValidationErrors(({ fullName: _notNeeded, ...rest }) => rest)
setSubmitError('') setSubmitError('')
const newValidationErrors: ValidationErrors = {} const newValidationErrors: ValidationErrors = {}
@ -211,11 +214,18 @@ export const RegisterForm = () => {
id="password" id="password"
name="password" name="password"
autocomplete="current-password" autocomplete="current-password"
type="password" type={showPassword() ? 'text' : 'password'}
placeholder={t('Password')} placeholder={t('Password')}
onInput={(event) => handlePasswordInput(event.currentTarget.value)} onInput={(event) => handlePasswordInput(event.currentTarget.value)}
/> />
<label for="password">{t('Password')}</label> <label for="password">{t('Password')}</label>
<button
type="button"
class={styles.passwordToggle}
onClick={() => setShowPassword(!showPassword())}
>
<Icon class={styles.passwordToggleIcon} name={showPassword() ? 'eye-off' : 'eye'} />
</button>
</div> </div>
<Show when={validationErrors().password}> <Show when={validationErrors().password}>
<div class={clsx(styles.registerPassword, styles.validationError)}> <div class={clsx(styles.registerPassword, styles.validationError)}>