-
Notifications
You must be signed in to change notification settings - Fork 2
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
[SOK-15] Login Page #14
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@import '../../scss/form-mixin'; | ||
|
||
.login-page { | ||
@include page-background-layout(); | ||
@include form-styles(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,86 @@ | ||
import { useState } from 'react' | ||
import './SignIn.scss' | ||
import React, { useState } from 'react' | ||
import { useAppDispatch } from '@/store' | ||
import { signInUser } from '@/store/reducers/auth-reducer' | ||
import { Button } from '@/components/ui/Button/Button' | ||
import { useSearchParams } from 'react-router-dom' | ||
import { Link, useSearchParams } from 'react-router-dom' | ||
import { useNavigate } from 'react-router-dom' | ||
import { toast } from 'react-toastify' | ||
import { Form } from '@/components/ui/Form/Form' | ||
import { Input } from '@/components/ui/Input/Input' | ||
import { CustomPageTitle } from '@/components/ui/CustomPageTitle/CustomPageTitle' | ||
import SiteLogo from '@/assets/images/site-logo.svg' | ||
|
||
export const SignIn = () => { | ||
const [form, setForm] = useState({ login: '', password: '' }) | ||
const [userData, setUserData] = useState({ login: '', password: '' }) | ||
const [error, setError] = useState<string | null>(null) | ||
const [searchParams] = useSearchParams() | ||
const [query] = useState(searchParams.get('redirectUrl')) | ||
const navigate = useNavigate() | ||
const dispatch = useAppDispatch() | ||
|
||
const handleForm = (name: string, value: string) => { | ||
setForm({ ...form, [name]: value }) | ||
} | ||
const handleInputChange = | ||
(field: string) => (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setUserData(prevData => ({ | ||
...prevData, | ||
[field]: event.target.value, | ||
})) | ||
} | ||
|
||
const handleSubmit = () => { | ||
dispatch(signInUser({ form: form, query: query })) | ||
dispatch(signInUser({ form: userData, query: query })) | ||
.unwrap() | ||
.then(() => { | ||
navigate('/game') | ||
}) | ||
.catch((error?: any, code?: any) => { | ||
toast.error(error.reason) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Если есть силы, добавить в lint`ер такую проверку было бы отлично. |
||
setError('Ошибка! Не правильный логин или пароль.') | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. По хорошему нужно вообще запретить залогиненому пользователю заходить на страницы логина и регистрации |
||
} | ||
|
||
return ( | ||
<> | ||
<form | ||
onSubmit={e => { | ||
e.preventDefault() | ||
}}> | ||
<label> | ||
<span>Логин</span> | ||
<input | ||
onChange={e => handleForm('login', e.target.value)} | ||
type="text" | ||
name={'login'} | ||
value={form.login} | ||
/> | ||
</label> | ||
<label> | ||
<span>Пароль</span> | ||
<input | ||
onChange={e => handleForm('password', e.target.value)} | ||
type="password" | ||
name={'password'} | ||
value={form.password} | ||
/> | ||
</label> | ||
<Button | ||
text={'войти'} | ||
useFixWidth={true} | ||
onClick={() => handleSubmit()} | ||
<div className={'login-page'}> | ||
<Link className="login-page__link" to="/"> | ||
<img | ||
src={SiteLogo} | ||
className="login-page__link__image" | ||
alt="Falcon Tanks Logo" | ||
draggable="false" | ||
/> | ||
</form> | ||
<Button | ||
text={'Регистрация'} | ||
useFixWidth={true} | ||
onClick={() => { | ||
navigate('/sign-up') | ||
}} | ||
/> | ||
</> | ||
</Link> | ||
<div className="container"> | ||
<div className={'row'}> | ||
<div className={'column col-6'}> | ||
<CustomPageTitle className={'login-page__title'} text={'Вход'} /> | ||
<Form className={'login-page__login-form'}> | ||
<Input | ||
className={'login'} | ||
name={'login'} | ||
placeholder={'Логин'} | ||
onChange={handleInputChange('login')} | ||
/> | ||
<Input | ||
className={'password'} | ||
name={'password'} | ||
type={'password'} | ||
placeholder={'Пароль'} | ||
onChange={handleInputChange('password')} | ||
/> | ||
{error && ( | ||
<div className={'login-page__error-message'}>{error}</div> | ||
)} | ||
</Form> | ||
<Button text={'Войти'} useFixWidth={true} onClick={handleSubmit} /> | ||
<Button | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Возможно тут стоит добавить пропс
|
||
className={'link-button'} | ||
text={'Регистрация'} | ||
useFixWidth={true} | ||
onClick={() => { | ||
navigate('/sign-up') | ||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Как будто это не кнопка, а ссылка. |
||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
@import 'vars'; | ||
|
||
@mixin page-background-layout( | ||
$background-image: ( | ||
$img_login-background, | ||
$img_page_background_left, | ||
), | ||
$background-repeat: ( | ||
no-repeat, | ||
no-repeat, | ||
), | ||
$background-size: ( | ||
contain, | ||
auto, | ||
), | ||
$background-position: ( | ||
left bottom, | ||
right bottom, | ||
) | ||
) { | ||
background-image: $background-image; | ||
background-repeat: $background-repeat; | ||
background-size: $background-size; | ||
background-position: $background-position; | ||
} | ||
|
||
@mixin form-styles { | ||
height: 100vh; | ||
display: flex; | ||
justify-content: flex-end; | ||
|
||
.container { | ||
margin-top: auto; | ||
margin-bottom: auto; | ||
width: 768px; | ||
|
||
.row { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Возможно стоит уточнить у @Timur233. У нас такой класс есть в grid-system. Не создает ли это проблем. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не создаёт, потому что используется в конкретном месте в There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Значит ты теряешь возможность использовать There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Так я изменяю его в конкретном месте, так же как и ширину контейнера выше например |
||
justify-content: end; | ||
|
||
.column { | ||
.custom-button { | ||
margin: 0 auto; | ||
} | ||
} | ||
} | ||
} | ||
|
||
&__link { | ||
position: absolute; | ||
left: 0; | ||
|
||
&__image { | ||
margin-left: 25%; | ||
width: 150px; | ||
} | ||
} | ||
|
||
&__title { | ||
margin-bottom: 48px; | ||
} | ||
|
||
.form-fields { | ||
display: flex; | ||
flex-direction: column; | ||
width: 301px; | ||
margin: 0 auto 48px; | ||
|
||
.input-wrapper { | ||
margin-bottom: 16px; | ||
|
||
.input-default { | ||
width: 100%; | ||
} | ||
|
||
&:last-child { | ||
margin-bottom: 0; | ||
} | ||
} | ||
} | ||
|
||
&__error-message { | ||
color: $error-color; | ||
text-wrap: wrap; | ||
} | ||
} |
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.
А зачем тут использовать useState? Мб просто const лучше?
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.
@k0ndratov В этой строке
const [query] = useState(searchParams.get('redirectUrl'))
или в моих?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.
Да, в строке. Вроде query не меняет свое состояние, тогда зачем использотьва useState?
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.
Так эта строка к конкретному реквесту отношения не имеет просто
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.
Можно и порефакторить =) Сейчас вообще query не используется.
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.
А, действительно не имеет. Не заметил. Сорре.