Skip to content
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

Rewrite LoginForm to tsx format and fix the sonar issues #2236

Merged
merged 8 commits into from
Aug 2, 2024
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
1 change: 0 additions & 1 deletion sonar-project.properties
BohdanMylyi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ sonar.projectKey=ita-social-projects_SpaceToStudy-Client
sonar.organization=ita-social-projects

sonar.projectName=SpaceToStudy-Client
sonar.branch.name = develop

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=.
Expand Down
Olenka-Hryk marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useTranslation } from 'react-i18next'
import useInputVisibility from '~/hooks/use-input-visibility'
import { useSelector } from 'react-redux'

import Box from '@mui/material/Box'
import ButtonBase from '@mui/material/ButtonBase'
Expand All @@ -14,18 +13,38 @@ import AppTextField from '~/components/app-text-field/AppTextField'
import AppButton from '~/components/app-button/AppButton'

import { styles } from '~/containers/guest-home-page/login-form/LoginForm.styles'
import { useAppSelector } from '~/hooks/use-redux'

const LoginForm = ({
interface LoginFormProps {
handleSubmit: (event: React.FormEvent<HTMLFormElement>) => void
handleChange: (
field: string
) => (event: React.SyntheticEvent<Element, Event>) => void
handleBlur: (
field: string
) => (event: React.FocusEvent<HTMLInputElement>) => void
data: {
email: string
password: string
rememberMe: boolean
}
errors: {
email?: string
password?: string
}
}

const LoginForm: React.FC<LoginFormProps> = ({
handleSubmit,
handleChange,
handleBlur,
data,
errors
}) => {
const { inputVisibility: passwordVisibility, showInputText: showPassword } =
useInputVisibility(errors.password)
useInputVisibility(errors.password ?? '')

const { authLoading } = useSelector((state) => state.appMain)
const { authLoading } = useAppSelector((state) => state.appMain)

const { openModal } = useModalContext()

Expand All @@ -40,21 +59,21 @@ const LoginForm = ({
<AppTextField
autoFocus
data-testid={'email'}
errorMsg={t(errors.email)}
errorMsg={t(errors.email ?? '')}
fullWidth
label={t('common.labels.email')}
onBlur={handleBlur('email')}
onChange={handleChange('email')}
required
size='large'
size='medium'
sx={{ mb: '5px' }}
type='email'
value={data.email}
/>

<AppTextField
InputProps={passwordVisibility}
errorMsg={t(errors.password)}
errorMsg={t(errors.password ?? '')}
fullWidth
label={t('common.labels.password')}
onBlur={handleBlur('password')}
Expand All @@ -69,7 +88,11 @@ const LoginForm = ({
control={<Checkbox />}
label={t('login.rememberMe')}
labelPlacement='end'
onChange={handleChange('rememberMe')}
onChange={(event) =>
handleChange('rememberMe')(
event as React.ChangeEvent<HTMLInputElement>
)
}
sx={styles.checkboxLabel}
value={data.rememberMe}
/>
Expand Down
Loading