-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created InputPassword and refactor InputCustom
- Loading branch information
Showing
8 changed files
with
93 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next' | |
import { NavLink, useOutletContext } from 'react-router-dom' | ||
import { AuthOutletContextType } from '~elements/LayoutAuth' | ||
import { Routes } from '~src/router/routes' | ||
import InputCustom from '../Layout/InputCustom' | ||
import InputBasic from '../Layout/InputBasic' | ||
|
||
function ForgotPassword() { | ||
const { t } = useTranslation() | ||
|
@@ -28,7 +28,7 @@ function ForgotPassword() { | |
<> | ||
<FormProvider {...methods}> | ||
<Flex as='form' onSubmit={methods.handleSubmit(onSubmit)} flexDirection='column' gap={6}> | ||
<InputCustom | ||
<InputBasic | ||
formValue='email' | ||
label={t('email')} | ||
placeholder={t('email_placeholder', { defaultValue: '[email protected]' })} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,11 @@ import { ILoginParams } from '~components/Auth/authQueries' | |
import { useAuth } from '~components/Auth/useAuth' | ||
import { VerifyAccountNeeded } from '~components/Auth/Verify' | ||
import FormSubmitMessage from '~components/Layout/FormSubmitMessage' | ||
import InputPassword from '~components/Layout/InputPassword' | ||
import { AuthOutletContextType } from '~elements/LayoutAuth' | ||
import { Routes } from '~src/router/routes' | ||
import CustomCheckbox from '../Layout/CheckboxCustom' | ||
import InputCustom from '../Layout/InputCustom' | ||
import InputBasic from '../Layout/InputBasic' | ||
import GoogleAuth from './GoogleAuth' | ||
|
||
type FormData = { | ||
|
@@ -64,18 +65,17 @@ const SignIn = () => { | |
</Flex> | ||
<FormProvider {...methods}> | ||
<Flex as='form' onSubmit={handleSubmit(onSubmit)} flexDirection='column' gap={6}> | ||
<InputCustom | ||
<InputBasic | ||
formValue='email' | ||
label={t('email')} | ||
placeholder={t('email_placeholder', { defaultValue: '[email protected]' })} | ||
type='email' | ||
required | ||
/> | ||
<InputCustom | ||
<InputPassword | ||
formValue='password' | ||
label={t('password')} | ||
placeholder={t('password_placeholder', { defaultValue: 'Enter your password' })} | ||
type='password' | ||
required | ||
/> | ||
<Flex justifyContent='center' align='center'> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,11 @@ import { IRegisterParams } from '~components/Auth/authQueries' | |
import { useAuth } from '~components/Auth/useAuth' | ||
import { VerifyAccountNeeded } from '~components/Auth/Verify' | ||
import FormSubmitMessage from '~components/Layout/FormSubmitMessage' | ||
import InputPassword from '~components/Layout/InputPassword' | ||
import { AuthOutletContextType } from '~elements/LayoutAuth' | ||
import { Routes } from '~src/router/routes' | ||
import CustomCheckbox from '../Layout/CheckboxCustom' | ||
import InputCustom from '../Layout/InputCustom' | ||
import { default as InputBasic } from '../Layout/InputBasic' | ||
import GoogleAuth from './GoogleAuth' | ||
import { HSeparator } from './SignIn' | ||
|
||
|
@@ -59,17 +60,17 @@ const SignUp = () => { | |
<FormProvider {...methods}> | ||
<Flex as='form' onSubmit={handleSubmit(onSubmit)} flexDirection='column' gap={6}> | ||
<Flex flexDirection={{ base: 'column', md: 'row' }} gap={{ md: 4 }}> | ||
<InputCustom formValue='firstName' label={t('signup_first_name')} placeholder={'John'} required /> | ||
<InputCustom formValue='lastName' label={t('signup_last_name')} placeholder={'Doe'} required /> | ||
<InputBasic formValue='firstName' label={t('signup_first_name')} placeholder={'John'} required /> | ||
<InputBasic formValue='lastName' label={t('signup_last_name')} placeholder={'Doe'} required /> | ||
</Flex> | ||
<InputCustom | ||
<InputBasic | ||
formValue='email' | ||
label={t('email')} | ||
placeholder={t('email_placeholder', { defaultValue: '[email protected]' })} | ||
type='email' | ||
required | ||
/> | ||
<InputCustom | ||
<InputPassword | ||
formValue='password' | ||
label={t('password')} | ||
placeholder={t('password_placeholder', { defaultValue: 'Min 8 characters' })} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { FormControl, FormErrorMessage, FormLabel, Icon, Input, InputGroup, InputRightElement } from '@chakra-ui/react' | ||
import { useState } from 'react' | ||
import { useFormContext } from 'react-hook-form' | ||
import { useTranslation } from 'react-i18next' | ||
import { MdOutlineRemoveRedEye } from 'react-icons/md' | ||
import { RiEyeCloseLine } from 'react-icons/ri' | ||
|
||
export interface InputPasswordProps { | ||
formValue: string | ||
label: string | ||
placeholder?: string | ||
type?: string | ||
required?: boolean | ||
validation?: any | ||
messageError?: string | ||
} | ||
const InputPassword = ({ | ||
formValue, | ||
label, | ||
placeholder, | ||
type = 'password', | ||
required = false, | ||
validation = {}, | ||
}: InputPasswordProps) => { | ||
const { t } = useTranslation() | ||
const [show, setShow] = useState(false) | ||
const handleClick = () => setShow(!show) | ||
|
||
const { | ||
register, | ||
formState: { errors }, | ||
} = useFormContext() | ||
|
||
const validationRules = { | ||
...validation, | ||
...(required ? { required: { value: true, message: t('form.error.field_is_required') } } : {}), | ||
} | ||
|
||
const errorMessage = errors[formValue]?.message?.toString() || '' | ||
|
||
let inputType = type | ||
|
||
if (type === 'password' && show) { | ||
inputType = 'text' | ||
} | ||
|
||
return ( | ||
<FormControl isInvalid={!!errors[formValue]} isRequired={required}> | ||
{label && <FormLabel variant='process-create-title-sm'>{label}</FormLabel>} | ||
<InputGroup> | ||
<Input {...register(formValue, validationRules)} type={inputType} placeholder={placeholder} /> | ||
<InputRightElement display='flex' alignItems='center' minH='100%'> | ||
<Icon | ||
_hover={{ cursor: 'pointer' }} | ||
as={show ? RiEyeCloseLine : MdOutlineRemoveRedEye} | ||
onClick={handleClick} | ||
/> | ||
</InputRightElement> | ||
</InputGroup> | ||
<FormErrorMessage mt={2}>{errorMessage || 'Error performing the operation'}</FormErrorMessage> | ||
</FormControl> | ||
) | ||
} | ||
|
||
export default InputPassword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { Controller, FormProvider, useForm, useFormContext } from 'react-hook-fo | |
import { Trans, useTranslation } from 'react-i18next' | ||
import { IoCloseSharp } from 'react-icons/io5' | ||
import { HSeparator } from '~components/Auth/SignIn' | ||
import InputCustom from '~components/Layout/InputCustom' | ||
import InputBasic from '~components/Layout/InputBasic' | ||
|
||
const Invite = ({ setInviteView }: { setInviteView: Dispatch<SetStateAction<boolean>> }) => { | ||
const { t } = useTranslation() | ||
|
@@ -38,7 +38,7 @@ const Invite = ({ setInviteView }: { setInviteView: Dispatch<SetStateAction<bool | |
<HSeparator /> | ||
<FormProvider {...methods}> | ||
<Flex as='form' onSubmit={methods.handleSubmit(onSubmit)} flexDirection='column' gap={6}> | ||
<InputCustom | ||
<InputBasic | ||
formValue='email' | ||
label={t('email')} | ||
placeholder={t('email_placeholder', { defaultValue: '[email protected]' })} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19e89f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π Published on https://vocdoni-app-stg.netlify.app as production
π Deployed on https://6720ae48fbe6e2c894c90ea3--vocdoni-app-stg.netlify.app
19e89f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π Published on https://vocdoni-app-dev.netlify.app as production
π Deployed on https://6720ae4d908ab6cb5ae4febc--vocdoni-app-dev.netlify.app